Blender V5.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
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
19
20namespace blender {
21struct bNodeTree;
22struct MTex;
23} // namespace blender
24
25namespace Freestyle {
26
27using namespace Geometry;
28
29#if 0
30// symbolic constant to call the appropriate renderers and textures
31# define NO_TEXTURE_WITH_BLEND_STROKE -2
32# define NO_TEXTURE_STROKE -1
33# define PSEUDO_CHARCOAL_STROKE 0
34# define WASH_BRUSH_STROKE 1
35# define OIL_STROKE 2
36# define NO_BLEND_STROKE 3
37# define CHARCOAL_MIN_STROKE 4
38# define BRUSH_MIN_STROKE 5
39# define OPAQUE_DRY_STROKE 6
40# define OPAQUE_STROKE 7
41
42# define DEFAULT_STROKE 0
43
44# define NUMBER_STROKE_RENDERER 8
45
46#endif
47
49 public:
51
52 StrokeVertexRep(const Vec2r &iPoint2d)
53 {
54 _point2d = iPoint2d;
55 }
56
57 StrokeVertexRep(const StrokeVertexRep &iBrother);
58
59 virtual ~StrokeVertexRep() {}
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) {
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 MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:StrokeVertexRep")
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 MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:Strip")
160};
161
163 protected:
165 vector<Strip *> _strips;
173
174 // float _averageTextureAlpha;
175
176 public:
177 StrokeRep();
178 StrokeRep(const StrokeRep &);
179 StrokeRep(Stroke *iStroke);
180 virtual ~StrokeRep();
181
183 virtual void create();
184
186 virtual void Render(const StrokeRenderer *iRenderer);
187
190 {
191 return _strokeType;
192 }
193
194 inline uint getTextureId() const
195 {
196 return _textureId;
197 }
198
199 inline blender::MTex *getMTex(int idx) const
200 {
201 return _mtex[idx];
202 }
203
205 {
206 return _material;
207 }
208
210 {
211 return _nodeTree;
212 }
213
214 inline bool hasTex() const
215 {
216 return _hasTex;
217 }
218
219 inline vector<Strip *> &getStrips()
220 {
221 return _strips;
222 }
223
224 inline uint getNumberOfStrips() const
225 {
226 return _strips.size();
227 }
228
230 {
231 return _stroke;
232 }
233
236 {
237 _strokeType = itype;
238 }
239
240 inline void setTextureId(uint textureId)
241 {
242 _textureId = textureId;
243 }
244
246 {
247 _material = mat;
248 }
249#if 0
250 inline void setMTex(int idx, blender::MTex *mtex_ptr)
251 {
252 _mtex[idx] = mtex_ptr;
253 }
254#endif
255
256 MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:StrokeRep")
257};
258
259} /* namespace Freestyle */
Vectors and Matrices (useful type definitions).
Read Blender memory allocation and freeing.
Classes to define a stroke.
#define MAX_MTEX
Definition Stroke.h:31
void createStrip(const std::vector< StrokeVertex * > &iStrokeVertices)
vertex_container & vertices()
Definition StrokeRep.h:154
vertex_container _vertices
Definition StrokeRep.h:126
Strip(const std::vector< StrokeVertex * > &iStrokeVertices, bool hasTex=false, bool tipBegin=false, bool tipEnd=false, float texStep=1.0)
Definition StrokeRep.cpp:41
std::vector< StrokeVertexRep * > vertex_container
Definition StrokeRep.h:123
float _averageThickness
Definition StrokeRep.h:127
int sizeStrip() const
Definition StrokeRep.h:149
void cleanUpSingularities(const std::vector< StrokeVertex * > &iStrokeVertices)
void computeTexCoord(const std::vector< StrokeVertex * > &iStrokeVertices, float texStep)
void computeTexCoordWithTips(const std::vector< StrokeVertex * > &iStrokeVertices, bool tipBegin, bool tipEnd, float texStep)
void setVertexColor(const std::vector< StrokeVertex * > &iStrokeVertices)
Stroke::MediumType _strokeType
Definition StrokeRep.h:166
void setMediumType(Stroke::MediumType itype)
Definition StrokeRep.h:235
uint getNumberOfStrips() const
Definition StrokeRep.h:224
void setTextureId(uint textureId)
Definition StrokeRep.h:240
bool hasTex() const
Definition StrokeRep.h:214
blender::Material * _material
Definition StrokeRep.h:171
blender::MTex * getMTex(int idx) const
Definition StrokeRep.h:199
blender::bNodeTree * _nodeTree
Definition StrokeRep.h:170
blender::bNodeTree * getNodeTree() const
Definition StrokeRep.h:209
virtual void create()
vector< Strip * > _strips
Definition StrokeRep.h:165
vector< Strip * > & getStrips()
Definition StrokeRep.h:219
Stroke::MediumType getMediumType() const
Definition StrokeRep.h:189
Stroke * getStroke()
Definition StrokeRep.h:229
blender::Material * getMaterial() const
Definition StrokeRep.h:204
virtual void Render(const StrokeRenderer *iRenderer)
void setMaterial(blender::Material *mat)
Definition StrokeRep.h:245
blender::MTex * _mtex[MAX_MTEX]
Definition StrokeRep.h:169
uint getTextureId() const
Definition StrokeRep.h:194
void setPoint2d(const Vec2r &p)
Definition StrokeRep.h:86
void setTexCoord(const Vec2r &p, bool tips=false)
Definition StrokeRep.h:91
void setColor(const Vec3r &p)
Definition StrokeRep.h:101
Vec2r & texCoord(bool tips=false)
Definition StrokeRep.h:66
StrokeVertexRep(const Vec2r &iPoint2d)
Definition StrokeRep.h:52
VecMat::Vec2< real > Vec2r
Definition Geom.h:24
VecMat::Vec3< real > Vec3r
Definition Geom.h:30
inherits from class Rep
Definition AppCanvas.cpp:20
BMesh Iterators.