Blender  V2.93
Curve.h
Go to the documentation of this file.
1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  */
16 
17 #pragma once
18 
24 #include <deque>
25 
26 #include "../geometry/Geom.h"
27 
28 //#include "../scene_graph/FrsMaterial.h"
29 
30 #include "../view_map/Interface0D.h"
31 #include "../view_map/Interface1D.h"
32 #include "../view_map/Silhouette.h"
33 #include "../view_map/SilhouetteGeomEngine.h"
34 
35 #include "../system/BaseIterator.h"
36 
37 #ifdef WITH_CXX_GUARDEDALLOC
38 # include "MEM_guardedalloc.h"
39 #endif
40 
41 using namespace std;
42 
43 namespace Freestyle {
44 
45 using namespace Geometry;
46 
47 /**********************************/
48 /* */
49 /* */
50 /* CurvePoint */
51 /* */
52 /* */
53 /**********************************/
54 
62 class CurvePoint : public Interface0D {
63  public: // Implementation of Interface0D
65  virtual string getExactTypeName() const
66  {
67  return "CurvePoint";
68  }
69 
70  // Data access methods
72  virtual real getX() const
73  {
74  return _Point3d.x();
75  }
76 
78  virtual real getY() const
79  {
80  return _Point3d.y();
81  }
82 
84  virtual real getZ() const
85  {
86  return _Point3d.z();
87  }
88 
90  virtual Vec3r getPoint3D() const
91  {
92  return _Point3d;
93  }
94 
96  virtual real getProjectedX() const
97  {
98  return _Point2d.x();
99  }
100 
102  virtual real getProjectedY() const
103  {
104  return _Point2d.y();
105  }
106 
108  virtual real getProjectedZ() const
109  {
110  return _Point2d.z();
111  }
112 
114  virtual Vec2r getPoint2D() const
115  {
116  return Vec2r(_Point2d.x(), _Point2d.y());
117  }
118 
119  virtual FEdge *getFEdge(Interface0D &inter);
120 
122  virtual Id getId() const
123  {
124  Id id;
125  if (_t2d == 0) {
126  return __A->getId();
127  }
128  else if (_t2d == 1) {
129  return __B->getId();
130  }
131  return id;
132  }
133 
136  {
138  if (_t2d == 0) {
139  nature |= __A->getNature();
140  }
141  else if (_t2d == 1) {
142  nature |= __B->getNature();
143  }
144  return nature;
145  }
146 
149  {
150  if (_t2d == 0) {
151  return __A;
152  }
153  else if (_t2d == 1) {
154  return __B;
155  }
156  return Interface0D::castToSVertex();
157  }
158 
161  {
162  if (_t2d == 0) {
163  return __A->castToViewVertex();
164  }
165  else if (_t2d == 1) {
166  return __B->castToViewVertex();
167  }
168  return Interface0D::castToViewVertex();
169  }
170 
173  {
174  if (_t2d == 0) {
175  return __A->castToNonTVertex();
176  }
177  else if (_t2d == 1) {
178  return __B->castToNonTVertex();
179  }
180  return Interface0D::castToNonTVertex();
181  }
182 
185  {
186  if (_t2d == 0) {
187  return __A->castToTVertex();
188  }
189  else if (_t2d == 1) {
190  return __B->castToTVertex();
191  }
192  return Interface0D::castToTVertex();
193  }
194 
195  public:
197 
198  protected:
201  float _t2d;
202  // float _t3d;
205 
206  public:
208  CurvePoint();
209 
218  CurvePoint(SVertex *iA, SVertex *iB, float t);
219 
228  CurvePoint(CurvePoint *iA, CurvePoint *iB, float t);
229 
230  // CurvePoint(SVertex *iA, SVertex *iB, float t2d, float t3d);
231 
233  CurvePoint(const CurvePoint &iBrother);
234 
236  CurvePoint &operator=(const CurvePoint &iBrother);
237 
239  virtual ~CurvePoint() = default;
240 
242  bool operator==(const CurvePoint &b)
243  {
244  return ((__A == b.__A) && (__B == b.__B) && (_t2d == b._t2d));
245  }
246 
247  /* accessors */
249  inline SVertex *A()
250  {
251  return __A;
252  }
253 
255  inline SVertex *B()
256  {
257  return __B;
258  }
259 
261  inline float t2d() const
262  {
263  return _t2d;
264  }
265 
266 #if 0
267  inline const float t3d() const
268  {
269  return _t3d;
270  }
271 #endif
272 
273  /* modifiers */
275  inline void setA(SVertex *iA)
276  {
277  __A = iA;
278  }
279 
281  inline void setB(SVertex *iB)
282  {
283  __B = iB;
284  }
285 
287  inline void setT2d(float t)
288  {
289  _t2d = t;
290  }
291 
292 #if 0
293  inline void SetT3d(float t)
294  {
295  _t3d = t;
296  }
297 #endif
298 
299  /* Information access interface */
300 
301  FEdge *fedge();
302 
303  inline const Vec3r &point2d() const
304  {
305  return _Point2d;
306  }
307 
308  inline const Vec3r &point3d() const
309  {
310  return _Point3d;
311  }
312 
313  Vec3r normal() const;
314  // FrsMaterial material() const;
315  // Id shape_id() const;
316  const SShape *shape() const;
317  // float shape_importance() const;
318 
319  // const unsigned qi() const;
320  occluder_container::const_iterator occluders_begin() const;
321  occluder_container::const_iterator occluders_end() const;
322  bool occluders_empty() const;
323  int occluders_size() const;
324  const Polygon3r &occludee() const;
325  const SShape *occluded_shape() const;
326  bool occludee_empty() const;
327  real z_discontinuity() const;
328 #if 0
329  float local_average_depth() const;
330  float local_depth_variance() const;
331  real local_average_density(float sigma = 2.3f) const;
332  Vec3r shaded_color() const;
333  Vec3r orientation2d() const;
334  Vec3r orientation3d() const;
335 
336  real curvature2d() const
337  {
338  return viewedge()->curvature2d((_VertexA->point2d() + _VertexB->point2d()) / 2.0);
339  }
340 
341  Vec3r curvature2d_as_vector() const;
343  real curvature2d_as_angle() const;
344 
345  real curvatureFredo() const;
346  Vec2d directionFredo() const;
347 #endif
348 
349 #ifdef WITH_CXX_GUARDEDALLOC
350  MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:CurvePoint")
351 #endif
352 };
353 
354 /**********************************/
355 /* */
356 /* */
357 /* Curve */
358 /* */
359 /* */
360 /**********************************/
361 
362 namespace CurveInternal {
363 
366 template<class Traits> class __point_iterator;
367 class CurvePointIterator;
368 
369 } // end of namespace CurveInternal
370 
375 class Curve : public Interface1D {
376  public:
378  typedef CurvePoint Point;
379  typedef Point point_type;
381  typedef deque<Vertex *> vertex_container;
382 
383  /* Iterator to iterate over a vertex edges */
384 
391 
392  protected:
394  double _Length;
396  unsigned _nSegments; // number of segments
397 
398  public:
401  {
402  _Length = 0;
403  _Id = 0;
404  _nSegments = 0;
405  }
406 
408  Curve(const Id &id)
409  {
410  _Length = 0;
411  _Id = id;
412  _nSegments = 0;
413  }
414 
416  Curve(const Curve &iBrother)
417  {
418  _Length = iBrother._Length;
419  _Vertices = iBrother._Vertices;
420  _Id = iBrother._Id;
421  _nSegments = 0;
422  }
423 
425  virtual ~Curve();
426 
428  virtual string getExactTypeName() const
429  {
430  return "Curve";
431  }
432 
433 #if 0
434  /* fredo's curvature storage */
435  void computeCurvatureAndOrientation();
436 #endif
437 
439  inline void push_vertex_back(Vertex *iVertex)
440  {
441  if (!_Vertices.empty()) {
442  Vec3r vec_tmp(iVertex->point2d() - _Vertices.back()->point2d());
443  _Length += vec_tmp.norm();
444  ++_nSegments;
445  }
446  Vertex *new_vertex = new Vertex(*iVertex);
447  _Vertices.push_back(new_vertex);
448  }
449 
451  inline void push_vertex_back(SVertex *iVertex)
452  {
453  if (!_Vertices.empty()) {
454  Vec3r vec_tmp(iVertex->point2d() - _Vertices.back()->point2d());
455  _Length += vec_tmp.norm();
456  ++_nSegments;
457  }
458  Vertex *new_vertex = new Vertex(iVertex, 0, 0);
459  _Vertices.push_back(new_vertex);
460  }
461 
463  inline void push_vertex_front(Vertex *iVertex)
464  {
465  if (!_Vertices.empty()) {
466  Vec3r vec_tmp(iVertex->point2d() - _Vertices.front()->point2d());
467  _Length += vec_tmp.norm();
468  ++_nSegments;
469  }
470  Vertex *new_vertex = new Vertex(*iVertex);
471  _Vertices.push_front(new_vertex);
472  }
473 
475  inline void push_vertex_front(SVertex *iVertex)
476  {
477  if (!_Vertices.empty()) {
478  Vec3r vec_tmp(iVertex->point2d() - _Vertices.front()->point2d());
479  _Length += vec_tmp.norm();
480  ++_nSegments;
481  }
482  Vertex *new_vertex = new Vertex(iVertex, 0, 0);
483  _Vertices.push_front(new_vertex);
484  }
485 
487  inline bool empty() const
488  {
489  return _Vertices.empty();
490  }
491 
493  inline real getLength2D() const
494  {
495  return _Length;
496  }
497 
499  virtual Id getId() const
500  {
501  return _Id;
502  }
503 
505  inline unsigned int nSegments() const
506  {
507  return _nSegments;
508  }
509 
510  inline void setId(const Id &id)
511  {
512  _Id = id;
513  }
514 
515  /* Information access interface */
516 
517 #if 0
518  inline Vec3r shaded_color(int iCombination = 0) const;
519  inline Vec3r orientation2d(point_iterator it) const;
520  Vec3r orientation2d(int iCombination = 0) const;
521  Vec3r orientation3d(point_iterator it) const;
522  Vec3r orientation3d(int iCombination = 0) const;
523 
524  real curvature2d(point_iterator it) const
525  {
526  return (*it)->curvature2d();
527  }
528 
529  real curvature2d(int iCombination = 0) const;
530  FrsMaterial material() const;
531  int qi() const;
532  occluder_container::const_iterator occluders_begin() const;
533  occluder_container::const_iterator occluders_end() const;
534  int occluders_size() const;
535  bool occluders_empty() const;
536 
537  const Polygon3r &occludee() const
538  {
539  return *(_FEdgeA->aFace());
540  }
541 
542  const SShape *occluded_shape() const;
543  const bool occludee_empty() const;
544  real z_discontinuity(int iCombination = 0) const;
545  int shape_id() const;
546  const SShape *shape() const;
547  float shape_importance(int iCombination = 0) const;
548  float local_average_depth(int iCombination = 0) const;
549  float local_depth_variance(int iCombination = 0) const;
550  real local_average_density(float sigma = 2.3f, int iCombination = 0) const;
551  Vec3r curvature2d_as_vector(int iCombination = 0) const;
553  real curvature2d_as_angle(int iCombination = 0) const;
554 #endif
555 
556  /* advanced iterators access */
557  point_iterator points_begin(float step = 0);
558  const_point_iterator points_begin(float step = 0) const;
559  point_iterator points_end(float step = 0);
560  const_point_iterator points_end(float step = 0) const;
561 
562  /* methods given for convenience */
563  point_iterator vertices_begin();
564  const_point_iterator vertices_begin() const;
565  point_iterator vertices_end();
566  const_point_iterator vertices_end() const;
567 
568  // specialized iterators access
569  CurveInternal::CurvePointIterator curvePointsBegin(float t = 0.0f);
570  CurveInternal::CurvePointIterator curvePointsEnd(float t = 0.0f);
571 
572  CurveInternal::CurvePointIterator curveVerticesBegin();
573  CurveInternal::CurvePointIterator curveVerticesEnd();
574 
575  // Iterators access
579  virtual Interface0DIterator verticesBegin();
580 
584  virtual Interface0DIterator verticesEnd();
585 
590  virtual Interface0DIterator pointsBegin(float t = 0.0f);
591 
596  virtual Interface0DIterator pointsEnd(float t = 0.0f);
597 
598 #ifdef WITH_CXX_GUARDEDALLOC
599  MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:Curve")
600 #endif
601 };
602 
603 } /* 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:200
const Vec3r & point2d() const
Definition: Curve.h:303
void setB(SVertex *iB)
Definition: Curve.h:281
void setT2d(float t)
Definition: Curve.h:287
virtual real getZ() const
Definition: Curve.h:84
virtual Id getId() const
Definition: Curve.h:122
virtual SVertex * castToSVertex()
Definition: Curve.h:148
virtual real getProjectedZ() const
Definition: Curve.h:108
virtual ViewVertex * castToViewVertex()
Definition: Curve.h:160
float t2d() const
Definition: Curve.h:261
SVertex * B()
Definition: Curve.h:255
virtual Nature::VertexNature getNature() const
Definition: Curve.h:135
SVertex vertex_type
Definition: Curve.h:196
virtual real getX() const
Definition: Curve.h:72
virtual real getProjectedX() const
Definition: Curve.h:96
virtual Vec3r getPoint3D() const
Definition: Curve.h:90
void setA(SVertex *iA)
Definition: Curve.h:275
SVertex * A()
Definition: Curve.h:249
virtual TVertex * castToTVertex()
Definition: Curve.h:184
SVertex * __A
Definition: Curve.h:199
virtual real getProjectedY() const
Definition: Curve.h:102
virtual ~CurvePoint()=default
virtual string getExactTypeName() const
Definition: Curve.h:65
virtual Vec2r getPoint2D() const
Definition: Curve.h:114
const Vec3r & point3d() const
Definition: Curve.h:308
bool operator==(const CurvePoint &b)
Definition: Curve.h:242
virtual NonTVertex * castToNonTVertex()
Definition: Curve.h:172
virtual real getY() const
Definition: Curve.h:78
unsigned int nSegments() const
Definition: Curve.h:505
void push_vertex_back(SVertex *iVertex)
Definition: Curve.h:451
void push_vertex_back(Vertex *iVertex)
Definition: Curve.h:439
vertex_container _Vertices
Definition: Curve.h:393
CurveInternal::__point_iterator< CurveInternal::CurvePoint_nonconst_traits > point_iterator
Definition: Curve.h:386
unsigned _nSegments
Definition: Curve.h:396
Vertex vertex_type
Definition: Curve.h:380
virtual string getExactTypeName() const
Definition: Curve.h:428
real getLength2D() const
Definition: Curve.h:493
CurvePoint Vertex
Definition: Curve.h:377
virtual Id getId() const
Definition: Curve.h:499
Point point_type
Definition: Curve.h:379
CurvePoint Point
Definition: Curve.h:378
deque< Vertex * > vertex_container
Definition: Curve.h:381
CurveInternal::__point_iterator< CurveInternal::CurvePoint_const_traits > const_point_iterator
Definition: Curve.h:388
bool empty() const
Definition: Curve.h:487
void push_vertex_front(Vertex *iVertex)
Definition: Curve.h:463
void setId(const Id &id)
Definition: Curve.h:510
Curve(const Curve &iBrother)
Definition: Curve.h:416
void push_vertex_front(SVertex *iVertex)
Definition: Curve.h:475
point_iterator vertex_iterator
Definition: Curve.h:389
double _Length
Definition: Curve.h:394
const_point_iterator const_vertex_iterator
Definition: Curve.h:390
Curve(const Id &id)
Definition: Curve.h:408
virtual ViewVertex * castToViewVertex()
virtual NonTVertex * castToNonTVertex()
Definition: ViewMap.h:751
const Vec3r & point2d() const
Definition: Silhouette.h:409
virtual TVertex * castToTVertex()
Definition: ViewMap.h:468
value_type norm() const
Definition: VecMat.h:109
Material material
IconTextureDrawCall normal
struct Vertex Vertex
FEdge * getFEdge(Interface0D &it1, Interface0D &it2)
Definition: Functions0D.cpp:32
VecMat::Vec2< double > Vec2d
Definition: Geom.h:35
VecMat::Vec2< real > Vec2r
Definition: Geom.h:36
VecMat::Vec3< real > Vec3r
Definition: Geom.h:42
unsigned short VertexNature
Definition: Nature.h:32
static const VertexNature POINT
Definition: Nature.h:34
inherits from class Rep
Definition: AppCanvas.cpp:32
double real
Definition: Precision.h:26