Blender V4.3
Stroke.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 <map>
13#include <vector>
14
15#include "Curve.h"
16
19
22
23#ifdef WITH_CXX_GUARDEDALLOC
24# include "MEM_guardedalloc.h"
25#endif
26
27extern "C" {
28struct MTex;
29struct bNodeTree;
30}
31
32#ifndef MAX_MTEX
33# define MAX_MTEX 18
34#endif
35
36namespace Freestyle {
37
38//
39// StrokeAttribute
40//
42
47 public:
50
52 StrokeAttribute(const StrokeAttribute &iBrother);
53
68 StrokeAttribute(float iRColor,
69 float iGColor,
70 float iBColor,
71 float iAlpha,
72 float iRThickness,
73 float iLThickness);
74
84 StrokeAttribute(const StrokeAttribute &a1, const StrokeAttribute &a2, float t);
85
87 virtual ~StrokeAttribute();
88
89 /* operators */
92
93 /* accessors */
97 inline const float *getColor() const
98 {
99 return _color;
100 }
101
103 inline const float getColorR() const
104 {
105 return _color[0];
106 }
107
109 inline const float getColorG() const
110 {
111 return _color[1];
112 }
113
115 inline const float getColorB() const
116 {
117 return _color[2];
118 }
119
121 inline Vec3f getColorRGB() const
122 {
123 return Vec3f(_color[0], _color[1], _color[2]);
124 }
125
127 inline float getAlpha() const
128 {
129 return _alpha;
130 }
131
136 inline const float *getThickness() const
137 {
138 return _thickness;
139 }
140
142 inline const float getThicknessR() const
143 {
144 return _thickness[0];
145 }
146
148 inline const float getThicknessL() const
149 {
150 return _thickness[1];
151 }
152
155 inline Vec2f getThicknessRL() const
156 {
157 return Vec2f(_thickness[0], _thickness[1]);
158 }
159
161 inline bool isVisible() const
162 {
163 return _visible;
164 }
165
170 float getAttributeReal(const char *iName) const;
171
176 Vec2f getAttributeVec2f(const char *iName) const;
177
182 Vec3f getAttributeVec3f(const char *iName) const;
183
185 bool isAttributeAvailableReal(const char *iName) const;
186
188 bool isAttributeAvailableVec2f(const char *iName) const;
189
191 bool isAttributeAvailableVec3f(const char *iName) const;
192
193 /* modifiers */
202 inline void setColor(float r, float g, float b)
203 {
204 _color[0] = r;
205 _color[1] = g;
206 _color[2] = b;
207 }
208
213 inline void setColor(const Vec3f &iRGB)
214 {
215 _color[0] = iRGB[0];
216 _color[1] = iRGB[1];
217 _color[2] = iRGB[2];
218 }
219
224 inline void setAlpha(float alpha)
225 {
226 _alpha = alpha;
227 }
228
235 inline void setThickness(float tr, float tl)
236 {
237 _thickness[0] = tr;
238 _thickness[1] = tl;
239 }
240
245 inline void setThickness(const Vec2f &tRL)
246 {
247 _thickness[0] = tRL[0];
248 _thickness[1] = tRL[1];
249 }
250
252 inline void setVisible(bool iVisible)
253 {
254 _visible = iVisible;
255 }
256
265 void setAttributeReal(const char *iName, float att);
266
275 void setAttributeVec2f(const char *iName, const Vec2f &att);
276
285 void setAttributeVec3f(const char *iName, const Vec3f &att);
286
287 private:
288 typedef std::map<const char *, float, StringUtils::ltstr> realMap;
289 typedef std::map<const char *, Vec2f, StringUtils::ltstr> Vec2fMap;
290 typedef std::map<const char *, Vec3f, StringUtils::ltstr> Vec3fMap;
291
293 float _color[3];
295 float _alpha;
297 float _thickness[2];
298 bool _visible;
299 realMap *_userAttributesReal;
300 Vec2fMap *_userAttributesVec2f;
301 Vec3fMap *_userAttributesVec3f;
302
303#ifdef WITH_CXX_GUARDEDALLOC
304 MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:StrokeAttribute")
305#endif
306};
307
308//
309// StrokeVertex
310//
312
314class StrokeVertex : public CurvePoint {
315 public: // Implementation of Interface0D
317 virtual string getExactTypeName() const
318 {
319 return "StrokeVertex";
320 }
321
322 private:
323 StrokeAttribute _Attribute;
324 float _CurvilignAbscissa;
325 float _StrokeLength; // stroke length
326
327 public:
329 StrokeVertex();
330
332 StrokeVertex(const StrokeVertex &iBrother);
333
335 StrokeVertex(SVertex *iSVertex);
336
338 StrokeVertex(CurvePoint *iPoint);
339
341 StrokeVertex(StrokeVertex *iA, StrokeVertex *iB, float t3);
342
344 StrokeVertex(SVertex *iSVertex, const StrokeAttribute &iAttribute);
345
346 /* operators */
348 StrokeVertex &operator=(const StrokeVertex &iBrother);
349
350 /* accessors */
352 inline real x() const
353 {
354 return _Point2d[0];
355 }
356
358 inline real y() const
359 {
360 return _Point2d[1];
361 }
362
364 inline Vec2r getPoint() const
365 {
366 return getPoint2D();
367 }
368
370 inline real operator[](const int i) const
371 {
372 return _Point2d[i];
373 }
374
376 inline const StrokeAttribute &attribute() const
377 {
378 return _Attribute;
379 }
380
383 {
384 return _Attribute;
385 }
386
388 inline float curvilinearAbscissa() const
389 {
390 return _CurvilignAbscissa;
391 }
392
394 inline float strokeLength() const
395 {
396 return _StrokeLength;
397 }
398
400 inline float u() const
401 {
402 return _CurvilignAbscissa / _StrokeLength;
403 }
404
405 /* modifiers */
407 inline void setX(real x)
408 {
409 _Point2d[0] = x;
410 }
411
413 inline void setY(real y)
414 {
415 _Point2d[1] = y;
416 }
417
419 inline void setPoint(real x, real y)
420 {
421 _Point2d[0] = x;
422 _Point2d[1] = y;
423 }
424
426 inline void setPoint(const Vec2r &p)
427 {
428 _Point2d[0] = p[0];
429 _Point2d[1] = p[1];
430 }
431
433 inline real &operator[](const int i)
434 {
435 return _Point2d[i];
436 }
437
439 inline void setAttribute(const StrokeAttribute &iAttribute)
440 {
441 _Attribute = iAttribute;
442 }
443
445 inline void setCurvilinearAbscissa(float iAbscissa)
446 {
447 _CurvilignAbscissa = iAbscissa;
448 }
449
453 inline void setStrokeLength(float iLength)
454 {
455 _StrokeLength = iLength;
456 }
457
458 /* interface definition */
459 /* inherited */
460
461#ifdef WITH_CXX_GUARDEDALLOC
462 MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:StrokeVertex")
463#endif
464};
465
466//
467// Stroke
468//
470
471class StrokeRenderer;
472class StrokeRep;
473
474namespace StrokeInternal {
475
478template<class Traits> class vertex_iterator_base;
480
481} // end of namespace StrokeInternal
482
489class Stroke : public Interface1D {
490 public: // Implementation of Interface1D
492 virtual string getExactTypeName() const
493 {
494 return "Stroke";
495 }
496
497 // Data access methods
498
500 virtual Id getId() const
501 {
502 return _id;
503 }
504
511
512 public:
513 typedef std::deque<StrokeVertex *> vertex_container; // the vertices container
514 typedef std::vector<ViewEdge *> viewedge_container; // the viewedges container
519
520 public:
521 // typedef StrokeVertex vertex_type;
522
523 private:
524 vertex_container _Vertices;
525 Id _id;
526 float _Length; // The stroke length
527 viewedge_container _ViewEdges;
528 float _sampling;
529 float _textureStep;
530 // StrokeRenderer *_renderer; // mark implementation OpenGL renderer
531 MediumType _mediumType;
532 uint _textureId;
533 MTex *_mtex[MAX_MTEX];
534 bNodeTree *_nodeTree;
535 bool _tips;
536 StrokeRep *_rep;
537 Vec2r _extremityOrientations[2]; // the orientations of the first and last extermity
538
539 public:
541 Stroke();
542
544 Stroke(const Stroke &iBrother);
545
554 template<class InputVertexIterator> Stroke(InputVertexIterator iBegin, InputVertexIterator iEnd);
555
557 virtual ~Stroke();
558
559 /* operators */
561 Stroke &operator=(const Stroke &iBrother);
562
572 float ComputeSampling(int iNVertices);
573
581 int Resample(int iNPoints);
582
589 int Resample(float iSampling);
590
593 void RemoveAllVertices();
594
600 void RemoveVertex(StrokeVertex *iVertex);
601
610
612 void UpdateLength();
613
614 /* Render method */
615 void ScaleThickness(float iFactor);
616 void Render(const StrokeRenderer *iRenderer);
617 void RenderBasic(const StrokeRenderer *iRenderer);
618
619 /* Iterator definition */
620
621 /* accessors */
623 inline real getLength2D() const
624 {
625 return _Length;
626 }
627
631 {
632 return _mediumType;
633 }
634
637 {
638 return _textureId;
639 }
640
642 inline float getTextureStep()
643 {
644 return _textureStep;
645 }
646
648 inline MTex *getMTex(int idx)
649 {
650 return _mtex[idx];
651 }
652
655 {
656 return _nodeTree;
657 }
658
660 inline bool hasTex() const
661 {
662 return (_mtex[0] != nullptr) || _nodeTree;
663 }
664
666 inline bool hasTips() const
667 {
668 return _tips;
669 }
670
671 /* these advanced iterators are used only in C++ */
672 inline int vertices_size() const
673 {
674 return _Vertices.size();
675 }
676
677 inline viewedge_container::const_iterator viewedges_begin() const
678 {
679 return _ViewEdges.begin();
680 }
681
682 inline viewedge_container::iterator viewedges_begin()
683 {
684 return _ViewEdges.begin();
685 }
686
687 inline viewedge_container::const_iterator viewedges_end() const
688 {
689 return _ViewEdges.end();
690 }
691
692 inline viewedge_container::iterator viewedges_end()
693 {
694 return _ViewEdges.end();
695 }
696
697 inline int viewedges_size() const
698 {
699 return _ViewEdges.size();
700 }
701
703 {
704 return _extremityOrientations[0];
705 }
706
708 {
709 return _extremityOrientations[0].x();
710 }
711
713 {
714 return _extremityOrientations[0].y();
715 }
716
718 {
719 return _extremityOrientations[1];
720 }
721
723 {
724 return _extremityOrientations[1].x();
725 }
726
728 {
729 return _extremityOrientations[1].y();
730 }
731
732 /* modifiers */
734 inline void setId(const Id &id)
735 {
736 _id = id;
737 }
738
740 void setLength(float iLength);
741
743 inline void setMediumType(MediumType iType)
744 {
745 _mediumType = iType;
746 }
747
749 inline void setTextureId(uint id)
750 {
751 _textureId = id;
752 }
753
755 inline void setTextureStep(float step)
756 {
757 _textureStep = step;
758 }
759
761 inline int setMTex(MTex *mtex)
762 {
763 for (int a = 0; a < MAX_MTEX; a++) {
764 if (!_mtex[a]) {
765 _mtex[a] = mtex;
766 return 0;
767 }
768 }
769 return -1; /* no free slots */
770 }
771
773 inline void setNodeTree(bNodeTree *iNodeTree)
774 {
775 _nodeTree = iNodeTree;
776 }
777
779 inline void setTips(bool iTips)
780 {
781 _tips = iTips;
782 }
783
784 inline void push_back(StrokeVertex *iVertex)
785 {
786 _Vertices.push_back(iVertex);
787 }
788
789 inline void push_front(StrokeVertex *iVertex)
790 {
791 _Vertices.push_front(iVertex);
792 }
793
794 inline void AddViewEdge(ViewEdge *iViewEdge)
795 {
796 _ViewEdges.push_back(iViewEdge);
797 }
798
799 inline void setBeginningOrientation(const Vec2r &iOrientation)
800 {
801 _extremityOrientations[0] = iOrientation;
802 }
803
805 {
806 _extremityOrientations[0] = Vec2r(x, y);
807 }
808
809 inline void setEndingOrientation(const Vec2r &iOrientation)
810 {
811 _extremityOrientations[1] = iOrientation;
812 }
813
815 {
816 _extremityOrientations[1] = Vec2r(x, y);
817 }
818
819 /* Information access interface */
820
821 // embedding vertex iterator
823 vertex_iterator vertices_begin(float sampling = 0.0f);
826
834
837
840 {
841 return _Vertices.size();
842 }
843
846 {
847 return *(_Vertices.at(i));
848 }
849
850 // Iterator access (Interface1D)
853
856
857 virtual Interface0DIterator pointsBegin(float t = 0.0f);
858 virtual Interface0DIterator pointsEnd(float t = 0.0f);
859
860#ifdef WITH_CXX_GUARDEDALLOC
861 MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:Stroke")
862#endif
863};
864
865//
866// Implementation
867//
869
870template<class InputVertexIterator>
871Stroke::Stroke(InputVertexIterator iBegin, InputVertexIterator iEnd)
872{
873 for (InputVertexIterator v = iBegin, vend = iEnd; v != vend; v++) {
874 _Vertices.push_back(*v);
875 }
876 _Length = 0;
877 _id = 0;
878}
879
880} /* namespace Freestyle */
unsigned int uint
Class to define a container for curves.
Configuration definitions.
Interface 1D and related tools definitions.
Read Guarded memory(de)allocation.
struct Render Render
Definition RE_pipeline.h:43
Classes to define a silhouette structure.
String utilities.
#define MAX_MTEX
Definition Stroke.h:33
ATTR_WARN_UNUSED_RESULT const BMVert * v
virtual Vec2r getPoint2D() const
Definition Curve.h:102
void setThickness(const Vec2f &tRL)
Definition Stroke.h:245
void setVisible(bool iVisible)
Definition Stroke.h:252
bool isAttributeAvailableVec3f(const char *iName) const
Definition Stroke.cpp:289
Vec2f getThicknessRL() const
Definition Stroke.h:155
void setThickness(float tr, float tl)
Definition Stroke.h:235
Vec3f getAttributeVec3f(const char *iName) const
Definition Stroke.cpp:246
void setAttributeReal(const char *iName, float att)
Definition Stroke.cpp:301
const float * getThickness() const
Definition Stroke.h:136
const float * getColor() const
Definition Stroke.h:97
const float getThicknessR() const
Definition Stroke.h:142
const float getColorR() const
Definition Stroke.h:103
void setAttributeVec3f(const char *iName, const Vec3f &att)
Definition Stroke.cpp:317
const float getColorB() const
Definition Stroke.h:115
bool isVisible() const
Definition Stroke.h:161
const float getThicknessL() const
Definition Stroke.h:148
Vec3f getColorRGB() const
Definition Stroke.h:121
float getAlpha() const
Definition Stroke.h:127
void setColor(float r, float g, float b)
Definition Stroke.h:202
const float getColorG() const
Definition Stroke.h:109
bool isAttributeAvailableVec2f(const char *iName) const
Definition Stroke.cpp:277
void setAlpha(float alpha)
Definition Stroke.h:224
void setColor(const Vec3f &iRGB)
Definition Stroke.h:213
Vec2f getAttributeVec2f(const char *iName) const
Definition Stroke.cpp:227
void setAttributeVec2f(const char *iName, const Vec2f &att)
Definition Stroke.cpp:309
StrokeAttribute & operator=(const StrokeAttribute &iBrother)
Definition Stroke.cpp:168
bool isAttributeAvailableReal(const char *iName) const
Definition Stroke.cpp:265
float getAttributeReal(const char *iName) const
Definition Stroke.cpp:208
real & operator[](const int i)
Definition Stroke.h:433
float curvilinearAbscissa() const
Definition Stroke.h:388
Vec2r getPoint() const
Definition Stroke.h:364
void setCurvilinearAbscissa(float iAbscissa)
Definition Stroke.h:445
real operator[](const int i) const
Definition Stroke.h:370
void setY(real y)
Definition Stroke.h:413
void setAttribute(const StrokeAttribute &iAttribute)
Definition Stroke.h:439
float u() const
Definition Stroke.h:400
float strokeLength() const
Definition Stroke.h:394
void setX(real x)
Definition Stroke.h:407
void setPoint(real x, real y)
Definition Stroke.h:419
const StrokeAttribute & attribute() const
Definition Stroke.h:376
void setPoint(const Vec2r &p)
Definition Stroke.h:426
StrokeVertex & operator=(const StrokeVertex &iBrother)
Definition Stroke.cpp:374
void setStrokeLength(float iLength)
Definition Stroke.h:453
virtual string getExactTypeName() const
Definition Stroke.h:317
StrokeAttribute & attribute()
Definition Stroke.h:382
virtual Interface0DIterator pointsEnd(float t=0.0f)
Definition Stroke.cpp:790
viewedge_container::iterator viewedges_end()
Definition Stroke.h:692
void setTextureId(uint id)
Definition Stroke.h:749
const_vertex_iterator vertices_begin() const
embedding vertex iterator
Definition Stroke.cpp:741
bool hasTex() const
Definition Stroke.h:660
viewedge_container::const_iterator viewedges_end() const
Definition Stroke.h:687
void push_back(StrokeVertex *iVertex)
Definition Stroke.h:784
void setId(const Id &id)
Definition Stroke.h:734
StrokeVertex & strokeVerticeAt(uint i)
Definition Stroke.h:845
void setBeginningOrientation(const Vec2r &iOrientation)
Definition Stroke.h:799
MTex * getMTex(int idx)
Definition Stroke.h:648
virtual Id getId() const
Definition Stroke.h:500
int viewedges_size() const
Definition Stroke.h:697
uint getTextureId()
Definition Stroke.h:636
void setTextureStep(float step)
Definition Stroke.h:755
void ScaleThickness(float iFactor)
Definition Stroke.cpp:795
void setBeginningOrientation(real x, real y)
Definition Stroke.h:804
virtual Interface0DIterator verticesBegin()
Definition Stroke.cpp:771
StrokeInternal::vertex_iterator_base< StrokeInternal::vertex_nonconst_traits > vertex_iterator
Definition Stroke.h:516
std::vector< ViewEdge * > viewedge_container
Definition Stroke.h:514
StrokeInternal::vertex_iterator_base< StrokeInternal::vertex_const_traits > const_vertex_iterator
Definition Stroke.h:518
void RemoveAllVertices()
Definition Stroke.cpp:693
void setEndingOrientation(real x, real y)
Definition Stroke.h:814
bNodeTree * getNodeTree()
Definition Stroke.h:654
void AddViewEdge(ViewEdge *iViewEdge)
Definition Stroke.h:794
virtual ~Stroke()
Definition Stroke.cpp:439
void RemoveVertex(StrokeVertex *iVertex)
Definition Stroke.cpp:703
void push_front(StrokeVertex *iVertex)
Definition Stroke.h:789
void InsertVertex(StrokeVertex *iVertex, StrokeInternal::StrokeVertexIterator next)
Definition Stroke.cpp:716
real getEndingOrientationX() const
Definition Stroke.h:722
int vertices_size() const
Definition Stroke.h:672
const_vertex_iterator vertices_end() const
Definition Stroke.cpp:746
std::deque< StrokeVertex * > vertex_container
Definition Stroke.h:513
bool hasTips() const
Definition Stroke.h:666
virtual Interface0DIterator verticesEnd()
Definition Stroke.cpp:778
real getBeginningOrientationY() const
Definition Stroke.h:712
float getTextureStep()
Definition Stroke.h:642
void UpdateLength()
Definition Stroke.cpp:723
int setMTex(MTex *mtex)
Definition Stroke.h:761
void setEndingOrientation(const Vec2r &iOrientation)
Definition Stroke.h:809
uint strokeVerticesSize() const
Definition Stroke.h:839
void setTips(bool iTips)
Definition Stroke.h:779
MediumType getMediumType() const
Definition Stroke.h:630
virtual Interface0DIterator pointsBegin(float t=0.0f)
Definition Stroke.cpp:785
Vec2r getBeginningOrientation() const
Definition Stroke.h:702
void RenderBasic(const StrokeRenderer *iRenderer)
Definition Stroke.cpp:813
Stroke & operator=(const Stroke &iBrother)
Definition Stroke.cpp:456
void setLength(float iLength)
Definition Stroke.cpp:483
float ComputeSampling(int iNVertices)
Definition Stroke.cpp:491
viewedge_container::const_iterator viewedges_begin() const
Definition Stroke.h:677
StrokeInternal::StrokeVertexIterator strokeVerticesEnd()
Definition Stroke.cpp:765
Vec2r getEndingOrientation() const
Definition Stroke.h:717
viewedge_container::iterator viewedges_begin()
Definition Stroke.h:682
StrokeInternal::StrokeVertexIterator strokeVerticesBegin(float t=0.0f)
Definition Stroke.cpp:756
virtual string getExactTypeName() const
Definition Stroke.h:492
real getEndingOrientationY() const
Definition Stroke.h:727
void setNodeTree(bNodeTree *iNodeTree)
Definition Stroke.h:773
real getLength2D() const
Definition Stroke.h:623
int Resample(int iNPoints)
Definition Stroke.cpp:525
real getBeginningOrientationX() const
Definition Stroke.h:707
void setMediumType(MediumType iType)
Definition Stroke.h:743
value_type x() const
Definition VecMat.h:296
value_type y() const
Definition VecMat.h:306
local_group_size(16, 16) .push_constant(Type b
static ulong * next
VecMat::Vec3< float > Vec3f
Definition Geom.h:28
VecMat::Vec2< real > Vec2r
Definition Geom.h:24
VecMat::Vec2< float > Vec2f
Definition Geom.h:22
inherits from class Rep
Definition AppCanvas.cpp:20
static uint a[3]
Definition RandGen.cpp:82
double real
Definition Precision.h:14