Blender  V3.3
ViewMapTesselator.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #pragma once
4 
10 #include "Silhouette.h"
11 #include "ViewMap.h"
12 
13 #include "../scene_graph/LineRep.h"
14 #include "../scene_graph/NodeGroup.h"
15 #include "../scene_graph/NodeShape.h"
16 #include "../scene_graph/OrientedLineRep.h"
17 #include "../scene_graph/VertexRep.h"
18 
19 #include "../winged_edge/WEdge.h"
20 
21 #ifdef WITH_CXX_GUARDEDALLOC
22 # include "MEM_guardedalloc.h"
23 #endif
24 
25 namespace Freestyle {
26 
27 class NodeShape;
28 class NodeGroup;
29 class SShape;
30 class WShape;
31 
33  public:
35  {
37  _FrsMaterial.setDiffuse(0, 0, 0, 1);
38  _overloadFrsMaterial = false;
39  }
40 
42  {
43  }
44 
47  NodeGroup *Tesselate(ViewMap *iViewMap);
48 
52  template<class ViewEdgesIterator>
53  NodeGroup *Tesselate(ViewEdgesIterator begin, ViewEdgesIterator end);
54 
57 
58  inline void setNature(Nature::EdgeNature iNature)
59  {
60  _nature = iNature;
61  }
62 
63  inline void setFrsMaterial(const FrsMaterial &iMaterial)
64  {
65  _FrsMaterial = iMaterial;
66  _overloadFrsMaterial = true;
67  }
68 
70  {
71  return _nature;
72  }
73 
74  inline const FrsMaterial &frs_material() const
75  {
76  return _FrsMaterial;
77  }
78 
79  protected:
80  virtual void AddVertexToLine(LineRep *iLine, SVertex *v) = 0;
81 
82  private:
83  Nature::EdgeNature _nature;
84  FrsMaterial _FrsMaterial;
85  bool _overloadFrsMaterial;
86 
87 #ifdef WITH_CXX_GUARDEDALLOC
88  MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:ViewMapTesselator")
89 #endif
90 };
91 
94  public:
96  {
97  }
99  {
100  }
101 
102  protected:
103  virtual void AddVertexToLine(LineRep *iLine, SVertex *v)
104  {
105  iLine->AddVertex(v->point2D());
106  }
107 
108 #ifdef WITH_CXX_GUARDEDALLOC
109  MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:ViewMapTesselator2D")
110 #endif
111 };
112 
115  public:
117  {
118  }
120  {
121  }
122 
123  protected:
124  virtual void AddVertexToLine(LineRep *iLine, SVertex *v)
125  {
126  iLine->AddVertex(v->point3D());
127  }
128 
129 #ifdef WITH_CXX_GUARDEDALLOC
130  MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:ViewMapTesselator3D")
131 #endif
132 };
133 
134 //
135 // Implementation
136 //
138 
139 template<class ViewEdgesIterator>
140 NodeGroup *ViewMapTesselator::Tesselate(ViewEdgesIterator begin, ViewEdgesIterator end)
141 {
142  NodeGroup *group = new NodeGroup;
143  NodeShape *tshape = new NodeShape;
144  group->AddChild(tshape);
145  // tshape->frs_material().setDiffuse(0.0f, 0.0f, 0.0f, 1.0f);
146  tshape->setFrsMaterial(_FrsMaterial);
147 
148  LineRep *line;
149 
150  FEdge *firstEdge;
151  FEdge *nextFEdge, *currentEdge;
152 
153  int id = 0;
154  // for (vector<ViewEdge*>::const_iterator c = viewedges.begin(), cend = viewedges.end(); c !=
155  // cend; c++)
156  for (ViewEdgesIterator c = begin, cend = end; c != cend; c++) {
157 #if 0
158  if ((*c)->qi() > 0) {
159  continue;
160  }
161  if (!((*c)->nature() & (_nature))) {
162  continue;
163  }
164 #endif
165  firstEdge = (*c)->fedgeA();
166 
167 #if 0
168  if (firstEdge->invisibility() > 0) {
169  continue;
170  }
171 #endif
172 
173  line = new OrientedLineRep();
174  if (_overloadFrsMaterial) {
175  line->setFrsMaterial(_FrsMaterial);
176  }
177 
178  // there might be chains containing a single element
179  if (0 == (firstEdge)->nextEdge()) {
180  line->setStyle(LineRep::LINES);
181  // line->AddVertex((*c)->vertexA()->point3D());
182  // line->AddVertex((*c)->vertexB()->point3D());
183  AddVertexToLine(line, firstEdge->vertexA());
184  AddVertexToLine(line, firstEdge->vertexB());
185  }
186  else {
188 
189  // firstEdge = (*c);
190  nextFEdge = firstEdge;
191  currentEdge = firstEdge;
192  do {
193  // line->AddVertex(nextFEdge->vertexA()->point3D());
194  AddVertexToLine(line, nextFEdge->vertexA());
195  currentEdge = nextFEdge;
196  nextFEdge = nextFEdge->nextEdge();
197  } while ((nextFEdge != NULL) && (nextFEdge != firstEdge));
198  // Add the last vertex
199  // line->AddVertex(currentEdge->vertexB()->point3D());
200  AddVertexToLine(line, currentEdge->vertexB());
201  }
202 
203  line->setId((*c)->getId().getFirst());
204  line->ComputeBBox();
205  tshape->AddRep(line);
206  id++;
207  }
208 
209  return group;
210 }
211 
212 } /* namespace Freestyle */
Read Guarded memory(de)allocation.
Classes to define a silhouette structure.
Classes to define a View Map (ViewVertex, ViewEdge, etc.)
ATTR_WARN_UNUSED_RESULT const BMVert * v
SVertex * vertexA()
Definition: Silhouette.h:597
SVertex * vertexB()
Definition: Silhouette.h:603
int invisibility() const
Definition: Silhouette.cpp:239
FEdge * nextEdge()
Definition: Silhouette.h:623
void setDiffuse(float r, float g, float b, float a)
Definition: FrsMaterial.h:374
void AddVertex(const Vec3r &iVertex)
Definition: LineRep.h:95
void setStyle(const LINES_STYLE iStyle)
Definition: LineRep.h:90
virtual void ComputeBBox()
Definition: LineRep.cpp:12
virtual void AddChild(Node *iChild)
Definition: NodeGroup.cpp:14
virtual void AddRep(Rep *iRep)
Definition: NodeShape.h:39
void setFrsMaterial(const FrsMaterial &iMaterial)
Definition: NodeShape.h:55
void setId(const Id &id)
Definition: Rep.h:140
void setFrsMaterial(const FrsMaterial &iMaterial)
Definition: Rep.h:155
virtual void AddVertexToLine(LineRep *iLine, SVertex *v)
virtual void AddVertexToLine(LineRep *iLine, SVertex *v)
Nature::EdgeNature nature()
NodeGroup * Tesselate(WShape *iWShape)
void setFrsMaterial(const FrsMaterial &iMaterial)
void setNature(Nature::EdgeNature iNature)
virtual void AddVertexToLine(LineRep *iLine, SVertex *v)=0
const FrsMaterial & frs_material() const
NodeGroup * Tesselate(ViewMap *iViewMap)
static const EdgeNature BORDER
Definition: Nature.h:38
unsigned short EdgeNature
Definition: Nature.h:32
static const EdgeNature CREASE
Definition: Nature.h:40
static const EdgeNature SILHOUETTE
Definition: Nature.h:36
inherits from class Rep
Definition: AppCanvas.cpp:18
static unsigned c
Definition: RandGen.cpp:83