2
* ***** BEGIN GPL LICENSE BLOCK *****
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU General Public License
6
* as published by the Free Software Foundation; either version 2
7
* of the License, or (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
* GNU General Public License for more details.
14
* You should have received a copy of the GNU General Public License
15
* along with this program; if not, write to the Free Software Foundation,
16
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18
* ***** END GPL LICENSE BLOCK *****
21
#ifndef __FREESTYLE_VIEW_MAP_TESSELATOR_H__
22
#define __FREESTYLE_VIEW_MAP_TESSELATOR_H__
24
/** \file blender/freestyle/intern/view_map/ViewMapTesselator.h
26
* \brief Class to build a Node Tree designed to be displayed from a Silhouette View Map structure.
27
* \author Stephane Grabli
31
#include "Silhouette.h"
34
#include "../scene_graph/LineRep.h"
35
#include "../scene_graph/NodeShape.h"
36
#include "../scene_graph/NodeGroup.h"
37
#include "../scene_graph/OrientedLineRep.h"
38
#include "../scene_graph/VertexRep.h"
40
#include "../winged_edge/WEdge.h"
42
#ifdef WITH_CXX_GUARDEDALLOC
43
#include "MEM_guardedalloc.h"
53
class LIB_VIEW_MAP_EXPORT ViewMapTesselator
56
inline ViewMapTesselator()
58
_nature = Nature::SILHOUETTE | Nature::BORDER | Nature::CREASE;
59
_FrsMaterial.setDiffuse(0, 0, 0, 1);
60
_overloadFrsMaterial = false;
63
virtual ~ViewMapTesselator() {}
65
/*! Builds a set of lines rep contained under a a NodeShape, itself contained under a NodeGroup from a ViewMap */
66
NodeGroup *Tesselate(ViewMap *iViewMap);
68
/*! Builds a set of lines rep contained under a a NodeShape, itself contained under a NodeGroup from a set of
71
template<class ViewEdgesIterator>
72
NodeGroup *Tesselate(ViewEdgesIterator begin, ViewEdgesIterator end);
74
/*! Builds a set of lines rep contained among a NodeShape, from a WShape */
75
NodeGroup *Tesselate(WShape *iWShape);
77
inline void setNature(Nature::EdgeNature iNature)
82
inline void setFrsMaterial(const FrsMaterial& iMaterial)
84
_FrsMaterial = iMaterial;
85
_overloadFrsMaterial = true;
88
inline Nature::EdgeNature nature()
93
inline const FrsMaterial& frs_material() const
99
virtual void AddVertexToLine(LineRep *iLine, SVertex *v) = 0;
102
Nature::EdgeNature _nature;
103
FrsMaterial _FrsMaterial;
104
bool _overloadFrsMaterial;
106
#ifdef WITH_CXX_GUARDEDALLOC
108
MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:ViewMapTesselator")
112
/*! Class to tesselate the 2D projected silhouette */
113
class ViewMapTesselator2D : public ViewMapTesselator
116
inline ViewMapTesselator2D() : ViewMapTesselator() {}
117
virtual ~ViewMapTesselator2D() {}
120
virtual void AddVertexToLine(LineRep *iLine, SVertex *v)
122
iLine->AddVertex(v->point2D());
126
/*! Class to tesselate the 3D silhouette */
127
class ViewMapTesselator3D : public ViewMapTesselator
130
inline ViewMapTesselator3D() : ViewMapTesselator() {}
131
virtual ~ViewMapTesselator3D() {}
134
virtual void AddVertexToLine(LineRep *iLine, SVertex *v)
136
iLine->AddVertex(v->point3D());
143
///////////////////////////////////////////////
145
template<class ViewEdgesIterator>
146
NodeGroup *ViewMapTesselator::Tesselate(ViewEdgesIterator begin, ViewEdgesIterator end)
148
NodeGroup *group = new NodeGroup;
149
NodeShape *tshape = new NodeShape;
150
group->AddChild(tshape);
151
//tshape->frs_material().setDiffuse(0.0f, 0.0f, 0.0f, 1.0f);
152
tshape->setFrsMaterial(_FrsMaterial);
157
FEdge *nextFEdge, *currentEdge;
160
//for (vector<ViewEdge*>::const_iterator c = viewedges.begin(), cend = viewedges.end(); c != cend; c++)
161
for (ViewEdgesIterator c = begin, cend = end; c != cend; c++) {
163
if ((*c)->qi() > 0) {
166
if (!((*c)->nature() & (_nature))) {
170
firstEdge = (*c)->fedgeA();
173
if (firstEdge->invisibility() > 0)
177
line = new OrientedLineRep();
178
if (_overloadFrsMaterial)
179
line->setFrsMaterial(_FrsMaterial);
181
// there might be chains containing a single element
182
if (0 == (firstEdge)->nextEdge()) {
183
line->setStyle(LineRep::LINES);
184
//line->AddVertex((*c)->vertexA()->point3D());
185
//line->AddVertex((*c)->vertexB()->point3D());
186
AddVertexToLine(line, firstEdge->vertexA());
187
AddVertexToLine(line, firstEdge->vertexB());
190
line->setStyle(LineRep::LINE_STRIP);
193
nextFEdge = firstEdge;
194
currentEdge = firstEdge;
196
//line->AddVertex(nextFEdge->vertexA()->point3D());
197
AddVertexToLine(line, nextFEdge->vertexA());
198
currentEdge = nextFEdge;
199
nextFEdge = nextFEdge->nextEdge();
200
} while ((nextFEdge != NULL) && (nextFEdge != firstEdge));
201
// Add the last vertex
202
//line->AddVertex(currentEdge->vertexB()->point3D());
203
AddVertexToLine(line, currentEdge->vertexB());
206
line->setId((*c)->getId().getFirst());
208
tshape->AddRep(line);
215
} /* namespace Freestyle */
217
#endif // __FREESTYLE_VIEW_MAP_TESSELATOR_H__