Blender V4.3
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
12#include "Silhouette.h"
13#include "ViewMap.h"
14
20
22
23#ifdef WITH_CXX_GUARDEDALLOC
24# include "MEM_guardedalloc.h"
25#endif
26
27namespace Freestyle {
28
29class NodeShape;
30class NodeGroup;
31class SShape;
32class WShape;
33
35 public:
37 {
39 _FrsMaterial.setDiffuse(0, 0, 0, 1);
40 _overloadFrsMaterial = false;
41 }
42
43 virtual ~ViewMapTesselator() {}
44
47 NodeGroup *Tesselate(ViewMap *iViewMap);
48
52 template<class ViewEdgesIterator>
53 NodeGroup *Tesselate(ViewEdgesIterator begin, ViewEdgesIterator end);
54
56 NodeGroup *Tesselate(WShape *iWShape);
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:
97
98 protected:
99 virtual void AddVertexToLine(LineRep *iLine, SVertex *v)
100 {
101 iLine->AddVertex(v->point2D());
102 }
103
104#ifdef WITH_CXX_GUARDEDALLOC
105 MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:ViewMapTesselator2D")
106#endif
107};
108
111 public:
114
115 protected:
116 virtual void AddVertexToLine(LineRep *iLine, SVertex *v)
117 {
118 iLine->AddVertex(v->point3D());
119 }
120
121#ifdef WITH_CXX_GUARDEDALLOC
122 MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:ViewMapTesselator3D")
123#endif
124};
125
126//
127// Implementation
128//
130
131template<class ViewEdgesIterator>
132NodeGroup *ViewMapTesselator::Tesselate(ViewEdgesIterator begin, ViewEdgesIterator end)
133{
134 NodeGroup *group = new NodeGroup;
135 NodeShape *tshape = new NodeShape;
136 group->AddChild(tshape);
137 // tshape->frs_material().setDiffuse(0.0f, 0.0f, 0.0f, 1.0f);
138 tshape->setFrsMaterial(_FrsMaterial);
139
140 LineRep *line;
141
142 FEdge *firstEdge;
143 FEdge *nextFEdge, *currentEdge;
144
145 // for (vector<ViewEdge*>::const_iterator c = viewedges.begin(), cend = viewedges.end(); c !=
146 // cend; c++)
147 for (ViewEdgesIterator c = begin, cend = end; c != cend; c++) {
148#if 0
149 if ((*c)->qi() > 0) {
150 continue;
151 }
152 if (!((*c)->nature() & (_nature))) {
153 continue;
154 }
155#endif
156 firstEdge = (*c)->fedgeA();
157
158#if 0
159 if (firstEdge->invisibility() > 0) {
160 continue;
161 }
162#endif
163
164 line = new OrientedLineRep();
165 if (_overloadFrsMaterial) {
166 line->setFrsMaterial(_FrsMaterial);
167 }
168
169 // there might be chains containing a single element
170 if (0 == (firstEdge)->nextEdge()) {
171 line->setStyle(LineRep::LINES);
172 // line->AddVertex((*c)->vertexA()->point3D());
173 // line->AddVertex((*c)->vertexB()->point3D());
174 AddVertexToLine(line, firstEdge->vertexA());
175 AddVertexToLine(line, firstEdge->vertexB());
176 }
177 else {
178 line->setStyle(LineRep::LINE_STRIP);
179
180 // firstEdge = (*c);
181 nextFEdge = firstEdge;
182 currentEdge = firstEdge;
183 do {
184 // line->AddVertex(nextFEdge->vertexA()->point3D());
185 AddVertexToLine(line, nextFEdge->vertexA());
186 currentEdge = nextFEdge;
187 nextFEdge = nextFEdge->nextEdge();
188 } while ((nextFEdge != nullptr) && (nextFEdge != firstEdge));
189 // Add the last vertex
190 // line->AddVertex(currentEdge->vertexB()->point3D());
191 AddVertexToLine(line, currentEdge->vertexB());
192 }
193
194 line->setId((*c)->getId().getFirst());
195 line->ComputeBBox();
196 tshape->AddRep(line);
197 }
198
199 return group;
200}
201
202} /* 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.
ATTR_WARN_UNUSED_RESULT const BMVert * v
FEdge * nextEdge()
Definition Silhouette.h:623
SVertex * vertexA()
Definition Silhouette.h:597
SVertex * vertexB()
Definition Silhouette.h:603
int invisibility() const
void setDiffuse(float r, float g, float b, float a)
void AddVertex(const Vec3r &iVertex)
Definition LineRep.h:97
virtual void AddRep(Rep *iRep)
Definition NodeShape.h:39
void setFrsMaterial(const FrsMaterial &iMaterial)
Definition NodeShape.h:55
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