Blender  V3.3
WEdge.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #pragma once
4 
10 #include <iterator>
11 #include <vector>
12 
13 #include "../geometry/Geom.h"
14 
15 #include "../scene_graph/FrsMaterial.h"
16 
17 #include "../system/FreestyleConfig.h"
18 
19 #include "BLI_math.h"
20 
21 #ifdef WITH_CXX_GUARDEDALLOC
22 # include "MEM_guardedalloc.h"
23 #endif
24 
25 using namespace std;
26 
27 namespace Freestyle {
28 
29 using namespace Geometry;
30 
31 /**********************************
32  * *
33  * *
34  * WVertex *
35  * *
36  * *
37  **********************************/
38 
39 class WOEdge;
40 class WEdge;
41 class WShape;
42 class WFace;
43 
44 class 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 = NULL;
60  _Shape = NULL;
61  _Smooth = true;
62  _Border = -1;
63  }
64 
66  WVertex(WVertex &iBrother);
67  virtual WVertex *duplicate();
68  virtual ~WVertex()
69  {
70  }
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 = NULL;
142  }
143 
144  public:
147  public:
148  using iterator_category = input_iterator_tag;
149  using value_type = WOEdge *;
150  using difference_type = ptrdiff_t;
151  using pointer = value_type *;
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;
225  using pointer = value_type *;
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  {
298  return face_iterator(incoming_edges_begin());
299  }
300 
302  {
303  return face_iterator(incoming_edges_end());
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 
319 class WFace;
320 class WEdge;
321 
322 class 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 = NULL;
346  _pbCWEdge = NULL;
347  _paCCWEdge = NULL;
348  _pbCCWEdge = NULL;
349 #endif
350  _paVertex = NULL;
351  _pbVertex = NULL;
352  _paFace = NULL;
353  _pbFace = NULL;
354  _pOwner = NULL;
355  userdata = NULL;
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 
387  inline WVertex *GetaVertex()
388  {
389  return _paVertex;
390  }
391 
392  inline WVertex *GetbVertex()
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;
450  setVecAndAngle();
451  }
452 
453  inline void setbVertex(WVertex *pv)
454  {
455  _pbVertex = pv;
456  setVecAndAngle();
457  }
458 
459  inline void setaFace(WFace *pf)
460  {
461  _paFace = pf;
462  setVecAndAngle();
463  }
464 
465  inline void setbFace(WFace *pf)
466  {
467  _pbFace = pf;
468  setVecAndAngle();
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();
480  WOEdge *getPrevOnFace();
481 
482  virtual void ResetUserData()
483  {
484  userdata = NULL;
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 
500 class 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 = NULL;
514  _pbOEdge = NULL;
515  _nOEdges = 0;
516  userdata = NULL;
517  }
518 
519  inline WEdge(WOEdge *iOEdge)
520  {
521  _paOEdge = iOEdge;
522  _pbOEdge = NULL;
523  _nOEdges = 1;
524  userdata = NULL;
525  }
526 
527  inline WEdge(WOEdge *iaOEdge, WOEdge *ibOEdge)
528  {
529  _paOEdge = iaOEdge;
530  _pbOEdge = ibOEdge;
531  _nOEdges = 2;
532  userdata = NULL;
533  }
534 
536  WEdge(WEdge &iBrother);
537  virtual WEdge *duplicate();
538 
539  virtual ~WEdge()
540  {
541  if (_paOEdge) {
542  delete _paOEdge;
543  _paOEdge = NULL;
544  }
545 
546  if (_pbOEdge) {
547  delete _pbOEdge;
548  _pbOEdge = NULL;
549  }
550  }
551 
555  static inline WVertex *CommonVertex(WEdge *iEdge1, WEdge *iEdge2)
556  {
557  if (!iEdge1 || !iEdge2) {
558  return NULL;
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 NULL;
573  }
574 
576  inline WOEdge *GetaOEdge()
577  {
578  return _paOEdge;
579  }
580 
581  inline WOEdge *GetbOEdge()
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 
601  inline WVertex *GetaVertex()
602  {
603  return _paOEdge->GetaVertex();
604  }
605 
606  inline WVertex *GetbVertex()
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 = NULL;
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 
689 class 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 = NULL;
707  _FrsMaterialIndex = 0;
708  }
709 
711  WFace(WFace &iBrother);
712  virtual WFace *duplicate();
713  virtual ~WFace()
714  {
715  }
716 
718  inline const vector<WOEdge *> &getEdgeList()
719  {
720  return _OEdgeList;
721  }
722 
723  inline WOEdge *GetOEdge(int i)
724  {
725  return _OEdgeList[i];
726  }
727 
728  inline Vec3f &GetNormal()
729  {
730  return _Normal;
731  }
732 
733  inline int GetId()
734  {
735  return _Id;
736  }
737 
738  inline unsigned frs_materialIndex() const
739  {
740  return _FrsMaterialIndex;
741  }
742 
743  inline bool GetMark() const
744  {
745  return _Mark;
746  }
747 
748  const FrsMaterial &frs_material();
749 
751  inline WVertex *GetVertex(unsigned int index)
752  {
753 #if 0
754  if (index >= _OEdgeList.size()) {
755  return NULL;
756  }
757 #endif
758  return _OEdgeList[index]->GetaVertex();
759  }
760 
764  inline int GetIndex(WVertex *iVertex)
765  {
766  int index = 0;
767  for (vector<WOEdge *>::iterator woe = _OEdgeList.begin(), woend = _OEdgeList.end();
768  woe != woend;
769  woe++) {
770  if ((*woe)->GetaVertex() == iVertex) {
771  return index;
772  }
773  ++index;
774  }
775  return -1;
776  }
777 
778  inline void RetrieveVertexList(vector<WVertex *> &oVertices)
779  {
780  for (vector<WOEdge *>::iterator woe = _OEdgeList.begin(), woend = _OEdgeList.end();
781  woe != woend;
782  woe++) {
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  WFace *af;
793  if ((af = (*woe)->GetaFace())) {
794  oWFaces.push_back(af);
795  }
796  }
797  }
798 
799  inline WFace *GetBordingFace(int index)
800  {
801 #if 0
802  if (index >= _OEdgeList.size()) {
803  return NULL;
804  }
805 #endif
806  return _OEdgeList[index]->GetaFace();
807  }
808 
809  inline WFace *GetBordingFace(WOEdge *iOEdge)
810  {
811  return iOEdge->GetaFace();
812  }
813 
814  inline vector<Vec3f> &GetPerVertexNormals()
815  {
816  return _VerticesNormals;
817  }
818 
819  inline vector<Vec2f> &GetPerVertexTexCoords()
820  {
821  return _VerticesTexCoords;
822  }
823 
825  inline Vec3f &GetVertexNormal(int index)
826  {
827  return _VerticesNormals[index];
828  }
829 
831  inline Vec2f &GetVertexTexCoords(int index)
832  {
833  return _VerticesTexCoords[index];
834  }
835 
837  inline Vec3f &GetVertexNormal(WVertex *iVertex)
838  {
839  int i = 0;
840  int index = 0;
841  for (vector<WOEdge *>::const_iterator woe = _OEdgeList.begin(), woend = _OEdgeList.end();
842  woe != woend;
843  woe++) {
844  if ((*woe)->GetaVertex() == iVertex) {
845  index = i;
846  break;
847  }
848  ++i;
849  }
850 
851  return _VerticesNormals[index];
852  }
853 
854  inline WOEdge *GetNextOEdge(WOEdge *iOEdge)
855  {
856  bool found = false;
857  vector<WOEdge *>::iterator woe, woend, woefirst;
858  woefirst = _OEdgeList.begin();
859  for (woe = woefirst, woend = _OEdgeList.end(); woe != woend; ++woe) {
860  if (found) {
861  return (*woe);
862  }
863 
864  if ((*woe) == iOEdge) {
865  found = true;
866  }
867  }
868 
869  // We left the loop. That means that the first OEdge was the good one:
870  if (found) {
871  return (*woefirst);
872  }
873 
874  return NULL;
875  }
876 
877  WOEdge *GetPrevOEdge(WOEdge *iOEdge);
878 
879  inline int numberOfEdges() const
880  {
881  return _OEdgeList.size();
882  }
883 
884  inline int numberOfVertices() const
885  {
886  return _OEdgeList.size();
887  }
888 
890  inline bool isBorder() const
891  {
892  for (vector<WOEdge *>::const_iterator woe = _OEdgeList.begin(), woeend = _OEdgeList.end();
893  woe != woeend;
894  ++woe) {
895  if ((*woe)->GetOwner()->GetbOEdge() == 0) {
896  return true;
897  }
898  }
899  return false;
900  }
901 
903  inline void setEdgeList(const vector<WOEdge *> &iEdgeList)
904  {
905  _OEdgeList = iEdgeList;
906  }
907 
908  inline void setNormal(const Vec3f &iNormal)
909  {
910  _Normal = iNormal;
911  }
912 
913  inline void setNormalList(const vector<Vec3f> &iNormalsList)
914  {
915  _VerticesNormals = iNormalsList;
916  }
917 
918  inline void setTexCoordsList(const vector<Vec2f> &iTexCoordsList)
919  {
920  _VerticesTexCoords = iTexCoordsList;
921  }
922 
923  inline void setId(int id)
924  {
925  _Id = id;
926  }
927 
928  inline void setFrsMaterialIndex(unsigned iMaterialIndex)
929  {
930  _FrsMaterialIndex = iMaterialIndex;
931  }
932 
933  inline void setMark(bool iMark)
934  {
935  _Mark = iMark;
936  }
937 
939  virtual WEdge *instanciateEdge() const
940  {
941  return new WEdge;
942  }
943 
950  virtual WOEdge *MakeEdge(WVertex *v1, WVertex *v2);
951 
953  inline void AddEdge(WOEdge *iEdge)
954  {
955  _OEdgeList.push_back(iEdge);
956  }
957 
961  bool getOppositeEdge(const WVertex *v, WOEdge *&e);
962 
964  float getArea();
965 
966  WShape *getShape();
967  virtual void ResetUserData()
968  {
969  userdata = NULL;
970  }
971 
972 #ifdef WITH_CXX_GUARDEDALLOC
973  MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:WFace")
974 #endif
975 };
976 
977 /**********************************
978  * *
979  * *
980  * WShape *
981  * *
982  * *
983  **********************************/
984 
985 class WShape {
986  protected:
987  vector<WVertex *> _VertexList;
988  vector<WEdge *> _EdgeList;
989  vector<WFace *> _FaceList;
990  int _Id;
991  string _Name;
992  string _LibraryPath;
993  static unsigned _SceneCurrentId;
994 #if 0
995  Vec3f _min;
996  Vec3f _max;
997 #endif
998  vector<FrsMaterial> _FrsMaterials;
999 #if 0
1000  float _meanEdgeSize;
1001 #endif
1002 
1003  public:
1004  inline WShape()
1005  {
1006 #if 0
1007  _meanEdgeSize = 0;
1008 #endif
1009  _Id = _SceneCurrentId;
1010  _SceneCurrentId++;
1011  }
1012 
1014  WShape(WShape &iBrother);
1015  virtual WShape *duplicate();
1016 
1017  virtual ~WShape()
1018  {
1019  if (_EdgeList.size() != 0) {
1020  vector<WEdge *>::iterator e;
1021  for (e = _EdgeList.begin(); e != _EdgeList.end(); ++e) {
1022  delete (*e);
1023  }
1024  _EdgeList.clear();
1025  }
1026 
1027  if (_VertexList.size() != 0) {
1028  vector<WVertex *>::iterator v;
1029  for (v = _VertexList.begin(); v != _VertexList.end(); ++v) {
1030  delete (*v);
1031  }
1032  _VertexList.clear();
1033  }
1034 
1035  if (_FaceList.size() != 0) {
1036  vector<WFace *>::iterator f;
1037  for (f = _FaceList.begin(); f != _FaceList.end(); ++f) {
1038  delete (*f);
1039  }
1040  _FaceList.clear();
1041  }
1042  }
1043 
1045  inline vector<WEdge *> &getEdgeList()
1046  {
1047  return _EdgeList;
1048  }
1049 
1050  inline vector<WVertex *> &getVertexList()
1051  {
1052  return _VertexList;
1053  }
1054 
1055  inline vector<WFace *> &GetFaceList()
1056  {
1057  return _FaceList;
1058  }
1059 
1060  inline unsigned GetId()
1061  {
1062  return _Id;
1063  }
1064 
1065 #if 0
1066  inline void bbox(Vec3f &min, Vec3f &max)
1067  {
1068  min = _min;
1069  max = _max;
1070  }
1071 #endif
1072 
1073  inline const FrsMaterial &frs_material(unsigned i) const
1074  {
1075  return _FrsMaterials[i];
1076  }
1077 
1078  inline const vector<FrsMaterial> &frs_materials() const
1079  {
1080  return _FrsMaterials;
1081  }
1082 
1083 #if 0
1084  inline const float getMeanEdgeSize() const
1085  {
1086  return _meanEdgeSize;
1087  }
1088 #endif
1089 
1090  inline const string &getName() const
1091  {
1092  return _Name;
1093  }
1094 
1095  inline const string &getLibraryPath() const
1096  {
1097  return _LibraryPath;
1098  }
1099 
1101  static inline void setCurrentId(const unsigned id)
1102  {
1103  _SceneCurrentId = id;
1104  }
1105 
1106  inline void setEdgeList(const vector<WEdge *> &iEdgeList)
1107  {
1108  _EdgeList = iEdgeList;
1109  }
1110 
1111  inline void setVertexList(const vector<WVertex *> &iVertexList)
1112  {
1113  _VertexList = iVertexList;
1114  }
1115 
1116  inline void setFaceList(const vector<WFace *> &iFaceList)
1117  {
1118  _FaceList = iFaceList;
1119  }
1120 
1121  inline void setId(int id)
1122  {
1123  _Id = id;
1124  }
1125 
1126 #if 0
1127  inline void setBBox(const Vec3f &min, const Vec3f &max)
1128  {
1129  _min = min;
1130  _max = max;
1131  }
1132 #endif
1133 
1134  inline void setFrsMaterial(const FrsMaterial &frs_material, unsigned i)
1135  {
1136  _FrsMaterials[i] = frs_material;
1137  }
1138 
1139  inline void setFrsMaterials(const vector<FrsMaterial> &iMaterials)
1140  {
1141  _FrsMaterials = iMaterials;
1142  }
1143 
1144  inline void setName(const string &name)
1145  {
1146  _Name = name;
1147  }
1148 
1149  inline void setLibraryPath(const string &path)
1150  {
1151  _LibraryPath = path;
1152  }
1153 
1155  virtual WFace *instanciateFace() const
1156  {
1157  return new WFace;
1158  }
1159 
1169  virtual WFace *MakeFace(vector<WVertex *> &iVertexList,
1170  vector<bool> &iFaceEdgeMarksList,
1171  unsigned iMaterialIndex);
1172 
1184  virtual WFace *MakeFace(vector<WVertex *> &iVertexList,
1185  vector<Vec3f> &iNormalsList,
1186  vector<Vec2f> &iTexCoordsList,
1187  vector<bool> &iFaceEdgeMarksList,
1188  unsigned iMaterialIndex);
1189 
1190  inline void AddEdge(WEdge *iEdge)
1191  {
1192  _EdgeList.push_back(iEdge);
1193  }
1194 
1195  inline void AddFace(WFace *iFace)
1196  {
1197  _FaceList.push_back(iFace);
1198  }
1199 
1200  inline void AddVertex(WVertex *iVertex)
1201  {
1202  iVertex->setShape(this);
1203  _VertexList.push_back(iVertex);
1204  }
1205 
1206  inline void ResetUserData()
1207  {
1208  for (vector<WVertex *>::iterator v = _VertexList.begin(), vend = _VertexList.end(); v != vend;
1209  v++) {
1210  (*v)->ResetUserData();
1211  }
1212 
1213  for (vector<WEdge *>::iterator e = _EdgeList.begin(), eend = _EdgeList.end(); e != eend; e++) {
1214  (*e)->ResetUserData();
1215  // manages WOEdge:
1216  WOEdge *oe = (*e)->GetaOEdge();
1217  if (oe) {
1218  oe->ResetUserData();
1219  }
1220  oe = (*e)->GetbOEdge();
1221  if (oe) {
1222  oe->ResetUserData();
1223  }
1224  }
1225 
1226  for (vector<WFace *>::iterator f = _FaceList.begin(), fend = _FaceList.end(); f != fend; f++) {
1227  (*f)->ResetUserData();
1228  }
1229  }
1230 
1231 #if 0
1232  inline void ComputeBBox()
1233  {
1234  _min = _VertexList[0]->GetVertex();
1235  _max = _VertexList[0]->GetVertex();
1236 
1237  Vec3f v;
1238  for (vector<WVertex *>::iterator wv = _VertexList.begin(), wvend = _VertexList.end();
1239  wv != wvend;
1240  wv++) {
1241  for (unsigned int i = 0; i < 3; i++) {
1242  v = (*wv)->GetVertex();
1243  if (v[i] < _min[i]) {
1244  _min[i] = v[i];
1245  }
1246  if (v[i] > _max[i]) {
1247  _max[i] = v[i];
1248  }
1249  }
1250  }
1251  }
1252 #endif
1253 
1254 #if 0
1255  inline float ComputeMeanEdgeSize()
1256  {
1257  _meanEdgeSize = _meanEdgeSize / _EdgeList.size();
1258  return _meanEdgeSize;
1259  }
1260 #else
1261  real ComputeMeanEdgeSize() const;
1262 #endif
1263 
1264  protected:
1277  virtual WFace *MakeFace(vector<WVertex *> &iVertexList,
1278  vector<bool> &iFaceEdgeMarksList,
1279  unsigned iMaterialIndex,
1280  WFace *face);
1281 
1282 #ifdef WITH_CXX_GUARDEDALLOC
1283  MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:WShape")
1284 #endif
1285 };
1286 
1287 /**********************************
1288  * *
1289  * *
1290  * WingedEdge *
1291  * *
1292  * *
1293  **********************************/
1294 
1295 class WingedEdge {
1296  public:
1298  {
1299  _numFaces = 0;
1300  }
1301 
1303  {
1304  clear();
1305  }
1306 
1307  void clear()
1308  {
1309  for (vector<WShape *>::iterator it = _wshapes.begin(); it != _wshapes.end(); it++) {
1310  delete *it;
1311  }
1312  _wshapes.clear();
1313  _numFaces = 0;
1314  }
1315 
1316  void addWShape(WShape *wshape)
1317  {
1318  _wshapes.push_back(wshape);
1319  _numFaces += wshape->GetFaceList().size();
1320  }
1321 
1322  vector<WShape *> &getWShapes()
1323  {
1324  return _wshapes;
1325  }
1326 
1327  unsigned getNumFaces()
1328  {
1329  return _numFaces;
1330  }
1331 
1332  private:
1333  vector<WShape *> _wshapes;
1334  unsigned _numFaces;
1335 
1336 #ifdef WITH_CXX_GUARDEDALLOC
1337  MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:WingedEdge")
1338 #endif
1339 };
1340 
1341 /*
1342  * #############################################
1343  * #############################################
1344  * #############################################
1345  * ###### ######
1346  * ###### I M P L E M E N T A T I O N ######
1347  * ###### ######
1348  * #############################################
1349  * #############################################
1350  * #############################################
1351  */
1352 /* for inline functions */
1353 void WOEdge::RetrieveCWOrderedEdges(vector<WEdge *> &oEdges)
1354 {
1355  WOEdge *currentOEdge = this;
1356  do {
1357  WOEdge *nextOEdge = currentOEdge->GetbFace()->GetNextOEdge(currentOEdge);
1358  oEdges.push_back(nextOEdge->GetOwner());
1359  currentOEdge = nextOEdge->GetOwner()->GetOtherOEdge(nextOEdge);
1360  } while (currentOEdge && (currentOEdge->GetOwner() != GetOwner()));
1361 }
1362 
1363 inline void WOEdge::setVecAndAngle()
1364 {
1365  if (_paVertex && _pbVertex) {
1366  _vec = _pbVertex->GetVertex() - _paVertex->GetVertex();
1367  if (_paFace && _pbFace) {
1368  float sine = (_pbFace->GetNormal() ^ _paFace->GetNormal()) * _vec / _vec.norm();
1369  if (sine >= 1.0) {
1370  _angle = M_PI_2;
1371  return;
1372  }
1373  if (sine <= -1.0) {
1374  _angle = -M_PI_2;
1375  return;
1376  }
1377  _angle = ::asin(sine);
1378  }
1379  }
1380 }
1381 
1382 } /* namespace Freestyle */
#define M_PI_2
Definition: BLI_math_base.h:23
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble v1
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
value_type norm() const
Definition: VecMat.h:95
short GetNumberOfOEdges()
Definition: WEdge.h:586
WFace * GetaFace()
Definition: WEdge.h:611
int GetId()
Definition: WEdge.h:596
virtual ~WEdge()
Definition: WEdge.h:539
void setMark(bool mark)
Definition: WEdge.h:661
static WVertex * CommonVertex(WEdge *iEdge1, WEdge *iEdge2)
Definition: WEdge.h:555
WOEdge * GetbOEdge()
Definition: WEdge.h:581
WOEdge * _pbOEdge
Definition: WEdge.h:503
void setId(int id)
Definition: WEdge.h:666
WEdge(WOEdge *iaOEdge, WOEdge *ibOEdge)
Definition: WEdge.h:527
WVertex * GetbVertex()
Definition: WEdge.h:606
WOEdge * GetOtherOEdge(WOEdge *iOEdge)
Definition: WEdge.h:621
virtual void ResetUserData()
Definition: WEdge.h:671
void * userdata
Definition: WEdge.h:509
WFace * GetbFace()
Definition: WEdge.h:616
WOEdge * _paOEdge
Definition: WEdge.h:502
void setaOEdge(WOEdge *iEdge)
Definition: WEdge.h:632
bool GetMark()
Definition: WEdge.h:591
void setbOEdge(WOEdge *iEdge)
Definition: WEdge.h:637
short _nOEdges
Definition: WEdge.h:504
void setNumberOfOEdges(short n)
Definition: WEdge.h:656
WEdge(WOEdge *iOEdge)
Definition: WEdge.h:519
WOEdge * GetaOEdge()
Definition: WEdge.h:576
WVertex * GetaVertex()
Definition: WEdge.h:601
void AddOEdge(WOEdge *iEdge)
Definition: WEdge.h:642
void * userdata
Definition: WEdge.h:703
void setMark(bool iMark)
Definition: WEdge.h:933
unsigned frs_materialIndex() const
Definition: WEdge.h:738
Vec3f & GetVertexNormal(WVertex *iVertex)
Definition: WEdge.h:837
vector< Vec3f > & GetPerVertexNormals()
Definition: WEdge.h:814
Vec3f & GetVertexNormal(int index)
Definition: WEdge.h:825
vector< Vec2f > _VerticesTexCoords
Definition: WEdge.h:696
Vec2f & GetVertexTexCoords(int index)
Definition: WEdge.h:831
void RetrieveBorderFaces(vector< const WFace * > &oWFaces)
Definition: WEdge.h:787
void setNormal(const Vec3f &iNormal)
Definition: WEdge.h:908
void setFrsMaterialIndex(unsigned iMaterialIndex)
Definition: WEdge.h:928
int GetId()
Definition: WEdge.h:733
bool GetMark() const
Definition: WEdge.h:743
Vec3f _Normal
Definition: WEdge.h:692
virtual WEdge * instanciateEdge() const
Definition: WEdge.h:939
void AddEdge(WOEdge *iEdge)
Definition: WEdge.h:953
int numberOfEdges() const
Definition: WEdge.h:879
Vec3f & GetNormal()
Definition: WEdge.h:728
virtual ~WFace()
Definition: WEdge.h:713
vector< WOEdge * > _OEdgeList
Definition: WEdge.h:691
unsigned _FrsMaterialIndex
Definition: WEdge.h:699
int numberOfVertices() const
Definition: WEdge.h:884
void setId(int id)
Definition: WEdge.h:923
void setEdgeList(const vector< WOEdge * > &iEdgeList)
Definition: WEdge.h:903
bool isBorder() const
Definition: WEdge.h:890
virtual void ResetUserData()
Definition: WEdge.h:967
WOEdge * GetOEdge(int i)
Definition: WEdge.h:723
WOEdge * GetNextOEdge(WOEdge *iOEdge)
Definition: WEdge.h:854
WVertex * GetVertex(unsigned int index)
Definition: WEdge.h:751
void setNormalList(const vector< Vec3f > &iNormalsList)
Definition: WEdge.h:913
void setTexCoordsList(const vector< Vec2f > &iTexCoordsList)
Definition: WEdge.h:918
vector< Vec2f > & GetPerVertexTexCoords()
Definition: WEdge.h:819
WFace * GetBordingFace(WOEdge *iOEdge)
Definition: WEdge.h:809
const vector< WOEdge * > & getEdgeList()
Definition: WEdge.h:718
WFace * GetBordingFace(int index)
Definition: WEdge.h:799
void RetrieveVertexList(vector< WVertex * > &oVertices)
Definition: WEdge.h:778
vector< Vec3f > _VerticesNormals
Definition: WEdge.h:695
int GetIndex(WVertex *iVertex)
Definition: WEdge.h:764
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 setOwner(WEdge *pe)
Definition: WEdge.h:471
virtual ~WOEdge()
Definition: WEdge.h:358
WVertex * _paVertex
Definition: WEdge.h:330
WFace * GetbFace()
Definition: WEdge.h:402
const Vec3f & GetVec()
Definition: WEdge.h:412
WVertex * _pbVertex
Definition: WEdge.h:331
WVertex * GetaVertex()
Definition: WEdge.h:387
void setaVertex(WVertex *pv)
Definition: WEdge.h:447
virtual void ResetUserData()
Definition: WEdge.h:482
WFace * _pbFace
Definition: WEdge.h:333
WEdge * GetOwner()
Definition: WEdge.h:407
WFace * GetaFace()
Definition: WEdge.h:397
float _angle
Definition: WEdge.h:337
void * userdata
Definition: WEdge.h:340
WVertex * GetbVertex()
Definition: WEdge.h:392
const float GetAngle()
Definition: WEdge.h:417
vector< WEdge * > & getEdgeList()
Definition: WEdge.h:1045
void setFrsMaterials(const vector< FrsMaterial > &iMaterials)
Definition: WEdge.h:1139
void setVertexList(const vector< WVertex * > &iVertexList)
Definition: WEdge.h:1111
vector< FrsMaterial > _FrsMaterials
Definition: WEdge.h:998
void setEdgeList(const vector< WEdge * > &iEdgeList)
Definition: WEdge.h:1106
virtual WFace * instanciateFace() const
Definition: WEdge.h:1155
static void setCurrentId(const unsigned id)
Definition: WEdge.h:1101
string _LibraryPath
Definition: WEdge.h:992
void setName(const string &name)
Definition: WEdge.h:1144
const string & getLibraryPath() const
Definition: WEdge.h:1095
static unsigned _SceneCurrentId
Definition: WEdge.h:993
virtual ~WShape()
Definition: WEdge.h:1017
void setLibraryPath(const string &path)
Definition: WEdge.h:1149
const string & getName() const
Definition: WEdge.h:1090
void setFaceList(const vector< WFace * > &iFaceList)
Definition: WEdge.h:1116
void AddVertex(WVertex *iVertex)
Definition: WEdge.h:1200
vector< WFace * > _FaceList
Definition: WEdge.h:989
vector< WVertex * > _VertexList
Definition: WEdge.h:987
const vector< FrsMaterial > & frs_materials() const
Definition: WEdge.h:1078
void AddEdge(WEdge *iEdge)
Definition: WEdge.h:1190
void AddFace(WFace *iFace)
Definition: WEdge.h:1195
vector< WVertex * > & getVertexList()
Definition: WEdge.h:1050
void setId(int id)
Definition: WEdge.h:1121
string _Name
Definition: WEdge.h:991
void setFrsMaterial(const FrsMaterial &frs_material, unsigned i)
Definition: WEdge.h:1134
vector< WFace * > & GetFaceList()
Definition: WEdge.h:1055
void ResetUserData()
Definition: WEdge.h:1206
vector< WEdge * > _EdgeList
Definition: WEdge.h:988
unsigned GetId()
Definition: WEdge.h:1060
const FrsMaterial & frs_material(unsigned i) const
Definition: WEdge.h:1073
face_iterator(incoming_edge_iterator it)
Definition: WEdge.h:237
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++(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 face_iterator & operator++()
Definition: WEdge.h:251
input_iterator_tag iterator_category
Definition: WEdge.h:148
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
virtual incoming_edge_iterator & operator++()
Definition: WEdge.h:184
void setVertex(const Vec3f &v)
Definition: WEdge.h:101
Vec3f & GetVertex()
Definition: WEdge.h:73
WShape * _Shape
Definition: WEdge.h:49
vector< WEdge * > & GetEdges()
Definition: WEdge.h:78
WShape * shape() const
Definition: WEdge.h:88
void setSmooth(bool b)
Definition: WEdge.h:121
virtual face_iterator faces_end()
Definition: WEdge.h:301
void * userdata
Definition: WEdge.h:54
WVertex(const Vec3f &v)
Definition: WEdge.h:55
virtual void ResetUserData()
Definition: WEdge.h:139
vector< WEdge * > _EdgeList
Definition: WEdge.h:48
void setEdges(const vector< WEdge * > &iEdgeList)
Definition: WEdge.h:106
Vec3f _Vertex
Definition: WEdge.h:47
virtual face_iterator faces_begin()
Definition: WEdge.h:296
void setShape(WShape *iShape)
Definition: WEdge.h:116
virtual ~WVertex()
Definition: WEdge.h:68
bool isSmooth() const
Definition: WEdge.h:93
void setBorder(bool b)
Definition: WEdge.h:126
short _Border
Definition: WEdge.h:51
void setId(int id)
Definition: WEdge.h:111
unsigned getNumFaces()
Definition: WEdge.h:1327
vector< WShape * > & getWShapes()
Definition: WEdge.h:1322
void addWShape(WShape *wshape)
Definition: WEdge.h:1316
#define pf(_x, _i)
Prefetch 64.
Definition: gim_memory.h:48
static void clear(Message *msg)
Definition: msgfmt.c:278
Vec< T, N > operator*(const typename Vec< T, N >::value_type r, const Vec< T, N > &v)
Definition: VecMat.h:844
inherits from class Rep
Definition: AppCanvas.cpp:18
double real
Definition: Precision.h:12
INLINE Rall1d< T, V, S > asin(const Rall1d< T, V, S > &x)
Definition: rall1d.h:391
static const pxr::TfToken b("b", pxr::TfToken::Immortal)
#define min(a, b)
Definition: sort.c:35
float max