Blender  V3.3
CurveAdvancedIterators.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #pragma once
4 
10 #include "CurveIterators.h"
11 #include "Stroke.h"
12 
13 namespace Freestyle {
14 
15 namespace CurveInternal {
16 
17 class CurvePoint_const_traits : public Const_traits<CurvePoint *> {
18  public:
19  typedef deque<CurvePoint *> vertex_container;
20  typedef vertex_container::const_iterator vertex_container_iterator;
22 };
23 
24 class CurvePoint_nonconst_traits : public Nonconst_traits<CurvePoint *> {
25  public:
26  typedef deque<CurvePoint *> vertex_container;
27  typedef vertex_container::iterator vertex_container_iterator;
29 };
30 
31 /**********************************/
32 /* */
33 /* */
34 /* CurvePoint Iterator */
35 /* */
36 /* */
37 /**********************************/
38 
42 template<class Traits>
43 class __point_iterator : public IteratorBase<Traits, BidirectionalIteratorTag_Traits> {
44  public:
46  typedef typename Traits::vertex_container_iterator vertex_container_iterator;
47  typedef typename Traits::vertex_type vertex_type;
48  typedef CurvePoint Point;
49  typedef Point point_type;
50 
53 
54 #if 0
55  typedef Vertex vertex_type;
56  typedef vertex_container_iterator vertex_iterator_type;
57  typedef CurvePoint<Vertex> Point;
58  typedef Point point_type;
59 #endif
61 #if 0
62 # if defined(__GNUC__) && (__GNUC__ < 3)
63  typedef bidirectional_iterator<CurvePoint<Vertex>, ptrdiff_t> bidirectional_point_iterator;
64 # else
66  bidirectional_point_iterator;
67 # endif
68 #endif
69  friend class Curve;
70 #if 0
71  friend class Curve::vertex_iterator;
73  friend class iterator;
74 #endif
75  // protected:
76  public:
78  float _step;
83  int _n;
84  int _currentn;
85  float _t;
86  mutable Point *_Point;
87 
88  public:
89  inline __point_iterator(float step = 0.0f) : parent_class()
90  {
91  _step = step;
92  _CurvilinearLength = 0.0f;
93  _t = 0.0f;
94  _Point = 0;
95  _n = 0;
96  _currentn = 0;
97  }
98 
99  inline __point_iterator(const iterator &iBrother) : parent_class()
100  {
101  __A = iBrother.__A;
102  __B = iBrother.__B;
103  _begin = iBrother._begin;
104  _end = iBrother._end;
106  _step = iBrother._step;
107  _t = iBrother._t;
108  if (iBrother._Point == 0) {
109  _Point = 0;
110  }
111  else {
112  _Point = new Point(*(iBrother._Point));
113  }
114  _n = iBrother._n;
115  _currentn = iBrother._currentn;
116  }
117 
118  inline __point_iterator(const const_iterator &iBrother) : parent_class()
119  {
120  __A = iBrother.__A;
121  __B = iBrother.__B;
122  _begin = iBrother._begin;
123  _end = iBrother._end;
125  _step = iBrother._step;
126  _t = iBrother._t;
127  if (iBrother._Point == 0) {
128  _Point = 0;
129  }
130  else {
131  _Point = new Point(*(iBrother._Point));
132  }
133  _n = iBrother._n;
134  _currentn = iBrother._currentn;
135  }
136 
137  inline Self &operator=(const Self &iBrother)
138  {
139  //((bidirectional_point_iterator*)this)->operator=(iBrother);
140  __A = iBrother.__A;
141  __B = iBrother.__B;
142  _begin = iBrother._begin;
143  _end = iBrother._end;
145  _step = iBrother._step;
146  _t = iBrother._t;
147  if (iBrother._Point == 0) {
148  _Point = 0;
149  }
150  else {
151  _Point = new Point(*(iBrother._Point));
152  }
153  _n = iBrother._n;
154  _currentn = iBrother._currentn;
155  return *this;
156  }
157 
159  {
160  if (_Point != 0) {
161  delete _Point;
162  }
163  }
164 
165  // protected: //FIXME
166  public:
171  int currentn,
172  int n,
173  float step,
174  float t = 0.0f,
175  float iCurvilinearLength = 0.0f)
176  : parent_class()
177  {
178  __A = iA;
179  __B = iB;
180  _begin = ibegin;
181  _end = iend;
182  _CurvilinearLength = iCurvilinearLength;
183  _step = step;
184  _t = t;
185  _Point = 0;
186  _n = n;
187  _currentn = currentn;
188  }
189 
190  public:
191  // operators
192  inline Self &operator++() // operator corresponding to ++i
193  {
194  increment();
195  return *this;
196  }
197 
198  /* Operator corresponding to i++, i.e. it returns the value *and then* increments.
199  * That’s why we store the value in a temp.
200  */
201  inline Self operator++(int)
202  {
203  Self tmp = *this;
204  increment();
205  return tmp;
206  }
207 
208  inline Self &operator--() // operator corresponding to --i
209  {
210  decrement();
211  return *this;
212  }
213 
214  inline Self operator--(int) // operator corresponding to i--
215  {
216  Self tmp = *this;
217  decrement();
218  return tmp;
219  }
220 
221  // comparibility
222  virtual bool operator!=(const Self &b) const
223  {
224  return ((__A != b.__A) || (__B != b.__B) || (_t != b._t));
225  }
226 
227  virtual bool operator==(const Self &b) const
228  {
229  return !(*this != b);
230  }
231 
232  // dereferencing
233  virtual typename Traits::reference operator*() const
234  {
235  if (_Point != 0) {
236  delete _Point;
237  _Point = 0;
238  }
239  if ((_currentn < 0) || (_currentn >= _n)) {
240  return _Point; // 0 in this case
241  }
242  return (_Point = new Point(*__A, *__B, _t));
243  }
244 
245  virtual typename Traits::pointer operator->() const
246  {
247  return &(operator*());
248  }
249 
250  virtual bool begin() const
251  {
252  if ((__A == _begin) && (_t < (float)M_EPSILON)) {
253  return true;
254  }
255  return false;
256  }
257 
258  virtual bool end() const
259  {
260  if ((__B == _end)) {
261  return true;
262  }
263  return false;
264  }
265 
266  protected:
267  virtual void increment()
268  {
269  if (_Point != 0) {
270  delete _Point;
271  _Point = 0;
272  }
273  if ((_currentn == _n - 1) && (_t == 1.0f)) {
274  // we're setting the iterator to end
275  ++__A;
276  ++__B;
277  ++_currentn;
278  _t = 0.0f;
279  return;
280  }
281 
282  if (0 == _step) { // means we iterate over initial vertices
283  Vec3r vec_tmp((*__B)->point2d() - (*__A)->point2d());
284  _CurvilinearLength += vec_tmp.norm();
285  if (_currentn == _n - 1) {
286  _t = 1.0f;
287  return;
288  }
289  ++__B;
290  ++__A;
291  ++_currentn;
292  return;
293  }
294 
295  // compute the new position:
296  Vec3r vec_tmp2((*__A)->point2d() - (*__B)->point2d());
297  float normAB = vec_tmp2.norm();
298 
299  if (normAB > M_EPSILON) {
301  _t = _t + _step / normAB;
302  }
303  else {
304  _t = 1.0f; // AB is a null segment, we're directly at its end
305  }
306  // if normAB ~= 0, we don't change these values
307  if (_t >= 1) {
308  _CurvilinearLength -= normAB * (_t - 1);
309  if (_currentn == _n - 1) {
310  _t = 1.0f;
311  }
312  else {
313  _t = 0.0f;
314  ++_currentn;
315  ++__A;
316  ++__B;
317  }
318  }
319  }
320 
321  virtual void decrement()
322  {
323  if (_Point != 0) {
324  delete _Point;
325  _Point = 0;
326  }
327 
328  if (_t == 0.0f) { // we're at the beginning of the edge
329  _t = 1.0f;
330  --_currentn;
331  --__A;
332  --__B;
333  if (_currentn == _n - 1) {
334  return;
335  }
336  }
337 
338  if (0 == _step) { // means we iterate over initial vertices
339  Vec3r vec_tmp((*__B)->point2d() - (*__A)->point2d());
340  _CurvilinearLength -= vec_tmp.norm();
341  _t = 0;
342  return;
343  }
344 
345  // compute the new position:
346  Vec3r vec_tmp2((*__A)->point2d() - (*__B)->point2d());
347  float normAB = vec_tmp2.norm();
348 
349  if (normAB > M_EPSILON) {
351  _t = _t - _step / normAB;
352  }
353  else {
354  _t = -1.0f; // We just need a negative value here
355  }
356 
357  // round value
358  if (fabs(_t) < (float)M_EPSILON) {
359  _t = 0.0f;
360  }
361  if (_t < 0) {
362  if (_currentn == 0) {
363  _CurvilinearLength = 0.0f;
364  }
365  else {
366  _CurvilinearLength += normAB * (-_t);
367  }
368  _t = 0.0f;
369  }
370  }
371 };
372 
373 } // end of namespace CurveInternal
374 
375 } /* namespace Freestyle */
Iterators used to iterate over the elements of the Curve.
_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
Classes to define a stroke.
vertex_container::const_iterator vertex_container_iterator
virtual bool operator!=(const Self &b) const
__point_iterator(const const_iterator &iBrother)
virtual bool operator==(const Self &b) const
__point_iterator< CurvePoint_const_traits > const_iterator
Traits::vertex_container_iterator vertex_container_iterator
__point_iterator< CurvePoint_nonconst_traits > iterator
virtual Traits::reference operator*() const
__point_iterator(vertex_container_iterator iA, vertex_container_iterator iB, vertex_container_iterator ibegin, vertex_container_iterator iend, int currentn, int n, float step, float t=0.0f, float iCurvilinearLength=0.0f)
IteratorBase< Traits, BidirectionalIteratorTag_Traits > parent_class
point_iterator vertex_iterator
Definition: Curve.h:375
value_type norm() const
Definition: VecMat.h:95
ccl_device_inline float2 fabs(const float2 &a)
Definition: math_float2.h:222
inherits from class Rep
Definition: AppCanvas.cpp:18
static const real M_EPSILON
Definition: Precision.h:15
static const pxr::TfToken b("b", pxr::TfToken::Immortal)