Blender V5.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
11
12#include <map>
13#include <vector>
14
15#include "Curve.h"
16
19
22
23#include "MEM_guardedalloc.h"
24
25namespace blender {
26struct MTex;
27struct bNodeTree;
28} // namespace blender
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
508
509 public:
510 typedef std::deque<StrokeVertex *> vertex_container; // the vertices container
511 typedef std::vector<ViewEdge *> viewedge_container; // the viewedges container
516
517 public:
518 // typedef StrokeVertex vertex_type;
519
520 private:
521 vertex_container _Vertices;
522 Id _id;
523 float _Length; // The stroke length
524 viewedge_container _ViewEdges;
525 float _sampling;
526 float _textureStep;
527 // StrokeRenderer *_renderer; // mark implementation OpenGL renderer
528 MediumType _mediumType;
529 uint _textureId;
530 blender::MTex *_mtex[MAX_MTEX];
531 blender::bNodeTree *_nodeTree;
532 bool _tips;
533 StrokeRep *_rep;
534 Vec2r _extremityOrientations[2]; // the orientations of the first and last extremity
535
536 public:
538 Stroke();
539
541 Stroke(const Stroke &iBrother);
542
551 template<class InputVertexIterator> Stroke(InputVertexIterator iBegin, InputVertexIterator iEnd);
552
554 virtual ~Stroke();
555
556 /* operators */
558 Stroke &operator=(const Stroke &iBrother);
559
569 float ComputeSampling(int iNVertices);
570
578 int Resample(int iNPoints);
579
586 int Resample(float iSampling);
587
590 void RemoveAllVertices();
591
597 void RemoveVertex(StrokeVertex *iVertex);
598
607
609 void UpdateLength();
610
611 /* Render method */
612 void ScaleThickness(float iFactor);
613 void Render(const StrokeRenderer *iRenderer);
614 void RenderBasic(const StrokeRenderer *iRenderer);
615
616 /* Iterator definition */
617
618 /* accessors */
620 inline real getLength2D() const
621 {
622 return _Length;
623 }
624
628 {
629 return _mediumType;
630 }
631
633 inline uint getTextureId()
634 {
635 return _textureId;
636 }
637
639 inline float getTextureStep()
640 {
641 return _textureStep;
642 }
643
645 inline blender::MTex *getMTex(int idx)
646 {
647 return _mtex[idx];
648 }
649
652 {
653 return _nodeTree;
654 }
655
657 inline bool hasTex() const
658 {
659 return (_mtex[0] != nullptr) || _nodeTree;
660 }
661
663 inline bool hasTips() const
664 {
665 return _tips;
666 }
667
668 /* these advanced iterators are used only in C++ */
669 inline int vertices_size() const
670 {
671 return _Vertices.size();
672 }
673
674 inline viewedge_container::const_iterator viewedges_begin() const
675 {
676 return _ViewEdges.begin();
677 }
678
679 inline viewedge_container::iterator viewedges_begin()
680 {
681 return _ViewEdges.begin();
682 }
683
684 inline viewedge_container::const_iterator viewedges_end() const
685 {
686 return _ViewEdges.end();
687 }
688
689 inline viewedge_container::iterator viewedges_end()
690 {
691 return _ViewEdges.end();
692 }
693
694 inline int viewedges_size() const
695 {
696 return _ViewEdges.size();
697 }
698
700 {
701 return _extremityOrientations[0];
702 }
703
705 {
706 return _extremityOrientations[0].x();
707 }
708
710 {
711 return _extremityOrientations[0].y();
712 }
713
715 {
716 return _extremityOrientations[1];
717 }
718
720 {
721 return _extremityOrientations[1].x();
722 }
723
725 {
726 return _extremityOrientations[1].y();
727 }
728
729 /* modifiers */
731 inline void setId(const Id &id)
732 {
733 _id = id;
734 }
735
737 void setLength(float iLength);
738
740 inline void setMediumType(MediumType iType)
741 {
742 _mediumType = iType;
743 }
744
746 inline void setTextureId(uint id)
747 {
748 _textureId = id;
749 }
750
752 inline void setTextureStep(float step)
753 {
754 _textureStep = step;
755 }
756
758 inline int setMTex(blender::MTex *mtex)
759 {
760 for (int a = 0; a < MAX_MTEX; a++) {
761 if (!_mtex[a]) {
762 _mtex[a] = mtex;
763 return 0;
764 }
765 }
766 return -1; /* no free slots */
767 }
768
770 inline void setNodeTree(blender::bNodeTree *iNodeTree)
771 {
772 _nodeTree = iNodeTree;
773 }
774
776 inline void setTips(bool iTips)
777 {
778 _tips = iTips;
779 }
780
781 inline void push_back(StrokeVertex *iVertex)
782 {
783 _Vertices.push_back(iVertex);
784 }
785
786 inline void push_front(StrokeVertex *iVertex)
787 {
788 _Vertices.push_front(iVertex);
789 }
790
791 inline void AddViewEdge(ViewEdge *iViewEdge)
792 {
793 _ViewEdges.push_back(iViewEdge);
794 }
795
796 inline void setBeginningOrientation(const Vec2r &iOrientation)
797 {
798 _extremityOrientations[0] = iOrientation;
799 }
800
802 {
803 _extremityOrientations[0] = Vec2r(x, y);
804 }
805
806 inline void setEndingOrientation(const Vec2r &iOrientation)
807 {
808 _extremityOrientations[1] = iOrientation;
809 }
810
812 {
813 _extremityOrientations[1] = Vec2r(x, y);
814 }
815
816 /* Information access interface */
817
818 // embedding vertex iterator
820 vertex_iterator vertices_begin(float sampling = 0.0f);
823
831
834
836 inline uint strokeVerticesSize() const
837 {
838 return _Vertices.size();
839 }
840
843 {
844 return *(_Vertices.at(i));
845 }
846
847 // Iterator access (Interface1D)
850
853
854 virtual Interface0DIterator pointsBegin(float t = 0.0f);
855 virtual Interface0DIterator pointsEnd(float t = 0.0f);
856
857 MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:Stroke")
858};
859
860//
861// Implementation
862//
864
865template<class InputVertexIterator>
866Stroke::Stroke(InputVertexIterator iBegin, InputVertexIterator iEnd)
867{
868 for (InputVertexIterator v = iBegin, vend = iEnd; v != vend; v++) {
869 _Vertices.push_back(*v);
870 }
871 _Length = 0;
872 _id = 0;
873}
874
875} /* namespace Freestyle */
Class to define a container for curves.
Configuration definitions.
Interface 1D and related tools definitions.
Read Blender memory allocation and freeing.
Classes to define a silhouette structure.
String utilities.
#define MAX_MTEX
Definition Stroke.h:31
btGeneric6DofConstraint & operator=(btGeneric6DofConstraint &other)
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
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:689
void setTextureId(uint id)
Definition Stroke.h:746
const_vertex_iterator vertices_begin() const
embedding vertex iterator
Definition Stroke.cpp:741
bool hasTex() const
Definition Stroke.h:657
viewedge_container::const_iterator viewedges_end() const
Definition Stroke.h:684
void push_back(StrokeVertex *iVertex)
Definition Stroke.h:781
void setId(const Id &id)
Definition Stroke.h:731
StrokeVertex & strokeVerticeAt(uint i)
Definition Stroke.h:842
void setBeginningOrientation(const Vec2r &iOrientation)
Definition Stroke.h:796
virtual Id getId() const
Definition Stroke.h:494
int viewedges_size() const
Definition Stroke.h:694
uint getTextureId()
Definition Stroke.h:633
void setTextureStep(float step)
Definition Stroke.h:752
void ScaleThickness(float iFactor)
Definition Stroke.cpp:795
void setBeginningOrientation(real x, real y)
Definition Stroke.h:801
virtual Interface0DIterator verticesBegin()
Definition Stroke.cpp:771
StrokeInternal::vertex_iterator_base< StrokeInternal::vertex_nonconst_traits > vertex_iterator
Definition Stroke.h:513
std::vector< ViewEdge * > viewedge_container
Definition Stroke.h:511
StrokeInternal::vertex_iterator_base< StrokeInternal::vertex_const_traits > const_vertex_iterator
Definition Stroke.h:515
void RemoveAllVertices()
Definition Stroke.cpp:693
void setEndingOrientation(real x, real y)
Definition Stroke.h:811
void AddViewEdge(ViewEdge *iViewEdge)
Definition Stroke.h:791
void RemoveVertex(StrokeVertex *iVertex)
Definition Stroke.cpp:703
void push_front(StrokeVertex *iVertex)
Definition Stroke.h:786
void InsertVertex(StrokeVertex *iVertex, StrokeInternal::StrokeVertexIterator next)
Definition Stroke.cpp:716
real getEndingOrientationX() const
Definition Stroke.h:719
int vertices_size() const
Definition Stroke.h:669
const_vertex_iterator vertices_end() const
Definition Stroke.cpp:746
std::deque< StrokeVertex * > vertex_container
Definition Stroke.h:510
bool hasTips() const
Definition Stroke.h:663
virtual Interface0DIterator verticesEnd()
Definition Stroke.cpp:778
void setNodeTree(blender::bNodeTree *iNodeTree)
Definition Stroke.h:770
real getBeginningOrientationY() const
Definition Stroke.h:709
float getTextureStep()
Definition Stroke.h:639
void UpdateLength()
Definition Stroke.cpp:723
void Render(const StrokeRenderer *iRenderer)
Definition Stroke.cpp:805
void setEndingOrientation(const Vec2r &iOrientation)
Definition Stroke.h:806
uint strokeVerticesSize() const
Definition Stroke.h:836
void setTips(bool iTips)
Definition Stroke.h:776
MediumType getMediumType() const
Definition Stroke.h:627
virtual Interface0DIterator pointsBegin(float t=0.0f)
Definition Stroke.cpp:785
Vec2r getBeginningOrientation() const
Definition Stroke.h:699
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:674
blender::bNodeTree * getNodeTree()
Definition Stroke.h:651
StrokeInternal::StrokeVertexIterator strokeVerticesEnd()
Definition Stroke.cpp:765
Vec2r getEndingOrientation() const
Definition Stroke.h:714
int setMTex(blender::MTex *mtex)
Definition Stroke.h:758
viewedge_container::iterator viewedges_begin()
Definition Stroke.h:679
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:724
real getLength2D() const
Definition Stroke.h:620
int Resample(int iNPoints)
Definition Stroke.cpp:525
real getBeginningOrientationX() const
Definition Stroke.h:704
blender::MTex * getMTex(int idx)
Definition Stroke.h:645
void setMediumType(MediumType iType)
Definition Stroke.h:740
VecBase< float, D > step(VecOp< float, D >, VecOp< float, D >) RET
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
double real
Definition Precision.h:14
BMesh Iterators.