Blender V5.0
ViewMapTesselator.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 "Silhouette.h"
13#include "ViewMap.h"
14
20
22
23#include "MEM_guardedalloc.h"
24
25namespace Freestyle {
26
27class NodeShape;
28class NodeGroup;
29class SShape;
30class WShape;
31
33 public:
35 {
37 _FrsMaterial.setDiffuse(0, 0, 0, 1);
38 _overloadFrsMaterial = false;
39 }
40
41 virtual ~ViewMapTesselator() {}
42
45 NodeGroup *Tesselate(ViewMap *iViewMap);
46
50 template<class ViewEdgesIterator>
51 NodeGroup *Tesselate(ViewEdgesIterator begin, ViewEdgesIterator end);
52
54 NodeGroup *Tesselate(WShape *iWShape);
55
56 inline void setNature(Nature::EdgeNature iNature)
57 {
58 _nature = iNature;
59 }
60
61 inline void setFrsMaterial(const FrsMaterial &iMaterial)
62 {
63 _FrsMaterial = iMaterial;
64 _overloadFrsMaterial = true;
65 }
66
68 {
69 return _nature;
70 }
71
72 inline const FrsMaterial &frs_material() const
73 {
74 return _FrsMaterial;
75 }
76
77 protected:
78 virtual void AddVertexToLine(LineRep *iLine, SVertex *v) = 0;
79
80 private:
81 Nature::EdgeNature _nature;
82 FrsMaterial _FrsMaterial;
83 bool _overloadFrsMaterial;
84
85 MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:ViewMapTesselator")
86};
87
90 public:
93
94 protected:
95 virtual void AddVertexToLine(LineRep *iLine, SVertex *v)
96 {
97 iLine->AddVertex(v->point2D());
98 }
99
100 MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:ViewMapTesselator2D")
101};
102
105 public:
108
109 protected:
110 virtual void AddVertexToLine(LineRep *iLine, SVertex *v)
111 {
112 iLine->AddVertex(v->point3D());
113 }
114
115 MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:ViewMapTesselator3D")
116};
117
118//
119// Implementation
120//
122
123template<class ViewEdgesIterator>
124NodeGroup *ViewMapTesselator::Tesselate(ViewEdgesIterator begin, ViewEdgesIterator end)
125{
126 NodeGroup *group = new NodeGroup;
127 NodeShape *tshape = new NodeShape;
128 group->AddChild(tshape);
129 // tshape->frs_material().setDiffuse(0.0f, 0.0f, 0.0f, 1.0f);
130 tshape->setFrsMaterial(_FrsMaterial);
131
132 LineRep *line;
133
134 FEdge *firstEdge;
135 FEdge *nextFEdge, *currentEdge;
136
137 // for (vector<ViewEdge*>::const_iterator c = viewedges.begin(), cend = viewedges.end(); c !=
138 // cend; c++)
139 for (ViewEdgesIterator c = begin, cend = end; c != cend; c++) {
140#if 0
141 if ((*c)->qi() > 0) {
142 continue;
143 }
144 if (!((*c)->nature() & (_nature))) {
145 continue;
146 }
147#endif
148 firstEdge = (*c)->fedgeA();
149
150#if 0
151 if (firstEdge->invisibility() > 0) {
152 continue;
153 }
154#endif
155
156 line = new OrientedLineRep();
157 if (_overloadFrsMaterial) {
158 line->setFrsMaterial(_FrsMaterial);
159 }
160
161 // there might be chains containing a single element
162 if (0 == (firstEdge)->nextEdge()) {
164 // line->AddVertex((*c)->vertexA()->point3D());
165 // line->AddVertex((*c)->vertexB()->point3D());
166 AddVertexToLine(line, firstEdge->vertexA());
167 AddVertexToLine(line, firstEdge->vertexB());
168 }
169 else {
171
172 // firstEdge = (*c);
173 nextFEdge = firstEdge;
174 currentEdge = firstEdge;
175 do {
176 // line->AddVertex(nextFEdge->vertexA()->point3D());
177 AddVertexToLine(line, nextFEdge->vertexA());
178 currentEdge = nextFEdge;
179 nextFEdge = nextFEdge->nextEdge();
180 } while ((nextFEdge != nullptr) && (nextFEdge != firstEdge));
181 // Add the last vertex
182 // line->AddVertex(currentEdge->vertexB()->point3D());
183 AddVertexToLine(line, currentEdge->vertexB());
184 }
185
186 line->setId((*c)->getId().getFirst());
187 line->ComputeBBox();
188 tshape->AddRep(line);
189 }
190
191 return group;
192}
193
194} /* namespace Freestyle */
Class to define the representation of 3D Line.
Read Guarded memory(de)allocation.
Class to represent a group node. This node can contains several children.
Class to build a shape node. It contains a Rep, which is the shape geometry.
Class to display an oriented line representation.
Classes to define a silhouette structure.
Class to define the representation of a vertex for displaying purpose.
Classes to define a View Map (ViewVertex, ViewEdge, etc.).
Classes to define a Winged Edge data structure.
iter begin(iter)
ATTR_WARN_UNUSED_RESULT const BMVert * v
FEdge * nextEdge()
Definition Silhouette.h:619
SVertex * vertexA()
Definition Silhouette.h:593
SVertex * vertexB()
Definition Silhouette.h:599
int invisibility() const
void AddVertex(const Vec3r &iVertex)
Definition LineRep.h:97
void setStyle(const LINES_STYLE iStyle)
Definition LineRep.h:92
virtual void ComputeBBox()
Definition LineRep.cpp:14
virtual void AddChild(Node *iChild)
Definition NodeGroup.cpp:16
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:142
void setFrsMaterial(const FrsMaterial &iMaterial)
Definition Rep.h:157
virtual void AddVertexToLine(LineRep *iLine, SVertex *v)
virtual void AddVertexToLine(LineRep *iLine, SVertex *v)
void setFrsMaterial(const FrsMaterial &iMaterial)
const FrsMaterial & frs_material() const
void setNature(Nature::EdgeNature iNature)
virtual void AddVertexToLine(LineRep *iLine, SVertex *v)=0
NodeGroup * Tesselate(ViewMap *iViewMap)
static const EdgeNature BORDER
Definition Nature.h:42
static const EdgeNature CREASE
Definition Nature.h:44
ushort EdgeNature
Definition Nature.h:36
static const EdgeNature SILHOUETTE
Definition Nature.h:40
inherits from class Rep
Definition AppCanvas.cpp:20
static uint c
Definition RandGen.cpp:87