Blender V4.3
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
12#include <deque>
13
14#include "../geometry/Geom.h"
15
16// #include "../scene_graph/FrsMaterial.h"
17
22
24
25#ifdef WITH_CXX_GUARDEDALLOC
26# include "MEM_guardedalloc.h"
27#endif
28
29using namespace std;
30
31namespace Freestyle {
32
33using namespace Geometry;
34
35/**********************************/
36/* */
37/* */
38/* CurvePoint */
39/* */
40/* */
41/**********************************/
42
50class CurvePoint : public Interface0D {
51 public: // Implementation of Interface0D
53 virtual string getExactTypeName() const
54 {
55 return "CurvePoint";
56 }
57
58 // Data access methods
60 virtual real getX() const
61 {
62 return _Point3d.x();
63 }
64
66 virtual real getY() const
67 {
68 return _Point3d.y();
69 }
70
72 virtual real getZ() const
73 {
74 return _Point3d.z();
75 }
76
78 virtual Vec3r getPoint3D() const
79 {
80 return _Point3d;
81 }
82
84 virtual real getProjectedX() const
85 {
86 return _Point2d.x();
87 }
88
90 virtual real getProjectedY() const
91 {
92 return _Point2d.y();
93 }
94
96 virtual real getProjectedZ() const
97 {
98 return _Point2d.z();
99 }
100
102 virtual Vec2r getPoint2D() const
103 {
104 return Vec2r(_Point2d.x(), _Point2d.y());
105 }
106
107 virtual FEdge *getFEdge(Interface0D &inter);
108
110 virtual Id getId() const
111 {
112 Id id;
113 if (_t2d == 0) {
114 return __A->getId();
115 }
116 else if (_t2d == 1) {
117 return __B->getId();
118 }
119 return id;
120 }
121
124 {
126 if (_t2d == 0) {
127 nature |= __A->getNature();
128 }
129 else if (_t2d == 1) {
130 nature |= __B->getNature();
131 }
132 return nature;
133 }
134
137 {
138 if (_t2d == 0) {
139 return __A;
140 }
141 else if (_t2d == 1) {
142 return __B;
143 }
145 }
146
149 {
150 if (_t2d == 0) {
151 return __A->castToViewVertex();
152 }
153 else if (_t2d == 1) {
154 return __B->castToViewVertex();
155 }
157 }
158
161 {
162 if (_t2d == 0) {
163 return __A->castToNonTVertex();
164 }
165 else if (_t2d == 1) {
166 return __B->castToNonTVertex();
167 }
169 }
170
173 {
174 if (_t2d == 0) {
175 return __A->castToTVertex();
176 }
177 else if (_t2d == 1) {
178 return __B->castToTVertex();
179 }
181 }
182
183 public:
185
186 protected:
189 float _t2d;
190 // float _t3d;
193
194 public:
196 CurvePoint();
197
206 CurvePoint(SVertex *iA, SVertex *iB, float t);
207
216 CurvePoint(CurvePoint *iA, CurvePoint *iB, float t);
217
218 // CurvePoint(SVertex *iA, SVertex *iB, float t2d, float t3d);
219
221 CurvePoint(const CurvePoint &iBrother);
222
224 CurvePoint &operator=(const CurvePoint &iBrother);
225
227 virtual ~CurvePoint() = default;
228
231 {
232 return ((__A == b.__A) && (__B == b.__B) && (_t2d == b._t2d));
233 }
234
235 /* accessors */
237 inline SVertex *A()
238 {
239 return __A;
240 }
241
243 inline SVertex *B()
244 {
245 return __B;
246 }
247
249 inline float t2d() const
250 {
251 return _t2d;
252 }
253
254#if 0
255 inline const float t3d() const
256 {
257 return _t3d;
258 }
259#endif
260
261 /* modifiers */
263 inline void setA(SVertex *iA)
264 {
265 __A = iA;
266 }
267
269 inline void setB(SVertex *iB)
270 {
271 __B = iB;
272 }
273
275 inline void setT2d(float t)
276 {
277 _t2d = t;
278 }
279
280#if 0
281 inline void SetT3d(float t)
282 {
283 _t3d = t;
284 }
285#endif
286
287 /* Information access interface */
288
289 FEdge *fedge();
290
291 inline const Vec3r &point2d() const
292 {
293 return _Point2d;
294 }
295
296 inline const Vec3r &point3d() const
297 {
298 return _Point3d;
299 }
300
301 Vec3r normal() const;
302 // FrsMaterial material() const;
303 // Id shape_id() const;
304 const SShape *shape() const;
305 // float shape_importance() const;
306
307 // const uint qi() const;
308 occluder_container::const_iterator occluders_begin() const;
309 occluder_container::const_iterator occluders_end() const;
310 bool occluders_empty() const;
311 int occluders_size() const;
312 const Polygon3r &occludee() const;
313 const SShape *occluded_shape() const;
314 bool occludee_empty() const;
315 real z_discontinuity() const;
316#if 0
317 float local_average_depth() const;
318 float local_depth_variance() const;
319 real local_average_density(float sigma = 2.3f) const;
320 Vec3r shaded_color() const;
321 Vec3r orientation2d() const;
322 Vec3r orientation3d() const;
323
324 real curvature2d() const
325 {
326 return viewedge()->curvature2d((_VertexA->point2d() + _VertexB->point2d()) / 2.0);
327 }
328
329 Vec3r curvature2d_as_vector() const;
331 real curvature2d_as_angle() const;
332
333 real curvatureFredo() const;
334 Vec2d directionFredo() const;
335#endif
336
337#ifdef WITH_CXX_GUARDEDALLOC
338 MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:CurvePoint")
339#endif
340};
341
342/**********************************/
343/* */
344/* */
345/* Curve */
346/* */
347/* */
348/**********************************/
349
350namespace CurveInternal {
351
354template<class Traits> class __point_iterator;
356
357} // end of namespace CurveInternal
358
363class Curve : public Interface1D {
364 public:
369 typedef deque<Vertex *> vertex_container;
370
371 /* Iterator to iterate over a vertex edges */
372
379
380 protected:
382 double _Length;
384 uint _nSegments; // number of segments
385
386 public:
389 {
390 _Length = 0;
391 _Id = 0;
392 _nSegments = 0;
393 }
394
396 Curve(const Id &id)
397 {
398 _Length = 0;
399 _Id = id;
400 _nSegments = 0;
401 }
402
404 Curve(const Curve &iBrother)
405 {
406 _Length = iBrother._Length;
407 _Vertices = iBrother._Vertices;
408 _Id = iBrother._Id;
409 _nSegments = 0;
410 }
411
413 virtual ~Curve();
414
416 virtual string getExactTypeName() const
417 {
418 return "Curve";
419 }
420
421#if 0
422 /* fredo's curvature storage */
423 void computeCurvatureAndOrientation();
424#endif
425
427 inline void push_vertex_back(Vertex *iVertex)
428 {
429 if (!_Vertices.empty()) {
430 Vec3r vec_tmp(iVertex->point2d() - _Vertices.back()->point2d());
431 _Length += vec_tmp.norm();
432 ++_nSegments;
433 }
434 Vertex *new_vertex = new Vertex(*iVertex);
435 _Vertices.push_back(new_vertex);
436 }
437
439 inline void push_vertex_back(SVertex *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, 0, 0);
447 _Vertices.push_back(new_vertex);
448 }
449
451 inline void push_vertex_front(Vertex *iVertex)
452 {
453 if (!_Vertices.empty()) {
454 Vec3r vec_tmp(iVertex->point2d() - _Vertices.front()->point2d());
455 _Length += vec_tmp.norm();
456 ++_nSegments;
457 }
458 Vertex *new_vertex = new Vertex(*iVertex);
459 _Vertices.push_front(new_vertex);
460 }
461
463 inline void push_vertex_front(SVertex *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, 0, 0);
471 _Vertices.push_front(new_vertex);
472 }
473
475 inline bool empty() const
476 {
477 return _Vertices.empty();
478 }
479
481 inline real getLength2D() const
482 {
483 return _Length;
484 }
485
487 virtual Id getId() const
488 {
489 return _Id;
490 }
491
493 inline uint nSegments() const
494 {
495 return _nSegments;
496 }
497
498 inline void setId(const Id &id)
499 {
500 _Id = id;
501 }
502
503 /* Information access interface */
504
505#if 0
506 inline Vec3r shaded_color(int iCombination = 0) const;
507 inline Vec3r orientation2d(point_iterator it) const;
508 Vec3r orientation2d(int iCombination = 0) const;
509 Vec3r orientation3d(point_iterator it) const;
510 Vec3r orientation3d(int iCombination = 0) const;
511
512 real curvature2d(point_iterator it) const
513 {
514 return (*it)->curvature2d();
515 }
516
517 real curvature2d(int iCombination = 0) const;
518 FrsMaterial material() const;
519 int qi() const;
520 occluder_container::const_iterator occluders_begin() const;
521 occluder_container::const_iterator occluders_end() const;
522 int occluders_size() const;
523 bool occluders_empty() const;
524
525 const Polygon3r &occludee() const
526 {
527 return *(_FEdgeA->aFace());
528 }
529
530 const SShape *occluded_shape() const;
531 bool occludee_empty() const;
532 real z_discontinuity(int iCombination = 0) const;
533 int shape_id() const;
534 const SShape *shape() const;
535 float shape_importance(int iCombination = 0) const;
536 float local_average_depth(int iCombination = 0) const;
537 float local_depth_variance(int iCombination = 0) const;
538 real local_average_density(float sigma = 2.3f, int iCombination = 0) const;
539 Vec3r curvature2d_as_vector(int iCombination = 0) const;
541 real curvature2d_as_angle(int iCombination = 0) const;
542#endif
543
544 /* advanced iterators access */
545 point_iterator points_begin(float step = 0);
546 const_point_iterator points_begin(float step = 0) const;
547 point_iterator points_end(float step = 0);
548 const_point_iterator points_end(float step = 0) const;
549
550 /* methods given for convenience */
555
556 // specialized iterators access
557 CurveInternal::CurvePointIterator curvePointsBegin(float t = 0.0f);
558 CurveInternal::CurvePointIterator curvePointsEnd(float t = 0.0f);
559
560 CurveInternal::CurvePointIterator curveVerticesBegin();
561 CurveInternal::CurvePointIterator curveVerticesEnd();
562
563 // Iterators access
567 virtual Interface0DIterator verticesBegin();
568
572 virtual Interface0DIterator verticesEnd();
573
578 virtual Interface0DIterator pointsBegin(float t = 0.0f);
579
584 virtual Interface0DIterator pointsEnd(float t = 0.0f);
585
586#ifdef WITH_CXX_GUARDEDALLOC
587 MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:Curve")
588#endif
589};
590
591} /* 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:269
void setT2d(float t)
Definition Curve.h:275
virtual real getZ() const
Definition Curve.h:72
int occluders_size() const
Definition Curve.cpp:384
real z_discontinuity() const
Definition Curve.cpp:428
virtual Id getId() const
Definition Curve.h:110
virtual real getProjectedZ() const
Definition Curve.h:96
virtual NonTVertex * castToNonTVertex()
Definition Curve.h:160
CurvePoint & operator=(const CurvePoint &iBrother)
Definition Curve.cpp:177
const Vec3r & point3d() const
Definition Curve.h:296
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:172
const SShape * occluded_shape() const
Definition Curve.cpp:395
float t2d() const
Definition Curve.h:249
virtual Nature::VertexNature getNature() const
Definition Curve.h:123
const Vec3r & point2d() const
Definition Curve.h:291
SVertex vertex_type
Definition Curve.h:184
virtual real getX() const
Definition Curve.h:60
virtual real getProjectedX() const
Definition Curve.h:84
virtual Vec3r getPoint3D() const
Definition Curve.h:78
void setA(SVertex *iA)
Definition Curve.h:263
virtual real getProjectedY() const
Definition Curve.h:90
virtual ViewVertex * castToViewVertex()
Definition Curve.h:148
SVertex * A()
Definition Curve.h:237
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:53
virtual Vec2r getPoint2D() const
Definition Curve.h:102
occluder_container::const_iterator occluders_end() const
Definition Curve.cpp:362
virtual SVertex * castToSVertex()
Definition Curve.h:136
SVertex * B()
Definition Curve.h:243
const Polygon3r & occludee() const
Definition Curve.cpp:406
const SShape * shape() const
Definition Curve.cpp:322
bool operator==(const CurvePoint &b)
Definition Curve.h:230
virtual real getY() const
Definition Curve.h:66
point_iterator vertices_end()
Definition Curve.cpp:627
uint nSegments() const
Definition Curve.h:493
void push_vertex_back(SVertex *iVertex)
Definition Curve.h:439
void push_vertex_back(Vertex *iVertex)
Definition Curve.h:427
vertex_container _Vertices
Definition Curve.h:381
CurveInternal::__point_iterator< CurveInternal::CurvePoint_nonconst_traits > point_iterator
Definition Curve.h:374
Vertex vertex_type
Definition Curve.h:368
virtual string getExactTypeName() const
Definition Curve.h:416
virtual Interface0DIterator verticesBegin()
Definition Curve.cpp:714
real getLength2D() const
Definition Curve.h:481
CurvePoint Vertex
Definition Curve.h:365
virtual Id getId() const
Definition Curve.h:487
Point point_type
Definition Curve.h:367
virtual Interface0DIterator verticesEnd()
Definition Curve.cpp:719
CurvePoint Point
Definition Curve.h:366
uint _nSegments
Definition Curve.h:384
point_iterator points_end(float step=0)
Definition Curve.cpp:589
deque< Vertex * > vertex_container
Definition Curve.h:369
CurveInternal::__point_iterator< CurveInternal::CurvePoint_const_traits > const_point_iterator
Definition Curve.h:376
virtual ~Curve()
Definition Curve.cpp:558
virtual Interface0DIterator pointsBegin(float t=0.0f)
Definition Curve.cpp:680
CurveInternal::CurvePointIterator curvePointsBegin(float t=0.0f)
Definition Curve.cpp:638
CurveInternal::CurvePointIterator curveVerticesBegin()
Definition Curve.cpp:670
bool empty() const
Definition Curve.h:475
void push_vertex_front(Vertex *iVertex)
Definition Curve.h:451
void setId(const Id &id)
Definition Curve.h:498
point_iterator points_begin(float step=0)
Definition Curve.cpp:571
CurveInternal::CurvePointIterator curveVerticesEnd()
Definition Curve.cpp:675
Curve(const Curve &iBrother)
Definition Curve.h:404
void push_vertex_front(SVertex *iVertex)
Definition Curve.h:463
point_iterator vertex_iterator
Definition Curve.h:377
virtual Interface0DIterator pointsEnd(float t=0.0f)
Definition Curve.cpp:697
double _Length
Definition Curve.h:382
point_iterator vertices_begin()
Definition Curve.cpp:617
const_point_iterator const_vertex_iterator
Definition Curve.h:378
CurveInternal::CurvePointIterator curvePointsEnd(float t=0.0f)
Definition Curve.cpp:654
Curve(const Id &id)
Definition Curve.h:396
virtual ViewVertex * castToViewVertex()
virtual NonTVertex * castToNonTVertex()
virtual TVertex * castToTVertex()
virtual SVertex * castToSVertex()
virtual ViewVertex * castToViewVertex()
virtual NonTVertex * castToNonTVertex()
virtual TVertex * castToTVertex()
const Vec3r & point2d() const
Definition Silhouette.h:397
virtual Nature::VertexNature getNature() const
virtual Id getId() const
Definition Silhouette.h:119
value_type x() const
Definition VecMat.h:493
value_type z() const
Definition VecMat.h:513
value_type y() const
Definition VecMat.h:503
value_type norm() const
Definition VecMat.h:94
local_group_size(16, 16) .push_constant(Type b
Material material
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