Blender V5.0
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
11
12#include "Stroke.h"
13
14#include "../geometry/Geom.h"
15
16#include "MEM_guardedalloc.h"
17
18#include "DNA_material_types.h" // for MAX_MTEX
19struct bNodeTree;
20
21namespace Freestyle {
22
23using 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 StrokeVertexRep(const Vec2r &iPoint2d)
49 {
50 _point2d = iPoint2d;
51 }
52
53 StrokeVertexRep(const StrokeVertexRep &iBrother);
54
55 virtual ~StrokeVertexRep() {}
56
57 inline Vec2r &point2d()
58 {
59 return _point2d;
60 }
61
62 inline Vec2r &texCoord(bool tips = false)
63 {
64 if (tips) {
65 return _texCoord_w_tips;
66 }
67 else {
68 return _texCoord;
69 }
70 }
71
72 inline Vec3r &color()
73 {
74 return _color;
75 }
76
77 inline float alpha()
78 {
79 return _alpha;
80 }
81
82 inline void setPoint2d(const Vec2r &p)
83 {
84 _point2d = p;
85 }
86
87 inline void setTexCoord(const Vec2r &p, bool tips = false)
88 {
89 if (tips) {
91 }
92 else {
93 _texCoord = p;
94 }
95 }
96
97 inline void setColor(const Vec3r &p)
98 {
99 _color = p;
100 }
101
102 inline void setAlpha(float a)
103 {
104 _alpha = a;
105 }
106
107 protected:
112 float _alpha;
113
114 MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:StrokeVertexRep")
115};
116
117class Strip {
118 public:
119 typedef std::vector<StrokeVertexRep *> vertex_container;
120
121 protected:
124
125 public:
126 Strip(const std::vector<StrokeVertex *> &iStrokeVertices,
127 bool hasTex = false,
128 bool tipBegin = false,
129 bool tipEnd = false,
130 float texStep = 1.0);
131 Strip(const Strip &iBrother);
132 virtual ~Strip();
133
134 protected:
135 void createStrip(const std::vector<StrokeVertex *> &iStrokeVertices);
136 void cleanUpSingularities(const std::vector<StrokeVertex *> &iStrokeVertices);
137 void setVertexColor(const std::vector<StrokeVertex *> &iStrokeVertices);
138 void computeTexCoord(const std::vector<StrokeVertex *> &iStrokeVertices, float texStep);
139 void computeTexCoordWithTips(const std::vector<StrokeVertex *> &iStrokeVertices,
140 bool tipBegin,
141 bool tipEnd,
142 float texStep);
143
144 public:
145 inline int sizeStrip() const
146 {
147 return _vertices.size();
148 }
149
151 {
152 return _vertices;
153 }
154
155 MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:Strip")
156};
157
159 protected:
161 vector<Strip *> _strips;
169
170 // float _averageTextureAlpha;
171
172 public:
173 StrokeRep();
174 StrokeRep(const StrokeRep &);
175 StrokeRep(Stroke *iStroke);
176 virtual ~StrokeRep();
177
179 virtual void create();
180
182 virtual void Render(const StrokeRenderer *iRenderer);
183
186 {
187 return _strokeType;
188 }
189
190 inline uint getTextureId() const
191 {
192 return _textureId;
193 }
194
195 inline MTex *getMTex(int idx) const
196 {
197 return _mtex[idx];
198 }
199
200 inline Material *getMaterial() const
201 {
202 return _material;
203 }
204
205 inline bNodeTree *getNodeTree() const
206 {
207 return _nodeTree;
208 }
209
210 inline bool hasTex() const
211 {
212 return _hasTex;
213 }
214
215 inline vector<Strip *> &getStrips()
216 {
217 return _strips;
218 }
219
220 inline uint getNumberOfStrips() const
221 {
222 return _strips.size();
223 }
224
226 {
227 return _stroke;
228 }
229
232 {
234 }
235
236 inline void setTextureId(uint textureId)
237 {
238 _textureId = textureId;
239 }
240
241 inline void setMaterial(Material *mat)
242 {
243 _material = mat;
244 }
245#if 0
246 inline void setMTex(int idx, MTex *mtex_ptr)
247 {
248 _mtex[idx] = mtex_ptr;
249 }
250#endif
251
252 MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:StrokeRep")
253};
254
255} /* namespace Freestyle */
unsigned int uint
struct Strip Strip
Vectors and Matrices (useful type definitions).
Read Guarded memory(de)allocation.
Classes to define a stroke.
#define MAX_MTEX
Definition Stroke.h:31
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:150
vertex_container _vertices
Definition StrokeRep.h:122
std::vector< StrokeVertexRep * > vertex_container
Definition StrokeRep.h:119
float _averageThickness
Definition StrokeRep.h:123
void computeTexCoordWithTips(const std::vector< StrokeVertex * > &iStrokeVertices, bool tipBegin, bool tipEnd, float texStep)
int sizeStrip() const
Definition StrokeRep.h:145
void createStrip(const std::vector< StrokeVertex * > &iStrokeVertices)
Strip(const std::vector< StrokeVertex * > &iStrokeVertices, bool hasTex=false, bool tipBegin=false, bool tipEnd=false, float texStep=1.0)
Definition StrokeRep.cpp:41
virtual ~Strip()
Definition StrokeRep.cpp:72
Stroke::MediumType _strokeType
Definition StrokeRep.h:162
void setMediumType(Stroke::MediumType itype)
Definition StrokeRep.h:231
uint getNumberOfStrips() const
Definition StrokeRep.h:220
void setTextureId(uint textureId)
Definition StrokeRep.h:236
bool hasTex() const
Definition StrokeRep.h:210
MTex * getMTex(int idx) const
Definition StrokeRep.h:195
Material * _material
Definition StrokeRep.h:167
virtual void create()
Material * getMaterial() const
Definition StrokeRep.h:200
vector< Strip * > _strips
Definition StrokeRep.h:161
void setMaterial(Material *mat)
Definition StrokeRep.h:241
vector< Strip * > & getStrips()
Definition StrokeRep.h:215
Stroke::MediumType getMediumType() const
Definition StrokeRep.h:185
Stroke * getStroke()
Definition StrokeRep.h:225
bNodeTree * getNodeTree() const
Definition StrokeRep.h:205
MTex * _mtex[MAX_MTEX]
Definition StrokeRep.h:165
virtual void Render(const StrokeRenderer *iRenderer)
bNodeTree * _nodeTree
Definition StrokeRep.h:166
uint getTextureId() const
Definition StrokeRep.h:190
void setPoint2d(const Vec2r &p)
Definition StrokeRep.h:82
void setTexCoord(const Vec2r &p, bool tips=false)
Definition StrokeRep.h:87
void setColor(const Vec3r &p)
Definition StrokeRep.h:97
Vec2r & texCoord(bool tips=false)
Definition StrokeRep.h:62
StrokeVertexRep(const Vec2r &iPoint2d)
Definition StrokeRep.h:48
VecMat::Vec2< real > Vec2r
Definition Geom.h:24
VecMat::Vec3< real > Vec3r
Definition Geom.h:30
inherits from class Rep
Definition AppCanvas.cpp:20
static uint a[3]
Definition RandGen.cpp:82