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