Blender V5.0
Curve.h
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
11
12#include <deque>
13
14#include "../geometry/Geom.h"
15
16// #include "../scene_graph/FrsMaterial.h"
17
22
24
25#include "MEM_guardedalloc.h"
26
27using namespace std;
28
29namespace Freestyle {
30
31using namespace Geometry;
32
33/**********************************/
34/* */
35/* */
36/* CurvePoint */
37/* */
38/* */
39/**********************************/
40
48class 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 }
143 }
144
147 {
148 if (_t2d == 0) {
149 return __A->castToViewVertex();
150 }
151 else if (_t2d == 1) {
152 return __B->castToViewVertex();
153 }
155 }
156
159 {
160 if (_t2d == 0) {
161 return __A->castToNonTVertex();
162 }
163 else if (_t2d == 1) {
164 return __B->castToNonTVertex();
165 }
167 }
168
171 {
172 if (_t2d == 0) {
173 return __A->castToTVertex();
174 }
175 else if (_t2d == 1) {
176 return __B->castToTVertex();
177 }
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
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 uint 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 MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:CurvePoint")
336};
337
338/**********************************/
339/* */
340/* */
341/* Curve */
342/* */
343/* */
344/**********************************/
345
346namespace CurveInternal {
347
350template<class Traits> class __point_iterator;
352
353} // end of namespace CurveInternal
354
359class Curve : public Interface1D {
360 public:
365 typedef deque<Vertex *> vertex_container;
366
367 /* Iterator to iterate over a vertex edges */
368
375
376 protected:
378 double _Length;
380 uint _nSegments; // number of segments
381
382 public:
385 {
386 _Length = 0;
387 _Id = 0;
388 _nSegments = 0;
389 }
390
392 Curve(const Id &id)
393 {
394 _Length = 0;
395 _Id = id;
396 _nSegments = 0;
397 }
398
400 Curve(const Curve &iBrother)
401 {
402 _Length = iBrother._Length;
403 _Vertices = iBrother._Vertices;
404 _Id = iBrother._Id;
405 _nSegments = 0;
406 }
407
409 virtual ~Curve();
410
412 virtual string getExactTypeName() const
413 {
414 return "Curve";
415 }
416
417#if 0
418 /* fredo's curvature storage */
419 void computeCurvatureAndOrientation();
420#endif
421
423 inline void push_vertex_back(Vertex *iVertex)
424 {
425 if (!_Vertices.empty()) {
426 Vec3r vec_tmp(iVertex->point2d() - _Vertices.back()->point2d());
427 _Length += vec_tmp.norm();
428 ++_nSegments;
429 }
430 Vertex *new_vertex = new Vertex(*iVertex);
431 _Vertices.push_back(new_vertex);
432 }
433
435 inline void push_vertex_back(SVertex *iVertex)
436 {
437 if (!_Vertices.empty()) {
438 Vec3r vec_tmp(iVertex->point2d() - _Vertices.back()->point2d());
439 _Length += vec_tmp.norm();
440 ++_nSegments;
441 }
442 Vertex *new_vertex = new Vertex(iVertex, 0, 0);
443 _Vertices.push_back(new_vertex);
444 }
445
447 inline void push_vertex_front(Vertex *iVertex)
448 {
449 if (!_Vertices.empty()) {
450 Vec3r vec_tmp(iVertex->point2d() - _Vertices.front()->point2d());
451 _Length += vec_tmp.norm();
452 ++_nSegments;
453 }
454 Vertex *new_vertex = new Vertex(*iVertex);
455 _Vertices.push_front(new_vertex);
456 }
457
459 inline void push_vertex_front(SVertex *iVertex)
460 {
461 if (!_Vertices.empty()) {
462 Vec3r vec_tmp(iVertex->point2d() - _Vertices.front()->point2d());
463 _Length += vec_tmp.norm();
464 ++_nSegments;
465 }
466 Vertex *new_vertex = new Vertex(iVertex, 0, 0);
467 _Vertices.push_front(new_vertex);
468 }
469
471 inline bool empty() const
472 {
473 return _Vertices.empty();
474 }
475
477 inline real getLength2D() const
478 {
479 return _Length;
480 }
481
483 virtual Id getId() const
484 {
485 return _Id;
486 }
487
489 inline uint nSegments() const
490 {
491 return _nSegments;
492 }
493
494 inline void setId(const Id &id)
495 {
496 _Id = id;
497 }
498
499 /* Information access interface */
500
501#if 0
502 inline Vec3r shaded_color(int iCombination = 0) const;
503 inline Vec3r orientation2d(point_iterator it) const;
504 Vec3r orientation2d(int iCombination = 0) const;
505 Vec3r orientation3d(point_iterator it) const;
506 Vec3r orientation3d(int iCombination = 0) const;
507
508 real curvature2d(point_iterator it) const
509 {
510 return (*it)->curvature2d();
511 }
512
513 real curvature2d(int iCombination = 0) const;
514 FrsMaterial material() const;
515 int qi() const;
516 occluder_container::const_iterator occluders_begin() const;
517 occluder_container::const_iterator occluders_end() const;
518 int occluders_size() const;
519 bool occluders_empty() const;
520
521 const Polygon3r &occludee() const
522 {
523 return *(_FEdgeA->aFace());
524 }
525
526 const SShape *occluded_shape() const;
527 bool occludee_empty() const;
528 real z_discontinuity(int iCombination = 0) const;
529 int shape_id() const;
530 const SShape *shape() const;
531 float shape_importance(int iCombination = 0) const;
532 float local_average_depth(int iCombination = 0) const;
533 float local_depth_variance(int iCombination = 0) const;
534 real local_average_density(float sigma = 2.3f, int iCombination = 0) const;
535 Vec3r curvature2d_as_vector(int iCombination = 0) const;
537 real curvature2d_as_angle(int iCombination = 0) const;
538#endif
539
540 /* advanced iterators access */
542 const_point_iterator points_begin(float step = 0) const;
543 point_iterator points_end(float step = 0);
544 const_point_iterator points_end(float step = 0) const;
545
546 /* methods given for convenience */
551
552 // specialized iterators access
553 CurveInternal::CurvePointIterator curvePointsBegin(float t = 0.0f);
554 CurveInternal::CurvePointIterator curvePointsEnd(float t = 0.0f);
555
556 CurveInternal::CurvePointIterator curveVerticesBegin();
557 CurveInternal::CurvePointIterator curveVerticesEnd();
558
559 // Iterators access
563 virtual Interface0DIterator verticesBegin();
564
568 virtual Interface0DIterator verticesEnd();
569
574 virtual Interface0DIterator pointsBegin(float t = 0.0f);
575
580 virtual Interface0DIterator pointsEnd(float t = 0.0f);
581
582 MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:Curve")
583};
584
585} /* namespace Freestyle */
unsigned int uint
Classes defining the basic "Iterator" design pattern.
Vectors and Matrices (useful type definitions).
Interface to 0D elements.
Interface 1D and related tools definitions.
Read Guarded memory(de)allocation.
Class to perform all geometric operations dedicated to silhouette. That, for example,...
Classes to define a silhouette structure.
virtual FEdge * getFEdge(Interface0D &inter)
Definition Curve.cpp:195
void setB(SVertex *iB)
Definition Curve.h:267
void setT2d(float t)
Definition Curve.h:273
virtual real getZ() const
Definition Curve.h:70
int occluders_size() const
Definition Curve.cpp:384
real z_discontinuity() const
Definition Curve.cpp:428
virtual Id getId() const
Definition Curve.h:108
virtual real getProjectedZ() const
Definition Curve.h:94
virtual NonTVertex * castToNonTVertex()
Definition Curve.h:158
CurvePoint & operator=(const CurvePoint &iBrother)
Definition Curve.cpp:177
const Vec3r & point3d() const
Definition Curve.h:294
bool occluders_empty() const
Definition Curve.cpp:373
occluder_container::const_iterator occluders_begin() const
Definition Curve.cpp:351
virtual TVertex * castToTVertex()
Definition Curve.h:170
const SShape * occluded_shape() const
Definition Curve.cpp:395
float t2d() const
Definition Curve.h:247
virtual Nature::VertexNature getNature() const
Definition Curve.h:121
const Vec3r & point2d() const
Definition Curve.h:289
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
virtual real getProjectedY() const
Definition Curve.h:88
virtual ViewVertex * castToViewVertex()
Definition Curve.h:146
SVertex * A()
Definition Curve.h:235
Vec3r normal() const
Definition Curve.cpp:283
bool occludee_empty() const
Definition Curve.cpp:417
virtual ~CurvePoint()=default
virtual string getExactTypeName() const
Definition Curve.h:51
virtual Vec2r getPoint2D() const
Definition Curve.h:100
occluder_container::const_iterator occluders_end() const
Definition Curve.cpp:362
virtual SVertex * castToSVertex()
Definition Curve.h:134
SVertex * B()
Definition Curve.h:241
const Polygon3r & occludee() const
Definition Curve.cpp:406
const SShape * shape() const
Definition Curve.cpp:322
bool operator==(const CurvePoint &b)
Definition Curve.h:228
virtual real getY() const
Definition Curve.h:64
point_iterator vertices_end()
Definition Curve.cpp:628
uint nSegments() const
Definition Curve.h:489
void push_vertex_back(SVertex *iVertex)
Definition Curve.h:435
void push_vertex_back(Vertex *iVertex)
Definition Curve.h:423
vertex_container _Vertices
Definition Curve.h:377
CurveInternal::__point_iterator< CurveInternal::CurvePoint_nonconst_traits > point_iterator
Definition Curve.h:370
Vertex vertex_type
Definition Curve.h:364
virtual string getExactTypeName() const
Definition Curve.h:412
virtual Interface0DIterator verticesBegin()
Definition Curve.cpp:715
real getLength2D() const
Definition Curve.h:477
CurvePoint Vertex
Definition Curve.h:361
virtual Id getId() const
Definition Curve.h:483
Point point_type
Definition Curve.h:363
virtual Interface0DIterator verticesEnd()
Definition Curve.cpp:720
CurvePoint Point
Definition Curve.h:362
uint _nSegments
Definition Curve.h:380
point_iterator points_end(float step=0)
Definition Curve.cpp:590
deque< Vertex * > vertex_container
Definition Curve.h:365
CurveInternal::__point_iterator< CurveInternal::CurvePoint_const_traits > const_point_iterator
Definition Curve.h:372
virtual ~Curve()
Definition Curve.cpp:558
virtual Interface0DIterator pointsBegin(float t=0.0f)
Definition Curve.cpp:681
CurveInternal::CurvePointIterator curvePointsBegin(float t=0.0f)
Definition Curve.cpp:639
CurveInternal::CurvePointIterator curveVerticesBegin()
Definition Curve.cpp:671
bool empty() const
Definition Curve.h:471
void push_vertex_front(Vertex *iVertex)
Definition Curve.h:447
void setId(const Id &id)
Definition Curve.h:494
CurveInternal::CurvePointIterator curveVerticesEnd()
Definition Curve.cpp:676
Curve(const Curve &iBrother)
Definition Curve.h:400
void push_vertex_front(SVertex *iVertex)
Definition Curve.h:459
point_iterator vertex_iterator
Definition Curve.h:373
virtual Interface0DIterator pointsEnd(float t=0.0f)
Definition Curve.cpp:698
double _Length
Definition Curve.h:378
point_iterator vertices_begin()
Definition Curve.cpp:618
point_iterator points_begin(float step=0)
Definition Curve.cpp:572
const_point_iterator const_vertex_iterator
Definition Curve.h:374
CurveInternal::CurvePointIterator curvePointsEnd(float t=0.0f)
Definition Curve.cpp:655
Curve(const Id &id)
Definition Curve.h:392
virtual ViewVertex * castToViewVertex()
virtual NonTVertex * castToNonTVertex()
virtual TVertex * castToTVertex()
virtual SVertex * castToSVertex()
const Vec3r & point2d() const
Definition Silhouette.h:395
value_type norm() const
Definition VecMat.h:92
VecBase< float, D > step(VecOp< float, D >, VecOp< float, D >) RET
VecMat::Vec2< double > Vec2d
Definition Geom.h:23
VecMat::Vec2< real > Vec2r
Definition Geom.h:24
VecMat::Vec3< real > Vec3r
Definition Geom.h:30
ushort VertexNature
Definition Nature.h:22
static const VertexNature POINT
Definition Nature.h:24
inherits from class Rep
Definition AppCanvas.cpp:20
double real
Definition Precision.h:14