Blender  V2.93
StrokeTesselator.cpp
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 
22 #include "StrokeTesselator.h"
24 
25 #include "../scene_graph/NodeGroup.h"
26 #include "../scene_graph/NodeShape.h"
27 #include "../scene_graph/OrientedLineRep.h"
28 
29 namespace Freestyle {
30 
32 {
33  if (nullptr == iStroke) {
34  return nullptr;
35  }
36 
37  LineRep *line;
38  line = new OrientedLineRep();
39 
41  if (2 == iStroke->vertices_size()) {
42  line->setStyle(LineRep::LINES);
43  v = iStroke->vertices_begin();
44  StrokeVertex *svA = (*v);
45  v++;
46  StrokeVertex *svB = (*v);
47  Vec3r A((*svA)[0], (*svA)[1], 0);
48  Vec3r B((*svB)[0], (*svB)[1], 0);
49  line->AddVertex(A);
50  line->AddVertex(B);
51  }
52  else {
53  if (_overloadFrsMaterial) {
54  line->setFrsMaterial(_FrsMaterial);
55  }
56 
58 
59  for (v = iStroke->vertices_begin(), vend = iStroke->vertices_end(); v != vend; v++) {
60  StrokeVertex *sv = (*v);
61  Vec3r V((*sv)[0], (*sv)[1], 0);
62  line->AddVertex(V);
63  }
64  }
65  line->setId(iStroke->getId());
66  line->ComputeBBox();
67 
68  return line;
69 }
70 
71 template<class StrokeVertexIterator>
72 NodeGroup *StrokeTesselator::Tesselate(StrokeVertexIterator begin, StrokeVertexIterator end)
73 {
74  NodeGroup *group = new NodeGroup;
75  NodeShape *tshape = new NodeShape;
76  group->AddChild(tshape);
77  // tshape->material().setDiffuse(0.0f, 0.0f, 0.0f, 1.0f);
78  tshape->setFrsMaterial(_FrsMaterial);
79 
80  for (StrokeVertexIterator c = begin, cend = end; c != cend; c++) {
81  tshape->AddRep(Tesselate((*c)));
82  }
83 
84  return group;
85 }
86 
87 } /* namespace Freestyle */
Iterators used to iterate over the elements of the Stroke. Can't be used in python.
Class to build a Node Tree designed to be displayed from a set of strokes structure.
ATTR_WARN_UNUSED_RESULT const BMVert * v
#define A
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
LineRep * Tesselate(Stroke *iStroke)
const_vertex_iterator vertices_begin() const
embedding vertex iterator
Definition: Stroke.cpp:749
virtual Id getId() const
Definition: Stroke.h:512
int vertices_size() const
Definition: Stroke.h:684
const_vertex_iterator vertices_end() const
Definition: Stroke.cpp:754
#define B
inherits from class Rep
Definition: AppCanvas.cpp:32
static unsigned c
Definition: RandGen.cpp:97
CCL_NAMESPACE_BEGIN struct View V