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

ViewEdgeXBuilder.h « view_map « intern « freestyle « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6483b53478809b8c9701a34f2200bbb39a87b84b (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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
/* SPDX-License-Identifier: GPL-2.0-or-later */

#pragma once

/** \file
 * \ingroup freestyle
 * \brief Class to build view edges and the underlying chains of feature edges...
 */

#include <map>
#include <utility>
#include <vector>

#if 0  // soc
#  if defined(__GNUC__) && (__GNUC__ >= 3)
/* hash_map is not part of the C++ standard anymore;
 * hash_map.h has been kept though for backward compatibility */
#    include <hash_map.h>
#  else
#    include <hash_map>
#  endif
#endif

#include "Interface1D.h"

#include "../geometry/Geom.h"

#include "../system/FreestyleConfig.h"

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

using namespace std;

namespace Freestyle {

using namespace Geometry;

class SVertex;

/** Defines a hash table used for searching the SVertex */
struct SVertexHasher {
#define _MUL 950706376UL
#define _MOD 2147483647UL
  inline size_t operator()(const Vec3r &p) const
  {
    size_t res = ((unsigned long)(p[0] * _MUL)) % _MOD;
    res = ((res + (unsigned long)(p[1]) * _MUL)) % _MOD;
    return ((res + (unsigned long)(p[2]) * _MUL)) % _MOD;
  }
#undef _MUL
#undef _MOD
};

// Key_compare predicate for hash_map. In particular, return false if equal.
struct epsilonEquals {
  bool operator()(const Vec3r &v1, const Vec3r &v2) const
  {
    real norm = (v1 - v2).norm();
    return (norm < 1.0e-06);
  }
};

// typedef hash_map<Vec3r, SVertex*, SVertexHasher, epsilonEquals> SVertexMap;
typedef map<Vec3r, SVertex *> SVertexMap;

class WXFaceLayer;

/** class to describe an oriented smooth edge */
class OWXFaceLayer {
 public:
  WXFaceLayer *fl;
  bool order;

  OWXFaceLayer()
  {
    fl = NULL;
    order = true;
  }

  OWXFaceLayer(WXFaceLayer *ifl, bool iOrder = true)
  {
    fl = ifl;
    order = iOrder;
  }

  OWXFaceLayer &operator=(const OWXFaceLayer &iBrother)
  {
    fl = iBrother.fl;
    order = iBrother.order;
    return *this;
  }

  bool operator==(const OWXFaceLayer &b)
  {
    return ((fl == b.fl) && (order == b.order));
  }

  bool operator!=(const OWXFaceLayer &b)
  {
    return !(*this == b);
  }

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

class WXEdge;

/** class to describe an oriented sharp edge */
class OWXEdge {
 public:
  WXEdge *e;
  bool order;

  OWXEdge()
  {
    e = NULL;
    order = true;
  }

  OWXEdge(WXEdge *ie, bool iOrder = true)
  {
    e = ie;
    order = iOrder;
  }

  OWXEdge &operator=(const OWXEdge &iBrother)
  {
    e = iBrother.e;
    order = iBrother.order;
    return *this;
  }

  bool operator==(const OWXEdge &b)
  {
    return ((e == b.e) && (order == b.order));
  }

  bool operator!=(const OWXEdge &b)
  {
    return !(*this == b);
  }

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

class WOEdge;
class WXEdge;
class WXShape;
class SVertex;
class FEdge;
class ViewVertex;
class ViewEdge;
class ViewShape;

class ViewEdgeXBuilder {
 protected:
  int _currentViewId;     // Id for view edges
  int _currentFId;        // Id for FEdges
  int _currentSVertexId;  // Id for SVertex

 public:
  inline ViewEdgeXBuilder()
  {
    _currentViewId = 1;
    _currentFId = 0;
    _currentSVertexId = 0;
  }

  virtual ~ViewEdgeXBuilder()
  {
  }

  /** Builds a view shape from a WXShape in which the feature edges are flagged
   *  Builds chains of feature edges (so ViewEdges) from a WXShape
   *    iWShape
   *      The Winged Edge structure in which all silhouette edges and vertices are flagged.
   *    oViewShape
   *      The Silhouette Shape in which the chains must be added.
   *    ioVEdges
   *      The list of new ViewEdges.
   *    ioVVertices
   *      THe new ViewVertices
   *    ioFEdges
   *      A list in which all new FEdges are added
   *    ioSVertices
   *      A list of SVertex where all created SVertex are added.
   */
  virtual void BuildViewEdges(WXShape *iWShape,
                              ViewShape *oVShape,
                              std::vector<ViewEdge *> &ioVEdges,
                              std::vector<ViewVertex *> &ioVVertices,
                              std::vector<FEdge *> &ioFEdges,
                              std::vector<SVertex *> &ioSVertices);

  /** Builds a smooth view edge, starting the face iFace. */
  ViewEdge *BuildSmoothViewEdge(const OWXFaceLayer &iFaceLayer);

  /** Makes a sharp viewedge. */
  ViewEdge *BuildSharpViewEdge(const OWXEdge &iWEdge);

 public:
  /** accessors */
  inline int currentViewId() const
  {
    return _currentViewId;
  }

  inline int currentFId() const
  {
    return _currentFId;
  }

  inline int currentSVertexId() const
  {
    return _currentSVertexId;
  }

  /** modifiers */
  inline void setCurrentViewId(int id)
  {
    _currentViewId = id;
  }

  inline void setCurrentFId(int id)
  {
    _currentFId = id;
  }

  inline void setCurrentSVertexId(int id)
  {
    _currentSVertexId = id;
  }

 protected:
  /** Init the view edges building */
  virtual void Init(ViewShape *oVShape);

  // SMOOTH //
  /** checks whether a face has already been processed or not */
  bool stopSmoothViewEdge(WXFaceLayer *iFaceLayer);
  OWXFaceLayer FindNextFaceLayer(const OWXFaceLayer &iFaceLayer);
  OWXFaceLayer FindPreviousFaceLayer(const OWXFaceLayer &iFaceLayer);
  FEdge *BuildSmoothFEdge(FEdge *feprevious, const OWXFaceLayer &ifl);

  // SHARP //
  /** checks whether a WEdge has already been processed or not */
  bool stopSharpViewEdge(WXEdge *iEdge);
  int retrieveFaceMarks(WXEdge *iEdge);
  OWXEdge FindNextWEdge(const OWXEdge &iEdge);
  OWXEdge FindPreviousWEdge(const OWXEdge &iEdge);
  FEdge *BuildSharpFEdge(FEdge *feprevious, const OWXEdge &iwe);

  // GENERAL //
  /** Instantiate a SVertex */
  SVertex *MakeSVertex(Vec3r &iPoint);
  /** Instantiate a SVertex if it hasn't been already created */
  SVertex *MakeSVertex(Vec3r &iPoint, bool shared);
  /** instantiate a ViewVertex from a SVertex, if it doesn't exist yet */
  ViewVertex *MakeViewVertex(SVertex *iSVertex);

  // oldtmp values
  // IdHashTable _hashtable;
  // VVIdHashTable _multivertexHashTable;
  SVertexMap _SVertexMap;
  SShape *_pCurrentSShape;
  ViewShape *_pCurrentVShape;

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

} /* namespace Freestyle */