Blender V5.0
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
11
12#include <map>
13#include <vector>
14
15#include "Curve.h"
16
19
22
23#include "MEM_guardedalloc.h"
24
25extern "C" {
26struct MTex;
27struct bNodeTree;
28}
29
30#ifndef MAX_MTEX
31# define MAX_MTEX 18
32#endif
33
34namespace Freestyle {
35
36//
37// StrokeAttribute
38//
40
45 public:
48
50 StrokeAttribute(const StrokeAttribute &iBrother);
51
66 StrokeAttribute(float iRColor,
67 float iGColor,
68 float iBColor,
69 float iAlpha,
70 float iRThickness,
71 float iLThickness);
72
82 StrokeAttribute(const StrokeAttribute &a1, const StrokeAttribute &a2, float t);
83
85 virtual ~StrokeAttribute();
86
87 /* operators */
90
91 /* accessors */
95 inline const float *getColor() const
96 {
97 return _color;
98 }
99
101 inline float getColorR() const
102 {
103 return _color[0];
104 }
105
107 inline float getColorG() const
108 {
109 return _color[1];
110 }
111
113 inline float getColorB() const
114 {
115 return _color[2];
116 }
117
119 inline Vec3f getColorRGB() const
120 {
121 return Vec3f(_color[0], _color[1], _color[2]);
122 }
123
125 inline float getAlpha() const
126 {
127 return _alpha;
128 }
129
134 inline const float *getThickness() const
135 {
136 return _thickness;
137 }
138
140 inline float getThicknessR() const
141 {
142 return _thickness[0];
143 }
144
146 inline float getThicknessL() const
147 {
148 return _thickness[1];
149 }
150
153 inline Vec2f getThicknessRL() const
154 {
155 return Vec2f(_thickness[0], _thickness[1]);
156 }
157
159 inline bool isVisible() const
160 {
161 return _visible;
162 }
163
168 float getAttributeReal(const char *iName) const;
169
174 Vec2f getAttributeVec2f(const char *iName) const;
175
180 Vec3f getAttributeVec3f(const char *iName) const;
181
183 bool isAttributeAvailableReal(const char *iName) const;
184
186 bool isAttributeAvailableVec2f(const char *iName) const;
187
189 bool isAttributeAvailableVec3f(const char *iName) const;
190
191 /* modifiers */
200 inline void setColor(float r, float g, float b)
201 {
202 _color[0] = r;
203 _color[1] = g;
204 _color[2] = b;
205 }
206
211 inline void setColor(const Vec3f &iRGB)
212 {
213 _color[0] = iRGB[0];
214 _color[1] = iRGB[1];
215 _color[2] = iRGB[2];
216 }
217
222 inline void setAlpha(float alpha)
223 {
224 _alpha = alpha;
225 }
226
233 inline void setThickness(float tr, float tl)
234 {
235 _thickness[0] = tr;
236 _thickness[1] = tl;
237 }
238
243 inline void setThickness(const Vec2f &tRL)
244 {
245 _thickness[0] = tRL[0];
246 _thickness[1] = tRL[1];
247 }
248
250 inline void setVisible(bool iVisible)
251 {
252 _visible = iVisible;
253 }
254
263 void setAttributeReal(const char *iName, float att);
264
273 void setAttributeVec2f(const char *iName, const Vec2f &att);
274
283 void setAttributeVec3f(const char *iName, const Vec3f &att);
284
285 private:
286 typedef std::map<const char *, float, StringUtils::ltstr> realMap;
287 typedef std::map<const char *, Vec2f, StringUtils::ltstr> Vec2fMap;
288 typedef std::map<const char *, Vec3f, StringUtils::ltstr> Vec3fMap;
289
291 float _color[3];
293 float _alpha;
295 float _thickness[2];
296 bool _visible;
297 realMap *_userAttributesReal;
298 Vec2fMap *_userAttributesVec2f;
299 Vec3fMap *_userAttributesVec3f;
300
301 MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:StrokeAttribute")
302};
303
304//
305// StrokeVertex
306//
308
310class StrokeVertex : public CurvePoint {
311 public: // Implementation of Interface0D
313 virtual string getExactTypeName() const
314 {
315 return "StrokeVertex";
316 }
317
318 private:
319 StrokeAttribute _Attribute;
320 float _CurvilignAbscissa;
321 float _StrokeLength; // stroke length
322
323 public:
325 StrokeVertex();
326
328 StrokeVertex(const StrokeVertex &iBrother);
329
331 StrokeVertex(SVertex *iSVertex);
332
334 StrokeVertex(CurvePoint *iPoint);
335
337 StrokeVertex(StrokeVertex *iA, StrokeVertex *iB, float t3);
338
340 StrokeVertex(SVertex *iSVertex, const StrokeAttribute &iAttribute);
341
342 /* operators */
344 StrokeVertex &operator=(const StrokeVertex &iBrother);
345
346 /* accessors */
348 inline real x() const
349 {
350 return _Point2d[0];
351 }
352
354 inline real y() const
355 {
356 return _Point2d[1];
357 }
358
360 inline Vec2r getPoint() const
361 {
362 return getPoint2D();
363 }
364
366 inline real operator[](const int i) const
367 {
368 return _Point2d[i];
369 }
370
372 inline const StrokeAttribute &attribute() const
373 {
374 return _Attribute;
375 }
376
379 {
380 return _Attribute;
381 }
382
384 inline float curvilinearAbscissa() const
385 {
386 return _CurvilignAbscissa;
387 }
388
390 inline float strokeLength() const
391 {
392 return _StrokeLength;
393 }
394
396 inline float u() const
397 {
398 return _CurvilignAbscissa / _StrokeLength;
399 }
400
401 /* modifiers */
403 inline void setX(real x)
404 {
405 _Point2d[0] = x;
406 }
407
409 inline void setY(real y)
410 {
411 _Point2d[1] = y;
412 }
413
415 inline void setPoint(real x, real y)
416 {
417 _Point2d[0] = x;
418 _Point2d[1] = y;
419 }
420
422 inline void setPoint(const Vec2r &p)
423 {
424 _Point2d[0] = p[0];
425 _Point2d[1] = p[1];
426 }
427
429 inline real &operator[](const int i)
430 {
431 return _Point2d[i];
432 }
433
435 inline void setAttribute(const StrokeAttribute &iAttribute)
436 {
437 _Attribute = iAttribute;
438 }
439
441 inline void setCurvilinearAbscissa(float iAbscissa)
442 {
443 _CurvilignAbscissa = iAbscissa;
444 }
445
449 inline void setStrokeLength(float iLength)
450 {
451 _StrokeLength = iLength;
452 }
453
454 /* interface definition */
455 /* inherited */
456
457 MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:StrokeVertex")
458};
459
460//
461// Stroke
462//
464
465class StrokeRenderer;
466class StrokeRep;
467
468namespace StrokeInternal {
469
472template<class Traits> class vertex_iterator_base;
474
475} // end of namespace StrokeInternal
476
483class Stroke : public Interface1D {
484 public: // Implementation of Interface1D
486 virtual string getExactTypeName() const
487 {
488 return "Stroke";
489 }
490
491 // Data access methods
492
494 virtual Id getId() const
495 {
496 return _id;
497 }
498
505
506 public:
507 typedef std::deque<StrokeVertex *> vertex_container; // the vertices container
508 typedef std::vector<ViewEdge *> viewedge_container; // the viewedges container
513
514 public:
515 // typedef StrokeVertex vertex_type;
516
517 private:
518 vertex_container _Vertices;
519 Id _id;
520 float _Length; // The stroke length
521 viewedge_container _ViewEdges;
522 float _sampling;
523 float _textureStep;
524 // StrokeRenderer *_renderer; // mark implementation OpenGL renderer
525 MediumType _mediumType;
526 uint _textureId;
527 MTex *_mtex[MAX_MTEX];
528 bNodeTree *_nodeTree;
529 bool _tips;
530 StrokeRep *_rep;
531 Vec2r _extremityOrientations[2]; // the orientations of the first and last extremity
532
533 public:
535 Stroke();
536
538 Stroke(const Stroke &iBrother);
539
548 template<class InputVertexIterator> Stroke(InputVertexIterator iBegin, InputVertexIterator iEnd);
549
551 virtual ~Stroke();
552
553 /* operators */
555 Stroke &operator=(const Stroke &iBrother);
556
566 float ComputeSampling(int iNVertices);
567
575 int Resample(int iNPoints);
576
583 int Resample(float iSampling);
584
587 void RemoveAllVertices();
588
594 void RemoveVertex(StrokeVertex *iVertex);
595
604
606 void UpdateLength();
607
608 /* Render method */
609 void ScaleThickness(float iFactor);
610 void Render(const StrokeRenderer *iRenderer);
611 void RenderBasic(const StrokeRenderer *iRenderer);
612
613 /* Iterator definition */
614
615 /* accessors */
617 inline real getLength2D() const
618 {
619 return _Length;
620 }
621
625 {
626 return _mediumType;
627 }
628
631 {
632 return _textureId;
633 }
634
636 inline float getTextureStep()
637 {
638 return _textureStep;
639 }
640
642 inline MTex *getMTex(int idx)
643 {
644 return _mtex[idx];
645 }
646
649 {
650 return _nodeTree;
651 }
652
654 inline bool hasTex() const
655 {
656 return (_mtex[0] != nullptr) || _nodeTree;
657 }
658
660 inline bool hasTips() const
661 {
662 return _tips;
663 }
664
665 /* these advanced iterators are used only in C++ */
666 inline int vertices_size() const
667 {
668 return _Vertices.size();
669 }
670
671 inline viewedge_container::const_iterator viewedges_begin() const
672 {
673 return _ViewEdges.begin();
674 }
675
676 inline viewedge_container::iterator viewedges_begin()
677 {
678 return _ViewEdges.begin();
679 }
680
681 inline viewedge_container::const_iterator viewedges_end() const
682 {
683 return _ViewEdges.end();
684 }
685
686 inline viewedge_container::iterator viewedges_end()
687 {
688 return _ViewEdges.end();
689 }
690
691 inline int viewedges_size() const
692 {
693 return _ViewEdges.size();
694 }
695
697 {
698 return _extremityOrientations[0];
699 }
700
702 {
703 return _extremityOrientations[0].x();
704 }
705
707 {
708 return _extremityOrientations[0].y();
709 }
710
712 {
713 return _extremityOrientations[1];
714 }
715
717 {
718 return _extremityOrientations[1].x();
719 }
720
722 {
723 return _extremityOrientations[1].y();
724 }
725
726 /* modifiers */
728 inline void setId(const Id &id)
729 {
730 _id = id;
731 }
732
734 void setLength(float iLength);
735
737 inline void setMediumType(MediumType iType)
738 {
739 _mediumType = iType;
740 }
741
743 inline void setTextureId(uint id)
744 {
745 _textureId = id;
746 }
747
749 inline void setTextureStep(float step)
750 {
751 _textureStep = step;
752 }
753
755 inline int setMTex(MTex *mtex)
756 {
757 for (int a = 0; a < MAX_MTEX; a++) {
758 if (!_mtex[a]) {
759 _mtex[a] = mtex;
760 return 0;
761 }
762 }
763 return -1; /* no free slots */
764 }
765
767 inline void setNodeTree(bNodeTree *iNodeTree)
768 {
769 _nodeTree = iNodeTree;
770 }
771
773 inline void setTips(bool iTips)
774 {
775 _tips = iTips;
776 }
777
778 inline void push_back(StrokeVertex *iVertex)
779 {
780 _Vertices.push_back(iVertex);
781 }
782
783 inline void push_front(StrokeVertex *iVertex)
784 {
785 _Vertices.push_front(iVertex);
786 }
787
788 inline void AddViewEdge(ViewEdge *iViewEdge)
789 {
790 _ViewEdges.push_back(iViewEdge);
791 }
792
793 inline void setBeginningOrientation(const Vec2r &iOrientation)
794 {
795 _extremityOrientations[0] = iOrientation;
796 }
797
799 {
800 _extremityOrientations[0] = Vec2r(x, y);
801 }
802
803 inline void setEndingOrientation(const Vec2r &iOrientation)
804 {
805 _extremityOrientations[1] = iOrientation;
806 }
807
809 {
810 _extremityOrientations[1] = Vec2r(x, y);
811 }
812
813 /* Information access interface */
814
815 // embedding vertex iterator
817 vertex_iterator vertices_begin(float sampling = 0.0f);
820
828
831
834 {
835 return _Vertices.size();
836 }
837
840 {
841 return *(_Vertices.at(i));
842 }
843
844 // Iterator access (Interface1D)
847
850
851 virtual Interface0DIterator pointsBegin(float t = 0.0f);
852 virtual Interface0DIterator pointsEnd(float t = 0.0f);
853
854 MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:Stroke")
855};
856
857//
858// Implementation
859//
861
862template<class InputVertexIterator>
863Stroke::Stroke(InputVertexIterator iBegin, InputVertexIterator iEnd)
864{
865 for (InputVertexIterator v = iBegin, vend = iEnd; v != vend; v++) {
866 _Vertices.push_back(*v);
867 }
868 _Length = 0;
869 _id = 0;
870}
871
872} /* 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.
Classes to define a silhouette structure.
String utilities.
#define MAX_MTEX
Definition Stroke.h:31
ATTR_WARN_UNUSED_RESULT const BMVert * v
virtual Vec2r getPoint2D() const
Definition Curve.h:100
void setThickness(const Vec2f &tRL)
Definition Stroke.h:243
float getColorR() const
Definition Stroke.h:101
void setVisible(bool iVisible)
Definition Stroke.h:250
bool isAttributeAvailableVec3f(const char *iName) const
Definition Stroke.cpp:289
Vec2f getThicknessRL() const
Definition Stroke.h:153
void setThickness(float tr, float tl)
Definition Stroke.h:233
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:134
float getColorG() const
Definition Stroke.h:107
const float * getColor() const
Definition Stroke.h:95
void setAttributeVec3f(const char *iName, const Vec3f &att)
Definition Stroke.cpp:317
float getThicknessR() const
Definition Stroke.h:140
bool isVisible() const
Definition Stroke.h:159
Vec3f getColorRGB() const
Definition Stroke.h:119
float getAlpha() const
Definition Stroke.h:125
float getColorB() const
Definition Stroke.h:113
void setColor(float r, float g, float b)
Definition Stroke.h:200
float getThicknessL() const
Definition Stroke.h:146
bool isAttributeAvailableVec2f(const char *iName) const
Definition Stroke.cpp:277
void setAlpha(float alpha)
Definition Stroke.h:222
void setColor(const Vec3f &iRGB)
Definition Stroke.h:211
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:429
float curvilinearAbscissa() const
Definition Stroke.h:384
Vec2r getPoint() const
Definition Stroke.h:360
void setCurvilinearAbscissa(float iAbscissa)
Definition Stroke.h:441
real operator[](const int i) const
Definition Stroke.h:366
void setY(real y)
Definition Stroke.h:409
void setAttribute(const StrokeAttribute &iAttribute)
Definition Stroke.h:435
float u() const
Definition Stroke.h:396
float strokeLength() const
Definition Stroke.h:390
void setX(real x)
Definition Stroke.h:403
void setPoint(real x, real y)
Definition Stroke.h:415
const StrokeAttribute & attribute() const
Definition Stroke.h:372
void setPoint(const Vec2r &p)
Definition Stroke.h:422
StrokeVertex & operator=(const StrokeVertex &iBrother)
Definition Stroke.cpp:374
void setStrokeLength(float iLength)
Definition Stroke.h:449
virtual string getExactTypeName() const
Definition Stroke.h:313
StrokeAttribute & attribute()
Definition Stroke.h:378
virtual Interface0DIterator pointsEnd(float t=0.0f)
Definition Stroke.cpp:790
viewedge_container::iterator viewedges_end()
Definition Stroke.h:686
void setTextureId(uint id)
Definition Stroke.h:743
const_vertex_iterator vertices_begin() const
embedding vertex iterator
Definition Stroke.cpp:741
bool hasTex() const
Definition Stroke.h:654
viewedge_container::const_iterator viewedges_end() const
Definition Stroke.h:681
void push_back(StrokeVertex *iVertex)
Definition Stroke.h:778
void setId(const Id &id)
Definition Stroke.h:728
StrokeVertex & strokeVerticeAt(uint i)
Definition Stroke.h:839
void setBeginningOrientation(const Vec2r &iOrientation)
Definition Stroke.h:793
MTex * getMTex(int idx)
Definition Stroke.h:642
virtual Id getId() const
Definition Stroke.h:494
int viewedges_size() const
Definition Stroke.h:691
uint getTextureId()
Definition Stroke.h:630
void setTextureStep(float step)
Definition Stroke.h:749
void ScaleThickness(float iFactor)
Definition Stroke.cpp:795
void setBeginningOrientation(real x, real y)
Definition Stroke.h:798
virtual Interface0DIterator verticesBegin()
Definition Stroke.cpp:771
StrokeInternal::vertex_iterator_base< StrokeInternal::vertex_nonconst_traits > vertex_iterator
Definition Stroke.h:510
std::vector< ViewEdge * > viewedge_container
Definition Stroke.h:508
StrokeInternal::vertex_iterator_base< StrokeInternal::vertex_const_traits > const_vertex_iterator
Definition Stroke.h:512
void RemoveAllVertices()
Definition Stroke.cpp:693
void setEndingOrientation(real x, real y)
Definition Stroke.h:808
bNodeTree * getNodeTree()
Definition Stroke.h:648
void AddViewEdge(ViewEdge *iViewEdge)
Definition Stroke.h:788
virtual ~Stroke()
Definition Stroke.cpp:439
void RemoveVertex(StrokeVertex *iVertex)
Definition Stroke.cpp:703
void push_front(StrokeVertex *iVertex)
Definition Stroke.h:783
void InsertVertex(StrokeVertex *iVertex, StrokeInternal::StrokeVertexIterator next)
Definition Stroke.cpp:716
real getEndingOrientationX() const
Definition Stroke.h:716
int vertices_size() const
Definition Stroke.h:666
const_vertex_iterator vertices_end() const
Definition Stroke.cpp:746
std::deque< StrokeVertex * > vertex_container
Definition Stroke.h:507
bool hasTips() const
Definition Stroke.h:660
virtual Interface0DIterator verticesEnd()
Definition Stroke.cpp:778
real getBeginningOrientationY() const
Definition Stroke.h:706
float getTextureStep()
Definition Stroke.h:636
void UpdateLength()
Definition Stroke.cpp:723
int setMTex(MTex *mtex)
Definition Stroke.h:755
void Render(const StrokeRenderer *iRenderer)
Definition Stroke.cpp:805
void setEndingOrientation(const Vec2r &iOrientation)
Definition Stroke.h:803
uint strokeVerticesSize() const
Definition Stroke.h:833
void setTips(bool iTips)
Definition Stroke.h:773
MediumType getMediumType() const
Definition Stroke.h:624
virtual Interface0DIterator pointsBegin(float t=0.0f)
Definition Stroke.cpp:785
Vec2r getBeginningOrientation() const
Definition Stroke.h:696
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:671
StrokeInternal::StrokeVertexIterator strokeVerticesEnd()
Definition Stroke.cpp:765
Vec2r getEndingOrientation() const
Definition Stroke.h:711
viewedge_container::iterator viewedges_begin()
Definition Stroke.h:676
StrokeInternal::StrokeVertexIterator strokeVerticesBegin(float t=0.0f)
Definition Stroke.cpp:756
virtual string getExactTypeName() const
Definition Stroke.h:486
real getEndingOrientationY() const
Definition Stroke.h:721
void setNodeTree(bNodeTree *iNodeTree)
Definition Stroke.h:767
real getLength2D() const
Definition Stroke.h:617
int Resample(int iNPoints)
Definition Stroke.cpp:525
real getBeginningOrientationX() const
Definition Stroke.h:701
void setMediumType(MediumType iType)
Definition Stroke.h:737
VecBase< float, D > step(VecOp< float, D >, VecOp< float, D >) RET
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
static uint x[3]
Definition RandGen.cpp:77
double real
Definition Precision.h:14
i
Definition text_draw.cc:230