Blender  V2.93
ViewMapTesselator.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
17 #pragma once
18 
24 #include "Silhouette.h"
25 #include "ViewMap.h"
26 
27 #include "../scene_graph/LineRep.h"
28 #include "../scene_graph/NodeGroup.h"
29 #include "../scene_graph/NodeShape.h"
30 #include "../scene_graph/OrientedLineRep.h"
31 #include "../scene_graph/VertexRep.h"
32 
33 #include "../winged_edge/WEdge.h"
34 
35 #ifdef WITH_CXX_GUARDEDALLOC
36 # include "MEM_guardedalloc.h"
37 #endif
38 
39 namespace Freestyle {
40 
41 class NodeShape;
42 class NodeGroup;
43 class SShape;
44 class WShape;
45 
47  public:
49  {
51  _FrsMaterial.setDiffuse(0, 0, 0, 1);
52  _overloadFrsMaterial = false;
53  }
54 
56  {
57  }
58 
61  NodeGroup *Tesselate(ViewMap *iViewMap);
62 
66  template<class ViewEdgesIterator>
67  NodeGroup *Tesselate(ViewEdgesIterator begin, ViewEdgesIterator end);
68 
71 
72  inline void setNature(Nature::EdgeNature iNature)
73  {
74  _nature = iNature;
75  }
76 
77  inline void setFrsMaterial(const FrsMaterial &iMaterial)
78  {
79  _FrsMaterial = iMaterial;
80  _overloadFrsMaterial = true;
81  }
82 
84  {
85  return _nature;
86  }
87 
88  inline const FrsMaterial &frs_material() const
89  {
90  return _FrsMaterial;
91  }
92 
93  protected:
94  virtual void AddVertexToLine(LineRep *iLine, SVertex *v) = 0;
95 
96  private:
97  Nature::EdgeNature _nature;
98  FrsMaterial _FrsMaterial;
99  bool _overloadFrsMaterial;
100 
101 #ifdef WITH_CXX_GUARDEDALLOC
102  MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:ViewMapTesselator")
103 #endif
104 };
105 
108  public:
110  {
111  }
113  {
114  }
115 
116  protected:
117  virtual void AddVertexToLine(LineRep *iLine, SVertex *v)
118  {
119  iLine->AddVertex(v->point2D());
120  }
121 
122 #ifdef WITH_CXX_GUARDEDALLOC
123  MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:ViewMapTesselator2D")
124 #endif
125 };
126 
129  public:
131  {
132  }
134  {
135  }
136 
137  protected:
138  virtual void AddVertexToLine(LineRep *iLine, SVertex *v)
139  {
140  iLine->AddVertex(v->point3D());
141  }
142 
143 #ifdef WITH_CXX_GUARDEDALLOC
144  MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:ViewMapTesselator3D")
145 #endif
146 };
147 
148 //
149 // Implementation
150 //
152 
153 template<class ViewEdgesIterator>
154 NodeGroup *ViewMapTesselator::Tesselate(ViewEdgesIterator begin, ViewEdgesIterator end)
155 {
156  NodeGroup *group = new NodeGroup;
157  NodeShape *tshape = new NodeShape;
158  group->AddChild(tshape);
159  // tshape->frs_material().setDiffuse(0.0f, 0.0f, 0.0f, 1.0f);
160  tshape->setFrsMaterial(_FrsMaterial);
161 
162  LineRep *line;
163 
164  FEdge *firstEdge;
165  FEdge *nextFEdge, *currentEdge;
166 
167  int id = 0;
168  // for (vector<ViewEdge*>::const_iterator c = viewedges.begin(), cend = viewedges.end(); c !=
169  // cend; c++)
170  for (ViewEdgesIterator c = begin, cend = end; c != cend; c++) {
171 #if 0
172  if ((*c)->qi() > 0) {
173  continue;
174  }
175  if (!((*c)->nature() & (_nature))) {
176  continue;
177  }
178 #endif
179  firstEdge = (*c)->fedgeA();
180 
181 #if 0
182  if (firstEdge->invisibility() > 0) {
183  continue;
184  }
185 #endif
186 
187  line = new OrientedLineRep();
188  if (_overloadFrsMaterial) {
189  line->setFrsMaterial(_FrsMaterial);
190  }
191 
192  // there might be chains containing a single element
193  if (0 == (firstEdge)->nextEdge()) {
194  line->setStyle(LineRep::LINES);
195  // line->AddVertex((*c)->vertexA()->point3D());
196  // line->AddVertex((*c)->vertexB()->point3D());
197  AddVertexToLine(line, firstEdge->vertexA());
198  AddVertexToLine(line, firstEdge->vertexB());
199  }
200  else {
202 
203  // firstEdge = (*c);
204  nextFEdge = firstEdge;
205  currentEdge = firstEdge;
206  do {
207  // line->AddVertex(nextFEdge->vertexA()->point3D());
208  AddVertexToLine(line, nextFEdge->vertexA());
209  currentEdge = nextFEdge;
210  nextFEdge = nextFEdge->nextEdge();
211  } while ((nextFEdge != NULL) && (nextFEdge != firstEdge));
212  // Add the last vertex
213  // line->AddVertex(currentEdge->vertexB()->point3D());
214  AddVertexToLine(line, currentEdge->vertexB());
215  }
216 
217  line->setId((*c)->getId().getFirst());
218  line->ComputeBBox();
219  tshape->AddRep(line);
220  id++;
221  }
222 
223  return group;
224 }
225 
226 } /* 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:611
SVertex * vertexB()
Definition: Silhouette.h:617
int invisibility() const
Definition: Silhouette.cpp:253
FEdge * nextEdge()
Definition: Silhouette.h:637
void setDiffuse(const float r, const float g, const float b, const float a)
Definition: FrsMaterial.h:388
void AddVertex(const Vec3r &iVertex)
Definition: LineRep.h:109
void setStyle(const LINES_STYLE iStyle)
Definition: LineRep.h:104
virtual void ComputeBBox()
Definition: LineRep.cpp:26
virtual void AddChild(Node *iChild)
Definition: NodeGroup.cpp:28
virtual void AddRep(Rep *iRep)
Definition: NodeShape.h:53
void setFrsMaterial(const FrsMaterial &iMaterial)
Definition: NodeShape.h:69
void setId(const Id &id)
Definition: Rep.h:154
void setFrsMaterial(const FrsMaterial &iMaterial)
Definition: Rep.h:169
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:52
unsigned short EdgeNature
Definition: Nature.h:46
static const EdgeNature CREASE
Definition: Nature.h:54
static const EdgeNature SILHOUETTE
Definition: Nature.h:50
inherits from class Rep
Definition: AppCanvas.cpp:32
static unsigned c
Definition: RandGen.cpp:97