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