Blender  V3.3
Curve.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #pragma once
4 
10 #include <deque>
11 
12 #include "../geometry/Geom.h"
13 
14 //#include "../scene_graph/FrsMaterial.h"
15 
16 #include "../view_map/Interface0D.h"
17 #include "../view_map/Interface1D.h"
18 #include "../view_map/Silhouette.h"
19 #include "../view_map/SilhouetteGeomEngine.h"
20 
21 #include "../system/BaseIterator.h"
22 
23 #ifdef WITH_CXX_GUARDEDALLOC
24 # include "MEM_guardedalloc.h"
25 #endif
26 
27 using namespace std;
28 
29 namespace Freestyle {
30 
31 using namespace Geometry;
32 
33 /**********************************/
34 /* */
35 /* */
36 /* CurvePoint */
37 /* */
38 /* */
39 /**********************************/
40 
48 class CurvePoint : public Interface0D {
49  public: // Implementation of Interface0D
51  virtual string getExactTypeName() const
52  {
53  return "CurvePoint";
54  }
55 
56  // Data access methods
58  virtual real getX() const
59  {
60  return _Point3d.x();
61  }
62 
64  virtual real getY() const
65  {
66  return _Point3d.y();
67  }
68 
70  virtual real getZ() const
71  {
72  return _Point3d.z();
73  }
74 
76  virtual Vec3r getPoint3D() const
77  {
78  return _Point3d;
79  }
80 
82  virtual real getProjectedX() const
83  {
84  return _Point2d.x();
85  }
86 
88  virtual real getProjectedY() const
89  {
90  return _Point2d.y();
91  }
92 
94  virtual real getProjectedZ() const
95  {
96  return _Point2d.z();
97  }
98 
100  virtual Vec2r getPoint2D() const
101  {
102  return Vec2r(_Point2d.x(), _Point2d.y());
103  }
104 
105  virtual FEdge *getFEdge(Interface0D &inter);
106 
108  virtual Id getId() const
109  {
110  Id id;
111  if (_t2d == 0) {
112  return __A->getId();
113  }
114  else if (_t2d == 1) {
115  return __B->getId();
116  }
117  return id;
118  }
119 
122  {
124  if (_t2d == 0) {
125  nature |= __A->getNature();
126  }
127  else if (_t2d == 1) {
128  nature |= __B->getNature();
129  }
130  return nature;
131  }
132 
135  {
136  if (_t2d == 0) {
137  return __A;
138  }
139  else if (_t2d == 1) {
140  return __B;
141  }
142  return Interface0D::castToSVertex();
143  }
144 
147  {
148  if (_t2d == 0) {
149  return __A->castToViewVertex();
150  }
151  else if (_t2d == 1) {
152  return __B->castToViewVertex();
153  }
154  return Interface0D::castToViewVertex();
155  }
156 
159  {
160  if (_t2d == 0) {
161  return __A->castToNonTVertex();
162  }
163  else if (_t2d == 1) {
164  return __B->castToNonTVertex();
165  }
166  return Interface0D::castToNonTVertex();
167  }
168 
171  {
172  if (_t2d == 0) {
173  return __A->castToTVertex();
174  }
175  else if (_t2d == 1) {
176  return __B->castToTVertex();
177  }
178  return Interface0D::castToTVertex();
179  }
180 
181  public:
183 
184  protected:
187  float _t2d;
188  // float _t3d;
191 
192  public:
194  CurvePoint();
195 
204  CurvePoint(SVertex *iA, SVertex *iB, float t);
205 
214  CurvePoint(CurvePoint *iA, CurvePoint *iB, float t);
215 
216  // CurvePoint(SVertex *iA, SVertex *iB, float t2d, float t3d);
217 
219  CurvePoint(const CurvePoint &iBrother);
220 
222  CurvePoint &operator=(const CurvePoint &iBrother);
223 
225  virtual ~CurvePoint() = default;
226 
228  bool operator==(const CurvePoint &b)
229  {
230  return ((__A == b.__A) && (__B == b.__B) && (_t2d == b._t2d));
231  }
232 
233  /* accessors */
235  inline SVertex *A()
236  {
237  return __A;
238  }
239 
241  inline SVertex *B()
242  {
243  return __B;
244  }
245 
247  inline float t2d() const
248  {
249  return _t2d;
250  }
251 
252 #if 0
253  inline const float t3d() const
254  {
255  return _t3d;
256  }
257 #endif
258 
259  /* modifiers */
261  inline void setA(SVertex *iA)
262  {
263  __A = iA;
264  }
265 
267  inline void setB(SVertex *iB)
268  {
269  __B = iB;
270  }
271 
273  inline void setT2d(float t)
274  {
275  _t2d = t;
276  }
277 
278 #if 0
279  inline void SetT3d(float t)
280  {
281  _t3d = t;
282  }
283 #endif
284 
285  /* Information access interface */
286 
287  FEdge *fedge();
288 
289  inline const Vec3r &point2d() const
290  {
291  return _Point2d;
292  }
293 
294  inline const Vec3r &point3d() const
295  {
296  return _Point3d;
297  }
298 
299  Vec3r normal() const;
300  // FrsMaterial material() const;
301  // Id shape_id() const;
302  const SShape *shape() const;
303  // float shape_importance() const;
304 
305  // const unsigned qi() const;
306  occluder_container::const_iterator occluders_begin() const;
307  occluder_container::const_iterator occluders_end() const;
308  bool occluders_empty() const;
309  int occluders_size() const;
310  const Polygon3r &occludee() const;
311  const SShape *occluded_shape() const;
312  bool occludee_empty() const;
313  real z_discontinuity() const;
314 #if 0
315  float local_average_depth() const;
316  float local_depth_variance() const;
317  real local_average_density(float sigma = 2.3f) const;
318  Vec3r shaded_color() const;
319  Vec3r orientation2d() const;
320  Vec3r orientation3d() const;
321 
322  real curvature2d() const
323  {
324  return viewedge()->curvature2d((_VertexA->point2d() + _VertexB->point2d()) / 2.0);
325  }
326 
327  Vec3r curvature2d_as_vector() const;
329  real curvature2d_as_angle() const;
330 
331  real curvatureFredo() const;
332  Vec2d directionFredo() const;
333 #endif
334 
335 #ifdef WITH_CXX_GUARDEDALLOC
336  MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:CurvePoint")
337 #endif
338 };
339 
340 /**********************************/
341 /* */
342 /* */
343 /* Curve */
344 /* */
345 /* */
346 /**********************************/
347 
348 namespace CurveInternal {
349 
352 template<class Traits> class __point_iterator;
353 class CurvePointIterator;
354 
355 } // end of namespace CurveInternal
356 
361 class Curve : public Interface1D {
362  public:
364  typedef CurvePoint Point;
365  typedef Point point_type;
367  typedef deque<Vertex *> vertex_container;
368 
369  /* Iterator to iterate over a vertex edges */
370 
377 
378  protected:
380  double _Length;
382  unsigned _nSegments; // number of segments
383 
384  public:
387  {
388  _Length = 0;
389  _Id = 0;
390  _nSegments = 0;
391  }
392 
394  Curve(const Id &id)
395  {
396  _Length = 0;
397  _Id = id;
398  _nSegments = 0;
399  }
400 
402  Curve(const Curve &iBrother)
403  {
404  _Length = iBrother._Length;
405  _Vertices = iBrother._Vertices;
406  _Id = iBrother._Id;
407  _nSegments = 0;
408  }
409 
411  virtual ~Curve();
412 
414  virtual string getExactTypeName() const
415  {
416  return "Curve";
417  }
418 
419 #if 0
420  /* fredo's curvature storage */
421  void computeCurvatureAndOrientation();
422 #endif
423 
425  inline void push_vertex_back(Vertex *iVertex)
426  {
427  if (!_Vertices.empty()) {
428  Vec3r vec_tmp(iVertex->point2d() - _Vertices.back()->point2d());
429  _Length += vec_tmp.norm();
430  ++_nSegments;
431  }
432  Vertex *new_vertex = new Vertex(*iVertex);
433  _Vertices.push_back(new_vertex);
434  }
435 
437  inline void push_vertex_back(SVertex *iVertex)
438  {
439  if (!_Vertices.empty()) {
440  Vec3r vec_tmp(iVertex->point2d() - _Vertices.back()->point2d());
441  _Length += vec_tmp.norm();
442  ++_nSegments;
443  }
444  Vertex *new_vertex = new Vertex(iVertex, 0, 0);
445  _Vertices.push_back(new_vertex);
446  }
447 
449  inline void push_vertex_front(Vertex *iVertex)
450  {
451  if (!_Vertices.empty()) {
452  Vec3r vec_tmp(iVertex->point2d() - _Vertices.front()->point2d());
453  _Length += vec_tmp.norm();
454  ++_nSegments;
455  }
456  Vertex *new_vertex = new Vertex(*iVertex);
457  _Vertices.push_front(new_vertex);
458  }
459 
461  inline void push_vertex_front(SVertex *iVertex)
462  {
463  if (!_Vertices.empty()) {
464  Vec3r vec_tmp(iVertex->point2d() - _Vertices.front()->point2d());
465  _Length += vec_tmp.norm();
466  ++_nSegments;
467  }
468  Vertex *new_vertex = new Vertex(iVertex, 0, 0);
469  _Vertices.push_front(new_vertex);
470  }
471 
473  inline bool empty() const
474  {
475  return _Vertices.empty();
476  }
477 
479  inline real getLength2D() const
480  {
481  return _Length;
482  }
483 
485  virtual Id getId() const
486  {
487  return _Id;
488  }
489 
491  inline unsigned int nSegments() const
492  {
493  return _nSegments;
494  }
495 
496  inline void setId(const Id &id)
497  {
498  _Id = id;
499  }
500 
501  /* Information access interface */
502 
503 #if 0
504  inline Vec3r shaded_color(int iCombination = 0) const;
505  inline Vec3r orientation2d(point_iterator it) const;
506  Vec3r orientation2d(int iCombination = 0) const;
507  Vec3r orientation3d(point_iterator it) const;
508  Vec3r orientation3d(int iCombination = 0) const;
509 
510  real curvature2d(point_iterator it) const
511  {
512  return (*it)->curvature2d();
513  }
514 
515  real curvature2d(int iCombination = 0) const;
516  FrsMaterial material() const;
517  int qi() const;
518  occluder_container::const_iterator occluders_begin() const;
519  occluder_container::const_iterator occluders_end() const;
520  int occluders_size() const;
521  bool occluders_empty() const;
522 
523  const Polygon3r &occludee() const
524  {
525  return *(_FEdgeA->aFace());
526  }
527 
528  const SShape *occluded_shape() const;
529  bool occludee_empty() const;
530  real z_discontinuity(int iCombination = 0) const;
531  int shape_id() const;
532  const SShape *shape() const;
533  float shape_importance(int iCombination = 0) const;
534  float local_average_depth(int iCombination = 0) const;
535  float local_depth_variance(int iCombination = 0) const;
536  real local_average_density(float sigma = 2.3f, int iCombination = 0) const;
537  Vec3r curvature2d_as_vector(int iCombination = 0) const;
539  real curvature2d_as_angle(int iCombination = 0) const;
540 #endif
541 
542  /* advanced iterators access */
543  point_iterator points_begin(float step = 0);
544  const_point_iterator points_begin(float step = 0) const;
545  point_iterator points_end(float step = 0);
546  const_point_iterator points_end(float step = 0) const;
547 
548  /* methods given for convenience */
549  point_iterator vertices_begin();
550  const_point_iterator vertices_begin() const;
551  point_iterator vertices_end();
552  const_point_iterator vertices_end() const;
553 
554  // specialized iterators access
555  CurveInternal::CurvePointIterator curvePointsBegin(float t = 0.0f);
556  CurveInternal::CurvePointIterator curvePointsEnd(float t = 0.0f);
557 
558  CurveInternal::CurvePointIterator curveVerticesBegin();
559  CurveInternal::CurvePointIterator curveVerticesEnd();
560 
561  // Iterators access
565  virtual Interface0DIterator verticesBegin();
566 
570  virtual Interface0DIterator verticesEnd();
571 
576  virtual Interface0DIterator pointsBegin(float t = 0.0f);
577 
582  virtual Interface0DIterator pointsEnd(float t = 0.0f);
583 
584 #ifdef WITH_CXX_GUARDEDALLOC
585  MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:Curve")
586 #endif
587 };
588 
589 } /* namespace Freestyle */
_GL_VOID GLfloat value _GL_VOID_RET _GL_VOID const GLuint GLboolean *residences _GL_BOOL_RET _GL_VOID GLsizei GLfloat GLfloat GLfloat GLfloat const GLubyte *bitmap _GL_VOID_RET _GL_VOID GLenum const void *lists _GL_VOID_RET _GL_VOID const GLdouble *equation _GL_VOID_RET _GL_VOID GLdouble GLdouble blue _GL_VOID_RET _GL_VOID GLfloat GLfloat blue _GL_VOID_RET _GL_VOID GLint GLint blue _GL_VOID_RET _GL_VOID GLshort GLshort blue _GL_VOID_RET _GL_VOID GLubyte GLubyte blue _GL_VOID_RET _GL_VOID GLuint GLuint blue _GL_VOID_RET _GL_VOID GLushort GLushort blue _GL_VOID_RET _GL_VOID GLbyte GLbyte GLbyte alpha _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble alpha _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat alpha _GL_VOID_RET _GL_VOID GLint GLint GLint alpha _GL_VOID_RET _GL_VOID GLshort GLshort GLshort alpha _GL_VOID_RET _GL_VOID GLubyte GLubyte GLubyte alpha _GL_VOID_RET _GL_VOID GLuint GLuint GLuint alpha _GL_VOID_RET _GL_VOID GLushort GLushort GLushort alpha _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLint GLsizei GLsizei GLenum type _GL_VOID_RET _GL_VOID GLsizei GLenum GLenum const void *pixels _GL_VOID_RET _GL_VOID const void *pointer _GL_VOID_RET _GL_VOID GLdouble v _GL_VOID_RET _GL_VOID GLfloat v _GL_VOID_RET _GL_VOID GLint GLint i2 _GL_VOID_RET _GL_VOID GLint j _GL_VOID_RET _GL_VOID GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble GLdouble GLdouble zFar _GL_VOID_RET _GL_UINT GLdouble *equation _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLenum GLfloat *v _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLfloat *values _GL_VOID_RET _GL_VOID GLushort *values _GL_VOID_RET _GL_VOID GLenum GLfloat *params _GL_VOID_RET _GL_VOID GLenum GLdouble *params _GL_VOID_RET _GL_VOID GLenum GLint *params _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_BOOL GLfloat param _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLushort pattern _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLint GLdouble GLdouble GLint GLint const GLdouble *points _GL_VOID_RET _GL_VOID GLdouble GLdouble u2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLint GLdouble GLdouble v2 _GL_VOID_RET _GL_VOID GLenum GLfloat param _GL_VOID_RET _GL_VOID GLenum GLint param _GL_VOID_RET _GL_VOID GLenum mode _GL_VOID_RET _GL_VOID GLdouble GLdouble nz _GL_VOID_RET _GL_VOID GLfloat GLfloat nz _GL_VOID_RET _GL_VOID GLint GLint nz _GL_VOID_RET _GL_VOID GLshort GLshort nz _GL_VOID_RET _GL_VOID GLsizei const void *pointer _GL_VOID_RET _GL_VOID GLsizei const GLfloat *values _GL_VOID_RET _GL_VOID GLsizei const GLushort *values _GL_VOID_RET _GL_VOID GLint param _GL_VOID_RET _GL_VOID const GLuint const GLclampf *priorities _GL_VOID_RET _GL_VOID GLdouble y _GL_VOID_RET _GL_VOID GLfloat y _GL_VOID_RET _GL_VOID GLint y _GL_VOID_RET _GL_VOID GLshort y _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLfloat GLfloat z _GL_VOID_RET _GL_VOID GLint GLint z _GL_VOID_RET _GL_VOID GLshort GLshort z _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble w _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat w _GL_VOID_RET _GL_VOID GLint GLint GLint w _GL_VOID_RET _GL_VOID GLshort GLshort GLshort w _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble y2 _GL_VOID_RET _GL_VOID GLfloat GLfloat GLfloat y2 _GL_VOID_RET _GL_VOID GLint GLint GLint y2 _GL_VOID_RET _GL_VOID GLshort GLshort GLshort y2 _GL_VOID_RET _GL_VOID GLdouble GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLdouble GLdouble z _GL_VOID_RET _GL_VOID GLuint *buffer _GL_VOID_RET _GL_VOID GLdouble t _GL_VOID_RET _GL_VOID GLfloat t _GL_VOID_RET _GL_VOID GLint t _GL_VOID_RET _GL_VOID GLshort t _GL_VOID_RET _GL_VOID GLdouble t
Read Guarded memory(de)allocation.
btGeneric6DofConstraint & operator=(btGeneric6DofConstraint &other)
SVertex * __B
Definition: Curve.h:186
const Vec3r & point2d() const
Definition: Curve.h:289
void setB(SVertex *iB)
Definition: Curve.h:267
void setT2d(float t)
Definition: Curve.h:273
virtual real getZ() const
Definition: Curve.h:70
virtual Id getId() const
Definition: Curve.h:108
virtual SVertex * castToSVertex()
Definition: Curve.h:134
virtual real getProjectedZ() const
Definition: Curve.h:94
virtual ViewVertex * castToViewVertex()
Definition: Curve.h:146
float t2d() const
Definition: Curve.h:247
SVertex * B()
Definition: Curve.h:241
virtual Nature::VertexNature getNature() const
Definition: Curve.h:121
SVertex vertex_type
Definition: Curve.h:182
virtual real getX() const
Definition: Curve.h:58
virtual real getProjectedX() const
Definition: Curve.h:82
virtual Vec3r getPoint3D() const
Definition: Curve.h:76
void setA(SVertex *iA)
Definition: Curve.h:261
SVertex * A()
Definition: Curve.h:235
virtual TVertex * castToTVertex()
Definition: Curve.h:170
SVertex * __A
Definition: Curve.h:185
virtual real getProjectedY() const
Definition: Curve.h:88
virtual ~CurvePoint()=default
virtual string getExactTypeName() const
Definition: Curve.h:51
virtual Vec2r getPoint2D() const
Definition: Curve.h:100
const Vec3r & point3d() const
Definition: Curve.h:294
bool operator==(const CurvePoint &b)
Definition: Curve.h:228
virtual NonTVertex * castToNonTVertex()
Definition: Curve.h:158
virtual real getY() const
Definition: Curve.h:64
unsigned int nSegments() const
Definition: Curve.h:491
void push_vertex_back(SVertex *iVertex)
Definition: Curve.h:437
void push_vertex_back(Vertex *iVertex)
Definition: Curve.h:425
vertex_container _Vertices
Definition: Curve.h:379
CurveInternal::__point_iterator< CurveInternal::CurvePoint_nonconst_traits > point_iterator
Definition: Curve.h:372
unsigned _nSegments
Definition: Curve.h:382
Vertex vertex_type
Definition: Curve.h:366
virtual string getExactTypeName() const
Definition: Curve.h:414
real getLength2D() const
Definition: Curve.h:479
CurvePoint Vertex
Definition: Curve.h:363
virtual Id getId() const
Definition: Curve.h:485
Point point_type
Definition: Curve.h:365
CurvePoint Point
Definition: Curve.h:364
deque< Vertex * > vertex_container
Definition: Curve.h:367
CurveInternal::__point_iterator< CurveInternal::CurvePoint_const_traits > const_point_iterator
Definition: Curve.h:374
bool empty() const
Definition: Curve.h:473
void push_vertex_front(Vertex *iVertex)
Definition: Curve.h:449
void setId(const Id &id)
Definition: Curve.h:496
Curve(const Curve &iBrother)
Definition: Curve.h:402
void push_vertex_front(SVertex *iVertex)
Definition: Curve.h:461
point_iterator vertex_iterator
Definition: Curve.h:375
double _Length
Definition: Curve.h:380
const_point_iterator const_vertex_iterator
Definition: Curve.h:376
Curve(const Id &id)
Definition: Curve.h:394
virtual ViewVertex * castToViewVertex()
Definition: Interface0D.cpp:89
virtual NonTVertex * castToNonTVertex()
Definition: ViewMap.h:741
const Vec3r & point2d() const
Definition: Silhouette.h:395
virtual TVertex * castToTVertex()
Definition: ViewMap.h:454
value_type norm() const
Definition: VecMat.h:95
Material material
IconTextureDrawCall normal
struct Vertex Vertex
FEdge * getFEdge(Interface0D &it1, Interface0D &it2)
Definition: Functions0D.cpp:18
VecMat::Vec2< double > Vec2d
Definition: Geom.h:21
VecMat::Vec2< real > Vec2r
Definition: Geom.h:22
VecMat::Vec3< real > Vec3r
Definition: Geom.h:28
unsigned short VertexNature
Definition: Nature.h:18
static const VertexNature POINT
Definition: Nature.h:20
inherits from class Rep
Definition: AppCanvas.cpp:18
double real
Definition: Precision.h:12
static const pxr::TfToken b("b", pxr::TfToken::Immortal)