Blender V4.3
WEdge.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 <iterator>
13#include <vector>
14
15#include "../geometry/Geom.h"
16
18
20
21#include "BLI_math_base.h"
22
23#ifdef WITH_CXX_GUARDEDALLOC
24# include "MEM_guardedalloc.h"
25#endif
26
27using namespace std;
28
29namespace Freestyle {
30
31using namespace Geometry;
32
33/**********************************
34 * *
35 * *
36 * WVertex *
37 * *
38 * *
39 **********************************/
40
41class WOEdge;
42class WEdge;
43class WShape;
44class WFace;
45
46class WVertex {
47 protected:
48 int _Id; // an identificator
50 vector<WEdge *> _EdgeList;
51 WShape *_Shape; // the shape to which the vertex belongs
52 bool _Smooth; // flag to indicate whether the Vertex belongs to a smooth edge or not
53 short _Border; // 1 -> border, 0 -> no border, -1 -> not set
54
55 public:
56 void *userdata; // designed to store specific user data
57 inline WVertex(const Vec3f &v)
58 {
59 _Id = 0;
60 _Vertex = v;
61 userdata = nullptr;
62 _Shape = nullptr;
63 _Smooth = true;
64 _Border = -1;
65 }
66
68 WVertex(WVertex &iBrother);
69 virtual WVertex *duplicate();
70 virtual ~WVertex() {}
71
73 inline Vec3f &GetVertex()
74 {
75 return _Vertex;
76 }
77
78 inline vector<WEdge *> &GetEdges()
79 {
80 return _EdgeList;
81 }
82
83 inline int GetId()
84 {
85 return _Id;
86 }
87
88 inline WShape *shape() const
89 {
90 return _Shape;
91 }
92
93 inline bool isSmooth() const
94 {
95 return _Smooth;
96 }
97
98 bool isBoundary();
99
101 inline void setVertex(const Vec3f &v)
102 {
103 _Vertex = v;
104 }
105
106 inline void setEdges(const vector<WEdge *> &iEdgeList)
107 {
108 _EdgeList = iEdgeList;
109 }
110
111 inline void setId(int id)
112 {
113 _Id = id;
114 }
115
116 inline void setShape(WShape *iShape)
117 {
118 _Shape = iShape;
119 }
120
121 inline void setSmooth(bool b)
122 {
123 _Smooth = b;
124 }
125
126 inline void setBorder(bool b)
127 {
128 if (b) {
129 _Border = 1;
130 }
131 else {
132 _Border = 0;
133 }
134 }
135
137 void AddEdge(WEdge *iEdge);
138
139 virtual void ResetUserData()
140 {
141 userdata = nullptr;
142 }
143
144 public:
147 public:
148 using iterator_category = input_iterator_tag;
150 using difference_type = ptrdiff_t;
153
154 private:
155 WVertex *_vertex;
156 //
157 WOEdge *_begin;
158 WOEdge *_current;
159
160 public:
161 inline incoming_edge_iterator() = default;
162 virtual ~incoming_edge_iterator() = default;
163
164 protected:
165 friend class WVertex;
166 inline incoming_edge_iterator(WVertex *iVertex, WOEdge *iBegin, WOEdge *iCurrent)
167 {
168 _vertex = iVertex;
169 _begin = iBegin;
170 _current = iCurrent;
171 }
172
173 public:
175 {
176 _vertex = iBrother._vertex;
177 _begin = iBrother._begin;
178 _current = iBrother._current;
179 }
180
181 public:
182 // operators
183 // operator corresponding to ++i
185 {
186 increment();
187 return *this;
188 }
189
190 // operator corresponding to i++
192 {
193 incoming_edge_iterator tmp = *this;
194 increment();
195 return tmp;
196 }
197
198 // comparibility
199 virtual bool operator!=(const incoming_edge_iterator &b) const
200 {
201 return ((_current) != (b._current));
202 }
203
204 virtual bool operator==(const incoming_edge_iterator &b) const
205 {
206 return ((_current) == (b._current));
207 }
208
209 // dereferencing
210 virtual WOEdge *operator*();
211 // virtual WOEdge **operator->();
212 protected:
213 virtual void increment();
214
215#ifdef WITH_CXX_GUARDEDALLOC
216 MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:WVertex:incoming_edge_iterator")
217#endif
218 };
219
221 public:
222 using iterator_category = input_iterator_tag;
223 using value_type = WFace *;
224 using difference_type = ptrdiff_t;
227
228 private:
229 incoming_edge_iterator _edge_it;
230
231 public:
232 inline face_iterator() = default;
233 virtual ~face_iterator() = default;
234
235 protected:
236 friend class WVertex;
238 {
239 _edge_it = it;
240 }
241
242 public:
243 inline face_iterator(const face_iterator &iBrother)
244 {
245 _edge_it = iBrother._edge_it;
246 }
247
248 public:
249 // operators
250 // operator corresponding to ++i
252 {
253 increment();
254 return *this;
255 }
256
257 // operator corresponding to i++
259 {
260 face_iterator tmp = *this;
261 increment();
262 return tmp;
263 }
264
265 // comparibility
266 virtual bool operator!=(const face_iterator &b) const
267 {
268 return ((_edge_it) != (b._edge_it));
269 }
270
271 virtual bool operator==(const face_iterator &b) const
272 {
273 return ((_edge_it) == (b._edge_it));
274 }
275
276 // dereferencing
277 virtual WFace *operator*();
278 // virtual WOEdge **operator->();
279
280 protected:
281 inline void increment()
282 {
283 ++_edge_it;
284 }
285
286#ifdef WITH_CXX_GUARDEDALLOC
287 MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:WVertex:face_iterator")
288#endif
289 };
290
291 public:
293 virtual incoming_edge_iterator incoming_edges_begin();
294 virtual incoming_edge_iterator incoming_edges_end();
295
297 {
299 }
300
302 {
304 }
305
306#ifdef WITH_CXX_GUARDEDALLOC
307 MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:WVertex")
308#endif
309};
310
311/**********************************
312 * *
313 * *
314 * WOEdge *
315 * *
316 * *
317 **********************************/
318
319class WFace;
320class WEdge;
321
322class WOEdge {
323 protected:
324#if 0
325 WOEdge *_paCWEdge; // edge reached when traveling clockwise on aFace from the edge
326 WOEdge *_pbCWEdge; // edge reached when traveling clockwise on bFace from the edge
327 WOEdge *_paCCWEdge; // edge reached when traveling counterclockwise on aFace from the edge
328 WOEdge *_pbCCWEdge; // edge reached when traveling counterclockwise on bFace from the edge
329#endif
330 WVertex *_paVertex; // starting vertex
331 WVertex *_pbVertex; // ending vertex
332 WFace *_paFace; // when following the edge, face on the right
333 WFace *_pbFace; // when following the edge, face on the left
334 WEdge *_pOwner; // Edge
335
337 float _angle;
338
339 public:
340 void *userdata;
341
342 inline WOEdge()
343 {
344#if 0
345 _paCWEdge = nullptr;
346 _pbCWEdge = nullptr;
347 _paCCWEdge = nullptr;
348 _pbCCWEdge = nullptr;
349#endif
350 _paVertex = nullptr;
351 _pbVertex = nullptr;
352 _paFace = nullptr;
353 _pbFace = nullptr;
354 _pOwner = nullptr;
355 userdata = nullptr;
356 }
357
358 virtual ~WOEdge(){}; // soc
359
361 WOEdge(WOEdge &iBrother);
362 virtual WOEdge *duplicate();
363
365#if 0
366 inline WOEdge *GetaCWEdge()
367 {
368 return _paCWEdge;
369 }
370
371 inline WOEdge *GetbCWEdge()
372 {
373 return _pbCWEdge;
374 }
375
376 inline WOEdge *GetaCCWEdge()
377 {
378 return _paCCWEdge;
379 }
380
381 inline WOEdge *GetbCCWEdge()
382 {
383 return _pbCCWEdge;
384 }
385#endif
386
388 {
389 return _paVertex;
390 }
391
393 {
394 return _pbVertex;
395 }
396
397 inline WFace *GetaFace()
398 {
399 return _paFace;
400 }
401
402 inline WFace *GetbFace()
403 {
404 return _pbFace;
405 }
406
407 inline WEdge *GetOwner()
408 {
409 return _pOwner;
410 }
411
412 inline const Vec3f &GetVec()
413 {
414 return _vec;
415 }
416
417 inline const float GetAngle()
418 {
419 return _angle;
420 }
421
423#if 0
424 inline void SetaCWEdge(WOEdge *pe)
425 {
426 _paCWEdge = pe;
427 }
428
429 inline void SetbCWEdge(WOEdge *pe)
430 {
431 _pbCWEdge = pe;
432 }
433
434 inline void SetaCCWEdge(WOEdge *pe)
435 {
436 _paCCWEdge = pe;
437 }
438
439 inline void SetbCCCWEdge(WOEdge *pe)
440 {
441 _pbCCWEdge = pe;
442 }
443#endif
444
445 inline void setVecAndAngle();
446
447 inline void setaVertex(WVertex *pv)
448 {
449 _paVertex = pv;
451 }
452
453 inline void setbVertex(WVertex *pv)
454 {
455 _pbVertex = pv;
457 }
458
459 inline void setaFace(WFace *pf)
460 {
461 _paFace = pf;
463 }
464
465 inline void setbFace(WFace *pf)
466 {
467 _pbFace = pf;
469 }
470
471 inline void setOwner(WEdge *pe)
472 {
473 _pOwner = pe;
474 }
475
477 inline void RetrieveCWOrderedEdges(vector<WEdge *> &oEdges);
478
479 WOEdge *twin();
481
482 virtual void ResetUserData()
483 {
484 userdata = nullptr;
485 }
486
487#ifdef WITH_CXX_GUARDEDALLOC
488 MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:WOEdge")
489#endif
490};
491
492/**********************************
493 * *
494 * *
495 * WEdge *
496 * *
497 * *
498 **********************************/
499
500class WEdge {
501 protected:
502 WOEdge *_paOEdge; // first oriented edge
503 WOEdge *_pbOEdge; // second oriented edge
504 short _nOEdges; // number of oriented edges associated with this edge. (1 means border edge)
505 bool _Mark; // user-specified edge mark for feature edge detection
506 int _Id; // Identifier for the edge
507
508 public:
509 void *userdata; // designed to store specific user data
510
511 inline WEdge()
512 {
513 _paOEdge = nullptr;
514 _pbOEdge = nullptr;
515 _nOEdges = 0;
516 userdata = nullptr;
517 }
518
519 inline WEdge(WOEdge *iOEdge)
520 {
521 _paOEdge = iOEdge;
522 _pbOEdge = nullptr;
523 _nOEdges = 1;
524 userdata = nullptr;
525 }
526
527 inline WEdge(WOEdge *iaOEdge, WOEdge *ibOEdge)
528 {
529 _paOEdge = iaOEdge;
530 _pbOEdge = ibOEdge;
531 _nOEdges = 2;
532 userdata = nullptr;
533 }
534
536 WEdge(WEdge &iBrother);
537 virtual WEdge *duplicate();
538
539 virtual ~WEdge()
540 {
541 if (_paOEdge) {
542 delete _paOEdge;
543 _paOEdge = nullptr;
544 }
545
546 if (_pbOEdge) {
547 delete _pbOEdge;
548 _pbOEdge = nullptr;
549 }
550 }
551
555 static inline WVertex *CommonVertex(WEdge *iEdge1, WEdge *iEdge2)
556 {
557 if (!iEdge1 || !iEdge2) {
558 return nullptr;
559 }
560
561 WVertex *wv1 = iEdge1->GetaOEdge()->GetaVertex();
562 WVertex *wv2 = iEdge1->GetaOEdge()->GetbVertex();
563 WVertex *wv3 = iEdge2->GetaOEdge()->GetaVertex();
564 WVertex *wv4 = iEdge2->GetaOEdge()->GetbVertex();
565
566 if ((wv1 == wv3) || (wv1 == wv4)) {
567 return wv1;
568 }
569 else if ((wv2 == wv3) || (wv2 == wv4)) {
570 return wv2;
571 }
572 return nullptr;
573 }
574
577 {
578 return _paOEdge;
579 }
580
582 {
583 return _pbOEdge;
584 }
585
586 inline short GetNumberOfOEdges()
587 {
588 return _nOEdges;
589 }
590
591 inline bool GetMark()
592 {
593 return _Mark;
594 }
595
596 inline int GetId()
597 {
598 return _Id;
599 }
600
602 {
603 return _paOEdge->GetaVertex();
604 }
605
607 {
608 return _paOEdge->GetbVertex();
609 }
610
611 inline WFace *GetaFace()
612 {
613 return _paOEdge->GetaFace();
614 }
615
616 inline WFace *GetbFace()
617 {
618 return _paOEdge->GetbFace();
619 }
620
621 inline WOEdge *GetOtherOEdge(WOEdge *iOEdge)
622 {
623 if (iOEdge == _paOEdge) {
624 return _pbOEdge;
625 }
626 else {
627 return _paOEdge;
628 }
629 }
630
632 inline void setaOEdge(WOEdge *iEdge)
633 {
634 _paOEdge = iEdge;
635 }
636
637 inline void setbOEdge(WOEdge *iEdge)
638 {
639 _pbOEdge = iEdge;
640 }
641
642 inline void AddOEdge(WOEdge *iEdge)
643 {
644 if (!_paOEdge) {
645 _paOEdge = iEdge;
646 _nOEdges++;
647 return;
648 }
649 if (!_pbOEdge) {
650 _pbOEdge = iEdge;
651 _nOEdges++;
652 return;
653 }
654 }
655
656 inline void setNumberOfOEdges(short n)
657 {
658 _nOEdges = n;
659 }
660
661 inline void setMark(bool mark)
662 {
663 _Mark = mark;
664 }
665
666 inline void setId(int id)
667 {
668 _Id = id;
669 }
670
671 virtual void ResetUserData()
672 {
673 userdata = nullptr;
674 }
675
676#ifdef WITH_CXX_GUARDEDALLOC
677 MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:WEdge")
678#endif
679};
680
681/**********************************
682 * *
683 * *
684 * WFace *
685 * *
686 * *
687 **********************************/
688
689class WFace {
690 protected:
691 vector<WOEdge *> _OEdgeList; // list of oriented edges of bording the face
692 Vec3f _Normal; // normal to the face
693 // in case there is a normal per vertex.
694 // The normal number i corresponds to the aVertex of the oedge number i, for that face
695 vector<Vec3f> _VerticesNormals;
696 vector<Vec2f> _VerticesTexCoords;
697
698 int _Id;
700 bool _Mark; // Freestyle face mark (if true, feature edges on this face are ignored)
701
702 public:
703 void *userdata;
704 inline WFace()
705 {
706 userdata = nullptr;
708 }
709
711 WFace(WFace &iBrother);
712 virtual WFace *duplicate();
713 virtual ~WFace() {}
714
716 inline const vector<WOEdge *> &getEdgeList()
717 {
718 return _OEdgeList;
719 }
720
721 inline WOEdge *GetOEdge(int i)
722 {
723 return _OEdgeList[i];
724 }
725
726 inline Vec3f &GetNormal()
727 {
728 return _Normal;
729 }
730
731 inline int GetId()
732 {
733 return _Id;
734 }
735
736 inline uint frs_materialIndex() const
737 {
738 return _FrsMaterialIndex;
739 }
740
741 inline bool GetMark() const
742 {
743 return _Mark;
744 }
745
746 const FrsMaterial &frs_material();
747
749 inline WVertex *GetVertex(uint index)
750 {
751#if 0
752 if (index >= _OEdgeList.size()) {
753 return nullptr;
754 }
755#endif
756 return _OEdgeList[index]->GetaVertex();
757 }
758
762 inline int GetIndex(WVertex *iVertex)
763 {
764 int index = 0;
765 for (vector<WOEdge *>::iterator woe = _OEdgeList.begin(), woend = _OEdgeList.end();
766 woe != woend;
767 woe++)
768 {
769 if ((*woe)->GetaVertex() == iVertex) {
770 return index;
771 }
772 ++index;
773 }
774 return -1;
775 }
776
777 inline void RetrieveVertexList(vector<WVertex *> &oVertices)
778 {
779 for (vector<WOEdge *>::iterator woe = _OEdgeList.begin(), woend = _OEdgeList.end();
780 woe != woend;
781 woe++)
782 {
783 oVertices.push_back((*woe)->GetaVertex());
784 }
785 }
786
787 inline void RetrieveBorderFaces(vector<const WFace *> &oWFaces)
788 {
789 for (vector<WOEdge *>::iterator woe = _OEdgeList.begin(), woend = _OEdgeList.end();
790 woe != woend;
791 woe++)
792 {
793 WFace *af;
794 if ((af = (*woe)->GetaFace())) {
795 oWFaces.push_back(af);
796 }
797 }
798 }
799
800 inline WFace *GetBordingFace(int index)
801 {
802#if 0
803 if (index >= _OEdgeList.size()) {
804 return nullptr;
805 }
806#endif
807 return _OEdgeList[index]->GetaFace();
808 }
809
810 inline WFace *GetBordingFace(WOEdge *iOEdge)
811 {
812 return iOEdge->GetaFace();
813 }
814
815 inline vector<Vec3f> &GetPerVertexNormals()
816 {
817 return _VerticesNormals;
818 }
819
820 inline vector<Vec2f> &GetPerVertexTexCoords()
821 {
822 return _VerticesTexCoords;
823 }
824
826 inline Vec3f &GetVertexNormal(int index)
827 {
828 return _VerticesNormals[index];
829 }
830
832 inline Vec2f &GetVertexTexCoords(int index)
833 {
834 return _VerticesTexCoords[index];
835 }
836
838 inline Vec3f &GetVertexNormal(WVertex *iVertex)
839 {
840 int i = 0;
841 int index = 0;
842 for (vector<WOEdge *>::const_iterator woe = _OEdgeList.begin(), woend = _OEdgeList.end();
843 woe != woend;
844 woe++)
845 {
846 if ((*woe)->GetaVertex() == iVertex) {
847 index = i;
848 break;
849 }
850 ++i;
851 }
852
853 return _VerticesNormals[index];
854 }
855
856 inline WOEdge *GetNextOEdge(WOEdge *iOEdge)
857 {
858 bool found = false;
859 vector<WOEdge *>::iterator woe, woend, woefirst;
860 woefirst = _OEdgeList.begin();
861 for (woe = woefirst, woend = _OEdgeList.end(); woe != woend; ++woe) {
862 if (found) {
863 return (*woe);
864 }
865
866 if ((*woe) == iOEdge) {
867 found = true;
868 }
869 }
870
871 // We left the loop. That means that the first OEdge was the good one:
872 if (found) {
873 return (*woefirst);
874 }
875
876 return nullptr;
877 }
878
879 WOEdge *GetPrevOEdge(WOEdge *iOEdge);
880
881 inline int numberOfEdges() const
882 {
883 return _OEdgeList.size();
884 }
885
886 inline int numberOfVertices() const
887 {
888 return _OEdgeList.size();
889 }
890
892 inline bool isBorder() const
893 {
894 for (vector<WOEdge *>::const_iterator woe = _OEdgeList.begin(), woeend = _OEdgeList.end();
895 woe != woeend;
896 ++woe)
897 {
898 if ((*woe)->GetOwner()->GetbOEdge() == 0) {
899 return true;
900 }
901 }
902 return false;
903 }
904
906 inline void setEdgeList(const vector<WOEdge *> &iEdgeList)
907 {
908 _OEdgeList = iEdgeList;
909 }
910
911 inline void setNormal(const Vec3f &iNormal)
912 {
913 _Normal = iNormal;
914 }
915
916 inline void setNormalList(const vector<Vec3f> &iNormalsList)
917 {
918 _VerticesNormals = iNormalsList;
919 }
920
921 inline void setTexCoordsList(const vector<Vec2f> &iTexCoordsList)
922 {
923 _VerticesTexCoords = iTexCoordsList;
924 }
925
926 inline void setId(int id)
927 {
928 _Id = id;
929 }
930
931 inline void setFrsMaterialIndex(uint iMaterialIndex)
932 {
933 _FrsMaterialIndex = iMaterialIndex;
934 }
935
936 inline void setMark(bool iMark)
937 {
938 _Mark = iMark;
939 }
940
942 virtual WEdge *instanciateEdge() const
943 {
944 return new WEdge;
945 }
946
953 virtual WOEdge *MakeEdge(WVertex *v1, WVertex *v2);
954
956 inline void AddEdge(WOEdge *iEdge)
957 {
958 _OEdgeList.push_back(iEdge);
959 }
960
964 bool getOppositeEdge(const WVertex *v, WOEdge *&e);
965
967 float getArea();
968
969 WShape *getShape();
970 virtual void ResetUserData()
971 {
972 userdata = nullptr;
973 }
974
975#ifdef WITH_CXX_GUARDEDALLOC
976 MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:WFace")
977#endif
978};
979
980/**********************************
981 * *
982 * *
983 * WShape *
984 * *
985 * *
986 **********************************/
987
988class WShape {
989 protected:
990 vector<WVertex *> _VertexList;
991 vector<WEdge *> _EdgeList;
992 vector<WFace *> _FaceList;
993 int _Id;
994 string _Name;
997#if 0
998 Vec3f _min;
999 Vec3f _max;
1000#endif
1001 vector<FrsMaterial> _FrsMaterials;
1002#if 0
1003 float _meanEdgeSize;
1004#endif
1005
1006 public:
1007 inline WShape()
1008 {
1009#if 0
1010 _meanEdgeSize = 0;
1011#endif
1014 }
1015
1017 WShape(WShape &iBrother);
1018 virtual WShape *duplicate();
1019
1020 virtual ~WShape()
1021 {
1022 if (_EdgeList.size() != 0) {
1023 vector<WEdge *>::iterator e;
1024 for (e = _EdgeList.begin(); e != _EdgeList.end(); ++e) {
1025 delete (*e);
1026 }
1027 _EdgeList.clear();
1028 }
1029
1030 if (_VertexList.size() != 0) {
1031 vector<WVertex *>::iterator v;
1032 for (v = _VertexList.begin(); v != _VertexList.end(); ++v) {
1033 delete (*v);
1034 }
1035 _VertexList.clear();
1036 }
1037
1038 if (_FaceList.size() != 0) {
1039 vector<WFace *>::iterator f;
1040 for (f = _FaceList.begin(); f != _FaceList.end(); ++f) {
1041 delete (*f);
1042 }
1043 _FaceList.clear();
1044 }
1045 }
1046
1048 inline vector<WEdge *> &getEdgeList()
1049 {
1050 return _EdgeList;
1051 }
1052
1053 inline vector<WVertex *> &getVertexList()
1054 {
1055 return _VertexList;
1056 }
1057
1058 inline vector<WFace *> &GetFaceList()
1059 {
1060 return _FaceList;
1061 }
1062
1063 inline uint GetId()
1064 {
1065 return _Id;
1066 }
1067
1068#if 0
1069 inline void bbox(Vec3f &min, Vec3f &max)
1070 {
1071 min = _min;
1072 max = _max;
1073 }
1074#endif
1075
1076 inline const FrsMaterial &frs_material(uint i) const
1077 {
1078 return _FrsMaterials[i];
1079 }
1080
1081 inline const vector<FrsMaterial> &frs_materials() const
1082 {
1083 return _FrsMaterials;
1084 }
1085
1086#if 0
1087 inline const float getMeanEdgeSize() const
1088 {
1089 return _meanEdgeSize;
1090 }
1091#endif
1092
1093 inline const string &getName() const
1094 {
1095 return _Name;
1096 }
1097
1098 inline const string &getLibraryPath() const
1099 {
1100 return _LibraryPath;
1101 }
1102
1104 static inline void setCurrentId(const uint id)
1105 {
1106 _SceneCurrentId = id;
1107 }
1108
1109 inline void setEdgeList(const vector<WEdge *> &iEdgeList)
1110 {
1111 _EdgeList = iEdgeList;
1112 }
1113
1114 inline void setVertexList(const vector<WVertex *> &iVertexList)
1115 {
1116 _VertexList = iVertexList;
1117 }
1118
1119 inline void setFaceList(const vector<WFace *> &iFaceList)
1120 {
1121 _FaceList = iFaceList;
1122 }
1123
1124 inline void setId(int id)
1125 {
1126 _Id = id;
1127 }
1128
1129#if 0
1130 inline void setBBox(const Vec3f &min, const Vec3f &max)
1131 {
1132 _min = min;
1133 _max = max;
1134 }
1135#endif
1136
1138 {
1140 }
1141
1142 inline void setFrsMaterials(const vector<FrsMaterial> &iMaterials)
1143 {
1144 _FrsMaterials = iMaterials;
1145 }
1146
1147 inline void setName(const string &name)
1148 {
1149 _Name = name;
1150 }
1151
1152 inline void setLibraryPath(const string &path)
1153 {
1154 _LibraryPath = path;
1155 }
1156
1158 virtual WFace *instanciateFace() const
1159 {
1160 return new WFace;
1161 }
1162
1172 virtual WFace *MakeFace(vector<WVertex *> &iVertexList,
1173 vector<bool> &iFaceEdgeMarksList,
1174 uint iMaterialIndex);
1175
1187 virtual WFace *MakeFace(vector<WVertex *> &iVertexList,
1188 vector<Vec3f> &iNormalsList,
1189 vector<Vec2f> &iTexCoordsList,
1190 vector<bool> &iFaceEdgeMarksList,
1191 uint iMaterialIndex);
1192
1193 inline void AddEdge(WEdge *iEdge)
1194 {
1195 _EdgeList.push_back(iEdge);
1196 }
1197
1198 inline void AddFace(WFace *iFace)
1199 {
1200 _FaceList.push_back(iFace);
1201 }
1202
1203 inline void AddVertex(WVertex *iVertex)
1204 {
1205 iVertex->setShape(this);
1206 _VertexList.push_back(iVertex);
1207 }
1208
1209 inline void ResetUserData()
1210 {
1211 for (vector<WVertex *>::iterator v = _VertexList.begin(), vend = _VertexList.end(); v != vend;
1212 v++)
1213 {
1214 (*v)->ResetUserData();
1215 }
1216
1217 for (vector<WEdge *>::iterator e = _EdgeList.begin(), eend = _EdgeList.end(); e != eend; e++) {
1218 (*e)->ResetUserData();
1219 // manages WOEdge:
1220 WOEdge *oe = (*e)->GetaOEdge();
1221 if (oe) {
1222 oe->ResetUserData();
1223 }
1224 oe = (*e)->GetbOEdge();
1225 if (oe) {
1226 oe->ResetUserData();
1227 }
1228 }
1229
1230 for (vector<WFace *>::iterator f = _FaceList.begin(), fend = _FaceList.end(); f != fend; f++) {
1231 (*f)->ResetUserData();
1232 }
1233 }
1234
1235#if 0
1236 inline void ComputeBBox()
1237 {
1238 _min = _VertexList[0]->GetVertex();
1239 _max = _VertexList[0]->GetVertex();
1240
1241 Vec3f v;
1242 for (vector<WVertex *>::iterator wv = _VertexList.begin(), wvend = _VertexList.end();
1243 wv != wvend;
1244 wv++)
1245 {
1246 for (uint i = 0; i < 3; i++) {
1247 v = (*wv)->GetVertex();
1248 if (v[i] < _min[i]) {
1249 _min[i] = v[i];
1250 }
1251 if (v[i] > _max[i]) {
1252 _max[i] = v[i];
1253 }
1254 }
1255 }
1256 }
1257#endif
1258
1259#if 0
1260 inline float ComputeMeanEdgeSize()
1261 {
1262 _meanEdgeSize = _meanEdgeSize / _EdgeList.size();
1263 return _meanEdgeSize;
1264 }
1265#else
1266 real ComputeMeanEdgeSize() const;
1267#endif
1268
1269 protected:
1282 virtual WFace *MakeFace(vector<WVertex *> &iVertexList,
1283 vector<bool> &iFaceEdgeMarksList,
1284 uint iMaterialIndex,
1285 WFace *face);
1286
1287#ifdef WITH_CXX_GUARDEDALLOC
1288 MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:WShape")
1289#endif
1290};
1291
1292/**********************************
1293 * *
1294 * *
1295 * WingedEdge *
1296 * *
1297 * *
1298 **********************************/
1299
1301 public:
1303 {
1304 _numFaces = 0;
1305 }
1306
1308 {
1309 clear();
1310 }
1311
1312 void clear()
1313 {
1314 for (vector<WShape *>::iterator it = _wshapes.begin(); it != _wshapes.end(); it++) {
1315 delete *it;
1316 }
1317 _wshapes.clear();
1318 _numFaces = 0;
1319 }
1320
1321 void addWShape(WShape *wshape)
1322 {
1323 _wshapes.push_back(wshape);
1324 _numFaces += wshape->GetFaceList().size();
1325 }
1326
1327 vector<WShape *> &getWShapes()
1328 {
1329 return _wshapes;
1330 }
1331
1333 {
1334 return _numFaces;
1335 }
1336
1337 private:
1338 vector<WShape *> _wshapes;
1339 uint _numFaces;
1340
1341#ifdef WITH_CXX_GUARDEDALLOC
1342 MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:WingedEdge")
1343#endif
1344};
1345
1346/*
1347 * #############################################
1348 * #############################################
1349 * #############################################
1350 * ###### ######
1351 * ###### I M P L E M E N T A T I O N ######
1352 * ###### ######
1353 * #############################################
1354 * #############################################
1355 * #############################################
1356 */
1357/* for inline functions */
1358void WOEdge::RetrieveCWOrderedEdges(vector<WEdge *> &oEdges)
1359{
1360 WOEdge *currentOEdge = this;
1361 do {
1362 WOEdge *nextOEdge = currentOEdge->GetbFace()->GetNextOEdge(currentOEdge);
1363 oEdges.push_back(nextOEdge->GetOwner());
1364 currentOEdge = nextOEdge->GetOwner()->GetOtherOEdge(nextOEdge);
1365 } while (currentOEdge && (currentOEdge->GetOwner() != GetOwner()));
1366}
1367
1369{
1370 if (_paVertex && _pbVertex) {
1371 _vec = _pbVertex->GetVertex() - _paVertex->GetVertex();
1372 if (_paFace && _pbFace) {
1373 float sine = (_pbFace->GetNormal() ^ _paFace->GetNormal()) * _vec / _vec.norm();
1374 if (sine >= 1.0) {
1375 _angle = M_PI_2;
1376 return;
1377 }
1378 if (sine <= -1.0) {
1379 _angle = -M_PI_2;
1380 return;
1381 }
1382 _angle = ::asin(sine);
1383 }
1384 }
1385}
1386
1387} /* namespace Freestyle */
#define M_PI_2
unsigned int uint
Configuration definitions.
Class used to handle materials.
Vectors and Matrices (useful type definitions)
Read Guarded memory(de)allocation.
in reality light always falls off quadratically Particle Retrieve the data of the particle that spawned the object for example to give variation to multiple instances of an object Point Retrieve information about points in a point cloud Retrieve the edges of an object as it appears to Cycles topology will always appear triangulated Convert a blackbody temperature to an RGB value Normal Generate a perturbed normal from an RGB normal map image Typically used for faking highly detailed surfaces Generate an OSL shader from a file or text data block Image Sample an image file as a texture Gabor Generate Gabor noise Gradient Generate interpolated color and intensity values based on the input vector Magic Generate a psychedelic color texture Voronoi Generate Worley noise based on the distance to random points Typically used to generate textures such as or biological cells Brick Generate a procedural texture producing bricks Texture Retrieve multiple types of texture coordinates nTypically used as inputs for texture nodes Vector Convert a vector
ATTR_WARN_UNUSED_RESULT const BMVert * v2
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
ATTR_WARN_UNUSED_RESULT const BMVert * v
WVertex * GetaVertex()
Definition WEdge.h:601
short GetNumberOfOEdges()
Definition WEdge.h:586
WVertex * GetbVertex()
Definition WEdge.h:606
WFace * GetaFace()
Definition WEdge.h:611
virtual ~WEdge()
Definition WEdge.h:539
void setMark(bool mark)
Definition WEdge.h:661
WOEdge * _pbOEdge
Definition WEdge.h:503
void setId(int id)
Definition WEdge.h:666
WEdge(WOEdge *iaOEdge, WOEdge *ibOEdge)
Definition WEdge.h:527
WOEdge * GetbOEdge()
Definition WEdge.h:581
virtual void ResetUserData()
Definition WEdge.h:671
WOEdge * GetOtherOEdge(WOEdge *iOEdge)
Definition WEdge.h:621
void * userdata
Definition WEdge.h:509
WOEdge * _paOEdge
Definition WEdge.h:502
void setaOEdge(WOEdge *iEdge)
Definition WEdge.h:632
bool GetMark()
Definition WEdge.h:591
virtual WEdge * duplicate()
Definition WEdge.cpp:242
void setbOEdge(WOEdge *iEdge)
Definition WEdge.h:637
short _nOEdges
Definition WEdge.h:504
WOEdge * GetaOEdge()
Definition WEdge.h:576
WFace * GetbFace()
Definition WEdge.h:616
void setNumberOfOEdges(short n)
Definition WEdge.h:656
WEdge(WOEdge *iOEdge)
Definition WEdge.h:519
void AddOEdge(WOEdge *iEdge)
Definition WEdge.h:642
static WVertex * CommonVertex(WEdge *iEdge1, WEdge *iEdge2)
Definition WEdge.h:555
void * userdata
Definition WEdge.h:703
float getArea()
Definition WEdge.cpp:409
const vector< WOEdge * > & getEdgeList()
Definition WEdge.h:716
void setMark(bool iMark)
Definition WEdge.h:936
vector< Vec2f > _VerticesTexCoords
Definition WEdge.h:696
vector< Vec2f > & GetPerVertexTexCoords()
Definition WEdge.h:820
void RetrieveBorderFaces(vector< const WFace * > &oWFaces)
Definition WEdge.h:787
void setNormal(const Vec3f &iNormal)
Definition WEdge.h:911
bool GetMark() const
Definition WEdge.h:741
Vec3f _Normal
Definition WEdge.h:692
WFace * GetBordingFace(int index)
Definition WEdge.h:800
void AddEdge(WOEdge *iEdge)
Definition WEdge.h:956
int numberOfEdges() const
Definition WEdge.h:881
const FrsMaterial & frs_material()
Definition WEdge.cpp:276
Vec3f & GetNormal()
Definition WEdge.h:726
virtual ~WFace()
Definition WEdge.h:713
WOEdge * GetNextOEdge(WOEdge *iOEdge)
Definition WEdge.h:856
vector< WOEdge * > _OEdgeList
Definition WEdge.h:691
Vec3f & GetVertexNormal(WVertex *iVertex)
Definition WEdge.h:838
WOEdge * GetPrevOEdge(WOEdge *iOEdge)
Definition WEdge.cpp:423
virtual WOEdge * MakeEdge(WVertex *v1, WVertex *v2)
Definition WEdge.cpp:281
int numberOfVertices() const
Definition WEdge.h:886
virtual WFace * duplicate()
Definition WEdge.cpp:270
void setId(int id)
Definition WEdge.h:926
void setEdgeList(const vector< WOEdge * > &iEdgeList)
Definition WEdge.h:906
bool isBorder() const
Definition WEdge.h:892
Vec2f & GetVertexTexCoords(int index)
Definition WEdge.h:832
virtual void ResetUserData()
Definition WEdge.h:970
bool getOppositeEdge(const WVertex *v, WOEdge *&e)
Definition WEdge.cpp:380
WShape * getShape()
Definition WEdge.cpp:445
Vec3f & GetVertexNormal(int index)
Definition WEdge.h:826
WFace * GetBordingFace(WOEdge *iOEdge)
Definition WEdge.h:810
void setNormalList(const vector< Vec3f > &iNormalsList)
Definition WEdge.h:916
void setFrsMaterialIndex(uint iMaterialIndex)
Definition WEdge.h:931
virtual WEdge * instanciateEdge() const
Definition WEdge.h:942
void setTexCoordsList(const vector< Vec2f > &iTexCoordsList)
Definition WEdge.h:921
vector< Vec3f > & GetPerVertexNormals()
Definition WEdge.h:815
WOEdge * GetOEdge(int i)
Definition WEdge.h:721
uint frs_materialIndex() const
Definition WEdge.h:736
void RetrieveVertexList(vector< WVertex * > &oVertices)
Definition WEdge.h:777
vector< Vec3f > _VerticesNormals
Definition WEdge.h:695
WVertex * GetVertex(uint index)
Definition WEdge.h:749
uint _FrsMaterialIndex
Definition WEdge.h:699
int GetIndex(WVertex *iVertex)
Definition WEdge.h:762
void setbVertex(WVertex *pv)
Definition WEdge.h:453
WEdge * _pOwner
Definition WEdge.h:334
void setbFace(WFace *pf)
Definition WEdge.h:465
void setaFace(WFace *pf)
Definition WEdge.h:459
WFace * _paFace
Definition WEdge.h:332
void RetrieveCWOrderedEdges(vector< WEdge * > &oEdges)
Definition WEdge.h:1358
WFace * GetaFace()
Definition WEdge.h:397
void setOwner(WEdge *pe)
Definition WEdge.h:471
virtual ~WOEdge()
Definition WEdge.h:358
WVertex * _paVertex
Definition WEdge.h:330
virtual WOEdge * duplicate()
Definition WEdge.cpp:195
WVertex * _pbVertex
Definition WEdge.h:331
WOEdge * twin()
Definition WEdge.cpp:201
void setaVertex(WVertex *pv)
Definition WEdge.h:447
WVertex * GetaVertex()
Definition WEdge.h:387
virtual void ResetUserData()
Definition WEdge.h:482
WFace * _pbFace
Definition WEdge.h:333
void setVecAndAngle()
Definition WEdge.h:1368
WFace * GetbFace()
Definition WEdge.h:402
const Vec3f & GetVec()
Definition WEdge.h:412
WVertex * GetbVertex()
Definition WEdge.h:392
void * userdata
Definition WEdge.h:340
WOEdge * getPrevOnFace()
Definition WEdge.cpp:206
WEdge * GetOwner()
Definition WEdge.h:407
const float GetAngle()
Definition WEdge.h:417
void setFrsMaterials(const vector< FrsMaterial > &iMaterials)
Definition WEdge.h:1142
vector< WVertex * > & getVertexList()
Definition WEdge.h:1053
real ComputeMeanEdgeSize() const
Definition WEdge.cpp:714
void setVertexList(const vector< WVertex * > &iVertexList)
Definition WEdge.h:1114
vector< FrsMaterial > _FrsMaterials
Definition WEdge.h:1001
void setEdgeList(const vector< WEdge * > &iEdgeList)
Definition WEdge.h:1109
void setFrsMaterial(const FrsMaterial &frs_material, uint i)
Definition WEdge.h:1137
vector< WEdge * > & getEdgeList()
Definition WEdge.h:1048
string _LibraryPath
Definition WEdge.h:995
const string & getLibraryPath() const
Definition WEdge.h:1098
void setName(const string &name)
Definition WEdge.h:1147
virtual WShape * duplicate()
Definition WEdge.cpp:460
virtual ~WShape()
Definition WEdge.h:1020
const string & getName() const
Definition WEdge.h:1093
void setLibraryPath(const string &path)
Definition WEdge.h:1152
static void setCurrentId(const uint id)
Definition WEdge.h:1104
virtual WFace * MakeFace(vector< WVertex * > &iVertexList, vector< bool > &iFaceEdgeMarksList, uint iMaterialIndex)
Definition WEdge.cpp:590
void setFaceList(const vector< WFace * > &iFaceList)
Definition WEdge.h:1119
void AddVertex(WVertex *iVertex)
Definition WEdge.h:1203
vector< WFace * > _FaceList
Definition WEdge.h:992
const FrsMaterial & frs_material(uint i) const
Definition WEdge.h:1076
vector< WVertex * > _VertexList
Definition WEdge.h:990
void AddEdge(WEdge *iEdge)
Definition WEdge.h:1193
void AddFace(WFace *iFace)
Definition WEdge.h:1198
vector< WFace * > & GetFaceList()
Definition WEdge.h:1058
void setId(int id)
Definition WEdge.h:1124
static uint _SceneCurrentId
Definition WEdge.h:996
const vector< FrsMaterial > & frs_materials() const
Definition WEdge.h:1081
void ResetUserData()
Definition WEdge.h:1209
vector< WEdge * > _EdgeList
Definition WEdge.h:991
virtual WFace * instanciateFace() const
Definition WEdge.h:1158
face_iterator(incoming_edge_iterator it)
Definition WEdge.h:237
virtual WFace * operator*()
Definition WEdge.cpp:87
face_iterator(const face_iterator &iBrother)
Definition WEdge.h:243
virtual bool operator!=(const face_iterator &b) const
Definition WEdge.h:266
virtual face_iterator & operator++()
Definition WEdge.h:251
virtual face_iterator operator++(int)
Definition WEdge.h:258
input_iterator_tag iterator_category
Definition WEdge.h:222
virtual bool operator==(const face_iterator &b) const
Definition WEdge.h:271
virtual incoming_edge_iterator & operator++()
Definition WEdge.h:184
virtual bool operator!=(const incoming_edge_iterator &b) const
Definition WEdge.h:199
virtual bool operator==(const incoming_edge_iterator &b) const
Definition WEdge.h:204
virtual incoming_edge_iterator operator++(int)
Definition WEdge.h:191
incoming_edge_iterator(WVertex *iVertex, WOEdge *iBegin, WOEdge *iCurrent)
Definition WEdge.h:166
incoming_edge_iterator(const incoming_edge_iterator &iBrother)
Definition WEdge.h:174
void setVertex(const Vec3f &v)
Definition WEdge.h:101
WShape * _Shape
Definition WEdge.h:51
vector< WEdge * > & GetEdges()
Definition WEdge.h:78
Vec3f & GetVertex()
Definition WEdge.h:73
void setSmooth(bool b)
Definition WEdge.h:121
virtual incoming_edge_iterator incoming_edges_begin()
Definition WEdge.cpp:132
virtual face_iterator faces_end()
Definition WEdge.h:301
void * userdata
Definition WEdge.h:56
WVertex(const Vec3f &v)
Definition WEdge.h:57
virtual void ResetUserData()
Definition WEdge.h:139
vector< WEdge * > _EdgeList
Definition WEdge.h:50
virtual incoming_edge_iterator incoming_edges_end()
Definition WEdge.cpp:146
void setEdges(const vector< WEdge * > &iEdgeList)
Definition WEdge.h:106
WShape * shape() const
Definition WEdge.h:88
virtual face_iterator faces_begin()
Definition WEdge.h:296
void setShape(WShape *iShape)
Definition WEdge.h:116
virtual ~WVertex()
Definition WEdge.h:70
void AddEdge(WEdge *iEdge)
Definition WEdge.cpp:127
bool isSmooth() const
Definition WEdge.h:93
void setBorder(bool b)
Definition WEdge.h:126
void setId(int id)
Definition WEdge.h:111
virtual WVertex * duplicate()
Definition WEdge.cpp:61
vector< WShape * > & getWShapes()
Definition WEdge.h:1327
void addWShape(WShape *wshape)
Definition WEdge.h:1321
local_group_size(16, 16) .push_constant(Type b
#define pf(_x, _i)
Prefetch 64.
Definition gim_memory.h:48
VecMat::Vec3< float > Vec3f
Definition Geom.h:28
VecMat::Vec2< float > Vec2f
Definition Geom.h:22
inherits from class Rep
Definition AppCanvas.cpp:20
double real
Definition Precision.h:14
#define min(a, b)
Definition sort.c:32
float max