Blender  V3.3
StrokeRep.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #pragma once
4 
10 #include "Stroke.h"
11 
12 #include "../geometry/Geom.h"
13 
14 #ifdef WITH_CXX_GUARDEDALLOC
15 # include "MEM_guardedalloc.h"
16 #endif
17 
18 #include "DNA_material_types.h" // for MAX_MTEX
19 struct bNodeTree;
20 
21 namespace Freestyle {
22 
23 using namespace Geometry;
24 
25 #if 0
26 //symbolic constant to call the appropriate renderers and textures
27 # define NO_TEXTURE_WITH_BLEND_STROKE -2
28 # define NO_TEXTURE_STROKE -1
29 # define PSEUDO_CHARCOAL_STROKE 0
30 # define WASH_BRUSH_STROKE 1
31 # define OIL_STROKE 2
32 # define NO_BLEND_STROKE 3
33 # define CHARCOAL_MIN_STROKE 4
34 # define BRUSH_MIN_STROKE 5
35 # define OPAQUE_DRY_STROKE 6
36 # define OPAQUE_STROKE 7
37 
38 # define DEFAULT_STROKE 0
39 
40 # define NUMBER_STROKE_RENDERER 8
41 
42 #endif
43 
45  public:
47  {
48  }
49 
50  StrokeVertexRep(const Vec2r &iPoint2d)
51  {
52  _point2d = iPoint2d;
53  }
54 
55  StrokeVertexRep(const StrokeVertexRep &iBrother);
56 
57  virtual ~StrokeVertexRep()
58  {
59  }
60 
61  inline Vec2r &point2d()
62  {
63  return _point2d;
64  }
65 
66  inline Vec2r &texCoord(bool tips = false)
67  {
68  if (tips) {
69  return _texCoord_w_tips;
70  }
71  else {
72  return _texCoord;
73  }
74  }
75 
76  inline Vec3r &color()
77  {
78  return _color;
79  }
80 
81  inline float alpha()
82  {
83  return _alpha;
84  }
85 
86  inline void setPoint2d(const Vec2r &p)
87  {
88  _point2d = p;
89  }
90 
91  inline void setTexCoord(const Vec2r &p, bool tips = false)
92  {
93  if (tips) {
94  _texCoord_w_tips = p;
95  }
96  else {
97  _texCoord = p;
98  }
99  }
100 
101  inline void setColor(const Vec3r &p)
102  {
103  _color = p;
104  }
105 
106  inline void setAlpha(float a)
107  {
108  _alpha = a;
109  }
110 
111  protected:
116  float _alpha;
117 
118 #ifdef WITH_CXX_GUARDEDALLOC
119  MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:StrokeVertexRep")
120 #endif
121 };
122 
123 class Strip {
124  public:
125  typedef std::vector<StrokeVertexRep *> vertex_container;
126 
127  protected:
130 
131  public:
132  Strip(const std::vector<StrokeVertex *> &iStrokeVertices,
133  bool hasTex = false,
134  bool tipBegin = false,
135  bool tipEnd = false,
136  float texStep = 1.0);
137  Strip(const Strip &iBrother);
138  virtual ~Strip();
139 
140  protected:
141  void createStrip(const std::vector<StrokeVertex *> &iStrokeVertices);
142  void cleanUpSingularities(const std::vector<StrokeVertex *> &iStrokeVertices);
143  void setVertexColor(const std::vector<StrokeVertex *> &iStrokeVertices);
144  void computeTexCoord(const std::vector<StrokeVertex *> &iStrokeVertices, float texStep);
145  void computeTexCoordWithTips(const std::vector<StrokeVertex *> &iStrokeVertices,
146  bool tipBegin,
147  bool tipEnd,
148  float texStep);
149 
150  public:
151  inline int sizeStrip() const
152  {
153  return _vertices.size();
154  }
155 
157  {
158  return _vertices;
159  }
160 
161 #ifdef WITH_CXX_GUARDEDALLOC
162  MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:Strip")
163 #endif
164 };
165 
166 class StrokeRep {
167  protected:
169  vector<Strip *> _strips;
171  unsigned int _textureId;
173  MTex *_mtex[MAX_MTEX];
176  bool _hasTex;
177 
178  // float _averageTextureAlpha;
179 
180  public:
181  StrokeRep();
182  StrokeRep(const StrokeRep &);
183  StrokeRep(Stroke *iStroke);
184  virtual ~StrokeRep();
185 
187  virtual void create();
188 
190  virtual void Render(const StrokeRenderer *iRenderer);
191 
194  {
195  return _strokeType;
196  }
197 
198  inline unsigned getTextureId() const
199  {
200  return _textureId;
201  }
202 
203  inline MTex *getMTex(int idx) const
204  {
205  return _mtex[idx];
206  }
207 
208  inline Material *getMaterial() const
209  {
210  return _material;
211  }
212 
213  inline bNodeTree *getNodeTree() const
214  {
215  return _nodeTree;
216  }
217 
218  inline bool hasTex() const
219  {
220  return _hasTex;
221  }
222 
223  inline vector<Strip *> &getStrips()
224  {
225  return _strips;
226  }
227 
228  inline unsigned int getNumberOfStrips() const
229  {
230  return _strips.size();
231  }
232 
233  inline Stroke *getStroke()
234  {
235  return _stroke;
236  }
237 
240  {
241  _strokeType = itype;
242  }
243 
244  inline void setTextureId(unsigned textureId)
245  {
246  _textureId = textureId;
247  }
248 
249  inline void setMaterial(Material *mat)
250  {
251  _material = mat;
252  }
253 #if 0
254  inline void setMTex(int idx, MTex *mtex_ptr)
255  {
256  _mtex[idx] = mtex_ptr;
257  }
258 #endif
259 
260 #ifdef WITH_CXX_GUARDEDALLOC
261  MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:StrokeRep")
262 #endif
263 };
264 
265 } /* namespace Freestyle */
struct Strip Strip
Read Guarded memory(de)allocation.
struct Render Render
Definition: RE_pipeline.h:39
Classes to define a stroke.
#define MAX_MTEX
Definition: Stroke.h:31
ATTR_WARN_UNUSED_RESULT BMesh const char itype
vertex_container _vertices
Definition: StrokeRep.h:128
std::vector< StrokeVertexRep * > vertex_container
Definition: StrokeRep.h:125
float _averageThickness
Definition: StrokeRep.h:129
vertex_container & vertices()
Definition: StrokeRep.h:156
int sizeStrip() const
Definition: StrokeRep.h:151
unsigned int getNumberOfStrips() const
Definition: StrokeRep.h:228
Stroke::MediumType _strokeType
Definition: StrokeRep.h:170
void setMediumType(Stroke::MediumType itype)
Definition: StrokeRep.h:239
bNodeTree * getNodeTree() const
Definition: StrokeRep.h:213
MTex * getMTex(int idx) const
Definition: StrokeRep.h:203
Material * getMaterial() const
Definition: StrokeRep.h:208
bool hasTex() const
Definition: StrokeRep.h:218
Material * _material
Definition: StrokeRep.h:175
unsigned int _textureId
Definition: StrokeRep.h:171
Stroke * getStroke()
Definition: StrokeRep.h:233
vector< Strip * > _strips
Definition: StrokeRep.h:169
void setMaterial(Material *mat)
Definition: StrokeRep.h:249
void setTextureId(unsigned textureId)
Definition: StrokeRep.h:244
Stroke::MediumType getMediumType() const
Definition: StrokeRep.h:193
unsigned getTextureId() const
Definition: StrokeRep.h:198
vector< Strip * > & getStrips()
Definition: StrokeRep.h:223
bNodeTree * _nodeTree
Definition: StrokeRep.h:174
void setPoint2d(const Vec2r &p)
Definition: StrokeRep.h:86
void setAlpha(float a)
Definition: StrokeRep.h:106
Vec2r & texCoord(bool tips=false)
Definition: StrokeRep.h:66
void setTexCoord(const Vec2r &p, bool tips=false)
Definition: StrokeRep.h:91
void setColor(const Vec3r &p)
Definition: StrokeRep.h:101
StrokeVertexRep(const Vec2r &iPoint2d)
Definition: StrokeRep.h:50
inherits from class Rep
Definition: AppCanvas.cpp:18
static unsigned a[3]
Definition: RandGen.cpp:78
std::unique_ptr< IDProperty, IDPropertyDeleter > create(StringRefNull prop_name, int32_t value)
Allocate a new IDProperty of type IDP_INT, set its name and value.