Welcome to mirror list, hosted at ThFree Co, Russian Federation.

ViewMapTesselator.h « view_map « intern « freestyle « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2da95d47912b989e4244bfc3dc308acf1f8347cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
/* SPDX-License-Identifier: GPL-2.0-or-later */

#pragma once

/** \file
 * \ingroup freestyle
 * \brief Class to build a Node Tree designed to be displayed from a Silhouette View Map structure.
 */

#include "Silhouette.h"
#include "ViewMap.h"

#include "../scene_graph/LineRep.h"
#include "../scene_graph/NodeGroup.h"
#include "../scene_graph/NodeShape.h"
#include "../scene_graph/OrientedLineRep.h"
#include "../scene_graph/VertexRep.h"

#include "../winged_edge/WEdge.h"

#ifdef WITH_CXX_GUARDEDALLOC
#  include "MEM_guardedalloc.h"
#endif

namespace Freestyle {

class NodeShape;
class NodeGroup;
class SShape;
class WShape;

class ViewMapTesselator {
 public:
  inline ViewMapTesselator()
  {
    _nature = Nature::SILHOUETTE | Nature::BORDER | Nature::CREASE;
    _FrsMaterial.setDiffuse(0, 0, 0, 1);
    _overloadFrsMaterial = false;
  }

  virtual ~ViewMapTesselator()
  {
  }

  /** Builds a set of lines rep contained under a NodeShape, itself contained under a NodeGroup
   * from a ViewMap */
  NodeGroup *Tesselate(ViewMap *iViewMap);

  /** Builds a set of lines rep contained under a NodeShape, itself contained under a NodeGroup
   * from a set of view edges
   */
  template<class ViewEdgesIterator>
  NodeGroup *Tesselate(ViewEdgesIterator begin, ViewEdgesIterator end);

  /** Builds a set of lines rep contained among a NodeShape, from a WShape */
  NodeGroup *Tesselate(WShape *iWShape);

  inline void setNature(Nature::EdgeNature iNature)
  {
    _nature = iNature;
  }

  inline void setFrsMaterial(const FrsMaterial &iMaterial)
  {
    _FrsMaterial = iMaterial;
    _overloadFrsMaterial = true;
  }

  inline Nature::EdgeNature nature()
  {
    return _nature;
  }

  inline const FrsMaterial &frs_material() const
  {
    return _FrsMaterial;
  }

 protected:
  virtual void AddVertexToLine(LineRep *iLine, SVertex *v) = 0;

 private:
  Nature::EdgeNature _nature;
  FrsMaterial _FrsMaterial;
  bool _overloadFrsMaterial;

#ifdef WITH_CXX_GUARDEDALLOC
  MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:ViewMapTesselator")
#endif
};

/** Class to tesselate the 2D projected silhouette */
class ViewMapTesselator2D : public ViewMapTesselator {
 public:
  inline ViewMapTesselator2D() : ViewMapTesselator()
  {
  }
  virtual ~ViewMapTesselator2D()
  {
  }

 protected:
  virtual void AddVertexToLine(LineRep *iLine, SVertex *v)
  {
    iLine->AddVertex(v->point2D());
  }

#ifdef WITH_CXX_GUARDEDALLOC
  MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:ViewMapTesselator2D")
#endif
};

/** Class to tesselate the 3D silhouette */
class ViewMapTesselator3D : public ViewMapTesselator {
 public:
  inline ViewMapTesselator3D() : ViewMapTesselator()
  {
  }
  virtual ~ViewMapTesselator3D()
  {
  }

 protected:
  virtual void AddVertexToLine(LineRep *iLine, SVertex *v)
  {
    iLine->AddVertex(v->point3D());
  }

#ifdef WITH_CXX_GUARDEDALLOC
  MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:ViewMapTesselator3D")
#endif
};

//
// Implementation
//
///////////////////////////////////////////////

template<class ViewEdgesIterator>
NodeGroup *ViewMapTesselator::Tesselate(ViewEdgesIterator begin, ViewEdgesIterator end)
{
  NodeGroup *group = new NodeGroup;
  NodeShape *tshape = new NodeShape;
  group->AddChild(tshape);
  // tshape->frs_material().setDiffuse(0.0f, 0.0f, 0.0f, 1.0f);
  tshape->setFrsMaterial(_FrsMaterial);

  LineRep *line;

  FEdge *firstEdge;
  FEdge *nextFEdge, *currentEdge;

  int id = 0;
  // for (vector<ViewEdge*>::const_iterator c = viewedges.begin(), cend = viewedges.end(); c !=
  // cend; c++)
  for (ViewEdgesIterator c = begin, cend = end; c != cend; c++) {
#if 0
    if ((*c)->qi() > 0) {
      continue;
    }
    if (!((*c)->nature() & (_nature))) {
      continue;
    }
#endif
    firstEdge = (*c)->fedgeA();

#if 0
    if (firstEdge->invisibility() > 0) {
      continue;
    }
#endif

    line = new OrientedLineRep();
    if (_overloadFrsMaterial) {
      line->setFrsMaterial(_FrsMaterial);
    }

    // there might be chains containing a single element
    if (0 == (firstEdge)->nextEdge()) {
      line->setStyle(LineRep::LINES);
      // line->AddVertex((*c)->vertexA()->point3D());
      // line->AddVertex((*c)->vertexB()->point3D());
      AddVertexToLine(line, firstEdge->vertexA());
      AddVertexToLine(line, firstEdge->vertexB());
    }
    else {
      line->setStyle(LineRep::LINE_STRIP);

      // firstEdge = (*c);
      nextFEdge = firstEdge;
      currentEdge = firstEdge;
      do {
        // line->AddVertex(nextFEdge->vertexA()->point3D());
        AddVertexToLine(line, nextFEdge->vertexA());
        currentEdge = nextFEdge;
        nextFEdge = nextFEdge->nextEdge();
      } while ((nextFEdge != NULL) && (nextFEdge != firstEdge));
      // Add the last vertex
      // line->AddVertex(currentEdge->vertexB()->point3D());
      AddVertexToLine(line, currentEdge->vertexB());
    }

    line->setId((*c)->getId().getFirst());
    line->ComputeBBox();
    tshape->AddRep(line);
    id++;
  }

  return group;
}

} /* namespace Freestyle */