Blender  V2.93
StrokeRep.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
17 #pragma once
18 
24 #include "Stroke.h"
25 
26 #include "../geometry/Geom.h"
27 
28 #ifdef WITH_CXX_GUARDEDALLOC
29 # include "MEM_guardedalloc.h"
30 #endif
31 
32 #include "DNA_material_types.h" // for MAX_MTEX
33 struct bNodeTree;
34 
35 namespace Freestyle {
36 
37 using namespace Geometry;
38 
39 #if 0
40 //symbolic constant to call the appropriate renderers and textures
41 # define NO_TEXTURE_WITH_BLEND_STROKE -2
42 # define NO_TEXTURE_STROKE -1
43 # define PSEUDO_CHARCOAL_STROKE 0
44 # define WASH_BRUSH_STROKE 1
45 # define OIL_STROKE 2
46 # define NO_BLEND_STROKE 3
47 # define CHARCOAL_MIN_STROKE 4
48 # define BRUSH_MIN_STROKE 5
49 # define OPAQUE_DRY_STROKE 6
50 # define OPAQUE_STROKE 7
51 
52 # define DEFAULT_STROKE 0
53 
54 # define NUMBER_STROKE_RENDERER 8
55 
56 #endif
57 
59  public:
61  {
62  }
63 
64  StrokeVertexRep(const Vec2r &iPoint2d)
65  {
66  _point2d = iPoint2d;
67  }
68 
69  StrokeVertexRep(const StrokeVertexRep &iBrother);
70 
71  virtual ~StrokeVertexRep()
72  {
73  }
74 
75  inline Vec2r &point2d()
76  {
77  return _point2d;
78  }
79 
80  inline Vec2r &texCoord(bool tips = false)
81  {
82  if (tips) {
83  return _texCoord_w_tips;
84  }
85  else {
86  return _texCoord;
87  }
88  }
89 
90  inline Vec3r &color()
91  {
92  return _color;
93  }
94 
95  inline float alpha()
96  {
97  return _alpha;
98  }
99 
100  inline void setPoint2d(const Vec2r &p)
101  {
102  _point2d = p;
103  }
104 
105  inline void setTexCoord(const Vec2r &p, bool tips = false)
106  {
107  if (tips) {
108  _texCoord_w_tips = p;
109  }
110  else {
111  _texCoord = p;
112  }
113  }
114 
115  inline void setColor(const Vec3r &p)
116  {
117  _color = p;
118  }
119 
120  inline void setAlpha(float a)
121  {
122  _alpha = a;
123  }
124 
125  protected:
130  float _alpha;
131 
132 #ifdef WITH_CXX_GUARDEDALLOC
133  MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:StrokeVertexRep")
134 #endif
135 };
136 
137 class Strip {
138  public:
139  typedef std::vector<StrokeVertexRep *> vertex_container;
140 
141  protected:
144 
145  public:
146  Strip(const std::vector<StrokeVertex *> &iStrokeVertices,
147  bool hasTex = false,
148  bool tipBegin = false,
149  bool tipEnd = false,
150  float texStep = 1.0);
151  Strip(const Strip &iBrother);
152  virtual ~Strip();
153 
154  protected:
155  void createStrip(const std::vector<StrokeVertex *> &iStrokeVertices);
156  void cleanUpSingularities(const std::vector<StrokeVertex *> &iStrokeVertices);
157  void setVertexColor(const std::vector<StrokeVertex *> &iStrokeVertices);
158  void computeTexCoord(const std::vector<StrokeVertex *> &iStrokeVertices, float texStep);
159  void computeTexCoordWithTips(const std::vector<StrokeVertex *> &iStrokeVertices,
160  bool tipBegin,
161  bool tipEnd,
162  float texStep);
163 
164  public:
165  inline int sizeStrip() const
166  {
167  return _vertices.size();
168  }
169 
171  {
172  return _vertices;
173  }
174 
175 #ifdef WITH_CXX_GUARDEDALLOC
176  MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:Strip")
177 #endif
178 };
179 
180 class StrokeRep {
181  protected:
183  vector<Strip *> _strips;
185  unsigned int _textureId;
187  MTex *_mtex[MAX_MTEX];
190  bool _hasTex;
191 
192  // float _averageTextureAlpha;
193 
194  public:
195  StrokeRep();
196  StrokeRep(const StrokeRep &);
197  StrokeRep(Stroke *iStroke);
198  virtual ~StrokeRep();
199 
201  virtual void create();
202 
204  virtual void Render(const StrokeRenderer *iRenderer);
205 
208  {
209  return _strokeType;
210  }
211 
212  inline unsigned getTextureId() const
213  {
214  return _textureId;
215  }
216 
217  inline MTex *getMTex(int idx) const
218  {
219  return _mtex[idx];
220  }
221 
222  inline Material *getMaterial() const
223  {
224  return _material;
225  }
226 
227  inline bNodeTree *getNodeTree() const
228  {
229  return _nodeTree;
230  }
231 
232  inline bool hasTex() const
233  {
234  return _hasTex;
235  }
236 
237  inline vector<Strip *> &getStrips()
238  {
239  return _strips;
240  }
241 
242  inline unsigned int getNumberOfStrips() const
243  {
244  return _strips.size();
245  }
246 
247  inline Stroke *getStroke()
248  {
249  return _stroke;
250  }
251 
254  {
255  _strokeType = itype;
256  }
257 
258  inline void setTextureId(unsigned textureId)
259  {
260  _textureId = textureId;
261  }
262 
263  inline void setMaterial(Material *mat)
264  {
265  _material = mat;
266  }
267 #if 0
268  inline void setMTex(int idx, MTex *mtex_ptr)
269  {
270  _mtex[idx] = mtex_ptr;
271  }
272 #endif
273 
274 #ifdef WITH_CXX_GUARDEDALLOC
275  MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:StrokeRep")
276 #endif
277 };
278 
279 } /* namespace Freestyle */
struct Strip Strip
Read Guarded memory(de)allocation.
struct Render Render
Definition: RE_pipeline.h:54
Classes to define a stroke.
#define MAX_MTEX
Definition: Stroke.h:45
ATTR_WARN_UNUSED_RESULT BMesh const char itype
vertex_container _vertices
Definition: StrokeRep.h:142
std::vector< StrokeVertexRep * > vertex_container
Definition: StrokeRep.h:139
float _averageThickness
Definition: StrokeRep.h:143
vertex_container & vertices()
Definition: StrokeRep.h:170
int sizeStrip() const
Definition: StrokeRep.h:165
unsigned int getNumberOfStrips() const
Definition: StrokeRep.h:242
Stroke::MediumType _strokeType
Definition: StrokeRep.h:184
void setMediumType(Stroke::MediumType itype)
Definition: StrokeRep.h:253
bNodeTree * getNodeTree() const
Definition: StrokeRep.h:227
MTex * getMTex(int idx) const
Definition: StrokeRep.h:217
Material * getMaterial() const
Definition: StrokeRep.h:222
bool hasTex() const
Definition: StrokeRep.h:232
Material * _material
Definition: StrokeRep.h:189
unsigned int _textureId
Definition: StrokeRep.h:185
Stroke * getStroke()
Definition: StrokeRep.h:247
vector< Strip * > _strips
Definition: StrokeRep.h:183
void setMaterial(Material *mat)
Definition: StrokeRep.h:263
void setTextureId(unsigned textureId)
Definition: StrokeRep.h:258
Stroke::MediumType getMediumType() const
Definition: StrokeRep.h:207
unsigned getTextureId() const
Definition: StrokeRep.h:212
vector< Strip * > & getStrips()
Definition: StrokeRep.h:237
bNodeTree * _nodeTree
Definition: StrokeRep.h:188
void setPoint2d(const Vec2r &p)
Definition: StrokeRep.h:100
void setAlpha(float a)
Definition: StrokeRep.h:120
Vec2r & texCoord(bool tips=false)
Definition: StrokeRep.h:80
void setTexCoord(const Vec2r &p, bool tips=false)
Definition: StrokeRep.h:105
void setColor(const Vec3r &p)
Definition: StrokeRep.h:115
StrokeVertexRep(const Vec2r &iPoint2d)
Definition: StrokeRep.h:64
inherits from class Rep
Definition: AppCanvas.cpp:32
static unsigned a[3]
Definition: RandGen.cpp:92