~ubuntu-branches/ubuntu/trusty/blender/trusty-proposed

« back to all changes in this revision

Viewing changes to source/blender/freestyle/intern/view_map/ViewMapTesselator.h

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2013-08-14 10:43:49 UTC
  • mfrom: (14.2.19 sid)
  • Revision ID: package-import@ubuntu.com-20130814104349-t1d5mtwkphp12dyj
Tags: 2.68a-3
* Upload to unstable
* debian/: python3.3 Depends simplified
  - debian/control: python3.3 Depends dropped
    for blender-data package
  - 0001-blender_thumbnailer.patch refreshed
* debian/control: libavcodec b-dep versioning dropped

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * ***** BEGIN GPL LICENSE BLOCK *****
 
3
 *
 
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.
 
8
 *
 
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.
 
13
 *
 
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.
 
17
 *
 
18
 * ***** END GPL LICENSE BLOCK *****
 
19
 */
 
20
 
 
21
#ifndef __FREESTYLE_VIEW_MAP_TESSELATOR_H__
 
22
#define __FREESTYLE_VIEW_MAP_TESSELATOR_H__
 
23
 
 
24
/** \file blender/freestyle/intern/view_map/ViewMapTesselator.h
 
25
 *  \ingroup freestyle
 
26
 *  \brief Class to build a Node Tree designed to be displayed from a Silhouette View Map structure.
 
27
 *  \author Stephane Grabli
 
28
 *  \date 26/03/2002
 
29
 */
 
30
 
 
31
#include "Silhouette.h"
 
32
#include "ViewMap.h"
 
33
 
 
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"
 
39
 
 
40
#include "../winged_edge/WEdge.h"
 
41
 
 
42
#ifdef WITH_CXX_GUARDEDALLOC
 
43
#include "MEM_guardedalloc.h"
 
44
#endif
 
45
 
 
46
namespace Freestyle {
 
47
 
 
48
class NodeShape;
 
49
class NodeGroup;
 
50
class SShape;
 
51
class WShape;
 
52
 
 
53
class LIB_VIEW_MAP_EXPORT ViewMapTesselator
 
54
{
 
55
public:
 
56
        inline ViewMapTesselator()
 
57
        {
 
58
                _nature = Nature::SILHOUETTE | Nature::BORDER | Nature::CREASE;
 
59
                _FrsMaterial.setDiffuse(0, 0, 0, 1);
 
60
                _overloadFrsMaterial = false;
 
61
        }
 
62
 
 
63
        virtual ~ViewMapTesselator() {}
 
64
 
 
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);
 
67
 
 
68
        /*! Builds a set of lines rep contained under a a NodeShape, itself contained under a NodeGroup from a set of
 
69
         *  view edges
 
70
         */
 
71
        template<class ViewEdgesIterator>
 
72
        NodeGroup *Tesselate(ViewEdgesIterator begin, ViewEdgesIterator end);
 
73
 
 
74
        /*! Builds a set of lines rep contained among a NodeShape, from a WShape */
 
75
        NodeGroup *Tesselate(WShape *iWShape);
 
76
 
 
77
        inline void setNature(Nature::EdgeNature iNature)
 
78
        {
 
79
                _nature = iNature;
 
80
        }
 
81
 
 
82
        inline void setFrsMaterial(const FrsMaterial& iMaterial)
 
83
        {
 
84
                _FrsMaterial = iMaterial;
 
85
                _overloadFrsMaterial = true;
 
86
        }
 
87
 
 
88
        inline Nature::EdgeNature nature()
 
89
        {
 
90
                return _nature;
 
91
        }
 
92
 
 
93
        inline const FrsMaterial& frs_material() const
 
94
        {
 
95
                return _FrsMaterial;
 
96
        }
 
97
 
 
98
protected:
 
99
        virtual void AddVertexToLine(LineRep *iLine, SVertex *v) = 0;
 
100
 
 
101
private:
 
102
        Nature::EdgeNature _nature;
 
103
        FrsMaterial _FrsMaterial;
 
104
        bool _overloadFrsMaterial;
 
105
 
 
106
#ifdef WITH_CXX_GUARDEDALLOC
 
107
public:
 
108
        MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:ViewMapTesselator")
 
109
#endif
 
110
};
 
111
 
 
112
/*! Class to tesselate the 2D projected silhouette */
 
113
class ViewMapTesselator2D : public ViewMapTesselator
 
114
{
 
115
public:
 
116
        inline ViewMapTesselator2D() : ViewMapTesselator() {}
 
117
        virtual ~ViewMapTesselator2D() {}
 
118
 
 
119
protected:
 
120
        virtual void AddVertexToLine(LineRep *iLine, SVertex *v)
 
121
        {
 
122
                iLine->AddVertex(v->point2D());
 
123
        }
 
124
};
 
125
 
 
126
/*! Class to tesselate the 3D silhouette */
 
127
class ViewMapTesselator3D : public ViewMapTesselator
 
128
{
 
129
public:
 
130
        inline ViewMapTesselator3D() : ViewMapTesselator() {}
 
131
        virtual ~ViewMapTesselator3D() {}
 
132
 
 
133
protected:
 
134
        virtual void AddVertexToLine(LineRep *iLine, SVertex *v)
 
135
        {
 
136
                iLine->AddVertex(v->point3D());
 
137
        }
 
138
};
 
139
 
 
140
//
 
141
// Implementation
 
142
//
 
143
///////////////////////////////////////////////
 
144
 
 
145
template<class ViewEdgesIterator>
 
146
NodeGroup *ViewMapTesselator::Tesselate(ViewEdgesIterator begin, ViewEdgesIterator end)
 
147
{
 
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);
 
153
 
 
154
        LineRep *line;
 
155
 
 
156
        FEdge *firstEdge;
 
157
        FEdge *nextFEdge, *currentEdge;
 
158
 
 
159
        int id = 0;
 
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++) {
 
162
#if 0
 
163
                if ((*c)->qi() > 0) {
 
164
                        continue;
 
165
                }
 
166
                if (!((*c)->nature() & (_nature))) {
 
167
                        continue;
 
168
                }
 
169
#endif
 
170
                firstEdge = (*c)->fedgeA();
 
171
 
 
172
#if 0
 
173
                if (firstEdge->invisibility() > 0)
 
174
                        continue;
 
175
#endif
 
176
 
 
177
                line = new OrientedLineRep();
 
178
                if (_overloadFrsMaterial)
 
179
                        line->setFrsMaterial(_FrsMaterial);
 
180
 
 
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());
 
188
                }
 
189
                else {
 
190
                        line->setStyle(LineRep::LINE_STRIP);
 
191
 
 
192
                        //firstEdge = (*c);
 
193
                        nextFEdge = firstEdge;
 
194
                        currentEdge = firstEdge;
 
195
                        do {
 
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());
 
204
                }
 
205
 
 
206
                line->setId((*c)->getId().getFirst());
 
207
                line->ComputeBBox();
 
208
                tshape->AddRep(line);
 
209
                id++;
 
210
        }
 
211
 
 
212
        return group;
 
213
}
 
214
 
 
215
} /* namespace Freestyle */
 
216
 
 
217
#endif // __FREESTYLE_VIEW_MAP_TESSELATOR_H__