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