Blender V4.3
CurveIterators.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 "Curve.h"
13#include "Stroke.h"
14
15namespace Freestyle {
16
17namespace CurveInternal {
18
25 public:
26 friend class Freestyle::Curve;
27
28 public:
30 float _step;
31 Curve::vertex_container::iterator __A;
32 Curve::vertex_container::iterator __B;
33 Curve::vertex_container::iterator _begin;
34 Curve::vertex_container::iterator _end;
35 int _n;
37 float _t;
40
41 public:
42 inline CurvePointIterator(float step = 0.0f) : Interface0DIteratorNested()
43 {
44 _step = step;
45 _CurvilinearLength = 0.0f;
46 _t = 0.0f;
47 //_Point = 0;
48 _n = 0;
49 _currentn = 0;
50 _CurveLength = 0;
51 }
52
54 {
55 __A = iBrother.__A;
56 __B = iBrother.__B;
57 _begin = iBrother._begin;
58 _end = iBrother._end;
60 _step = iBrother._step;
61 _t = iBrother._t;
62 _Point = iBrother._Point;
63 _n = iBrother._n;
64 _currentn = iBrother._currentn;
65 _CurveLength = iBrother._CurveLength;
66 }
67
69 {
70 __A = iBrother.__A;
71 __B = iBrother.__B;
72 _begin = iBrother._begin;
73 _end = iBrother._end;
75 _step = iBrother._step;
76 _t = iBrother._t;
77 _Point = iBrother._Point;
78 _n = iBrother._n;
79 _currentn = iBrother._currentn;
80 _CurveLength = iBrother._CurveLength;
81 return *this;
82 }
83
85
86 protected:
87 inline CurvePointIterator(Curve::vertex_container::iterator iA,
88 Curve::vertex_container::iterator iB,
89 Curve::vertex_container::iterator ibegin,
90 Curve::vertex_container::iterator iend,
91 int currentn,
92 int n,
93 float iCurveLength,
94 float step,
95 float t = 0.0f,
96 float iCurvilinearLength = 0.0f)
98 {
99 __A = iA;
100 __B = iB;
101 _begin = ibegin;
102 _end = iend;
103 _CurvilinearLength = iCurvilinearLength;
104 _step = step;
105 _t = t;
106 _n = n;
107 _currentn = currentn;
108 _CurveLength = iCurveLength;
109 }
110
111 public:
112 virtual CurvePointIterator *copy() const
113 {
114 return new CurvePointIterator(*this);
115 }
116
122
123 virtual string getExactTypeName() const
124 {
125 return "CurvePointIterator";
126 }
127
128 // operators
129 inline CurvePointIterator &operator++() // operator corresponding to ++i
130 {
131 increment();
132 return *this;
133 }
134
135 inline CurvePointIterator &operator--() // operator corresponding to --i
136 {
137 decrement();
138 return *this;
139 }
140
141 // comparibility
142 virtual bool operator==(const Interface0DIteratorNested &b) const
143 {
144 const CurvePointIterator *it_exact = dynamic_cast<const CurvePointIterator *>(&b);
145 if (!it_exact) {
146 return false;
147 }
148 return ((__A == it_exact->__A) && (__B == it_exact->__B) && (_t == it_exact->_t));
149 }
150
151 // dereferencing
153 {
154 return (_Point = CurvePoint(*__A, *__B, _t));
155 }
156
158 {
159 return &(operator*());
160 }
161
162 virtual bool isBegin() const
163 {
164 if ((__A == _begin) && (_t < (float)M_EPSILON)) {
165 return true;
166 }
167 return false;
168 }
169
170 virtual bool isEnd() const
171 {
172 if (__B == _end) {
173 return true;
174 }
175 return false;
176 }
177
178 // protected:
179 virtual int increment()
180 {
181 if ((_currentn == _n - 1) && (_t == 1.0f)) {
182 // we're setting the iterator to end
183 ++__A;
184 ++__B;
185 ++_currentn;
186 _t = 0.0f;
187 return 0;
188 }
189
190 if (0 == _step) { // means we iterate over initial vertices
191 Vec3r vec_tmp((*__B)->point2d() - (*__A)->point2d());
192 _CurvilinearLength += (float)vec_tmp.norm();
193 if (_currentn == _n - 1) {
194 _t = 1.0f;
195 return 0;
196 }
197 ++__B;
198 ++__A;
199 ++_currentn;
200 return 0;
201 }
202
203 // compute the new position:
204 Vec3r vec_tmp2((*__A)->point2d() - (*__B)->point2d());
205 float normAB = (float)vec_tmp2.norm();
206
207 if (normAB > M_EPSILON) {
209 _t = _t + _step / normAB;
210 }
211 else {
212 _t = 1.0f; // AB is a null segment, we're directly at its end
213 }
214 // if normAB ~= 0, we don't change these values
215 if (_t >= 1) {
216 _CurvilinearLength -= normAB * (_t - 1);
217 if (_currentn == _n - 1) {
218 _t = 1.0f;
219 }
220 else {
221 _t = 0.0f;
222 ++_currentn;
223 ++__A;
224 ++__B;
225 }
226 }
227 return 0;
228 }
229
230 virtual int decrement()
231 {
232 if (_t == 0.0f) { // we're at the beginning of the edge
233 _t = 1.0f;
234 --_currentn;
235 --__A;
236 --__B;
237 if (_currentn == _n - 1) {
238 return 0;
239 }
240 }
241
242 if (0 == _step) { // means we iterate over initial vertices
243 Vec3r vec_tmp((*__B)->point2d() - (*__A)->point2d());
244 _CurvilinearLength -= (float)vec_tmp.norm();
245 _t = 0;
246 return 0;
247 }
248
249 // compute the new position:
250 Vec3r vec_tmp2((*__A)->point2d() - (*__B)->point2d());
251 float normAB = (float)vec_tmp2.norm();
252
253 if (normAB > M_EPSILON) {
255 _t = _t - _step / normAB;
256 }
257 else {
258 _t = -1.0f; // We just need a negative value here
259 }
260
261 // round value
262 if (fabs(_t) < (float)M_EPSILON) {
263 _t = 0.0f;
264 }
265 if (_t < 0) {
266 if (_currentn == 0) {
267 _CurvilinearLength = 0.0f;
268 }
269 else {
270 _CurvilinearLength += normAB * (-_t);
271 }
272 _t = 0.0f;
273 }
274 return 0;
275 }
276
277 virtual float t() const
278 {
279 return _CurvilinearLength;
280 }
281
282 virtual float u() const
283 {
285 }
286};
287
288} // end of namespace CurveInternal
289
290} /* namespace Freestyle */
Class to define a container for curves.
Classes to define a stroke.
CurvePointIterator & operator=(const CurvePointIterator &iBrother)
Curve::vertex_container::iterator _begin
Curve::vertex_container::iterator _end
virtual bool operator==(const Interface0DIteratorNested &b) const
Curve::vertex_container::iterator __A
CurvePointIterator(const CurvePointIterator &iBrother)
virtual CurvePointIterator * copy() const
CurvePointIterator(Curve::vertex_container::iterator iA, Curve::vertex_container::iterator iB, Curve::vertex_container::iterator ibegin, Curve::vertex_container::iterator iend, int currentn, int n, float iCurveLength, float step, float t=0.0f, float iCurvilinearLength=0.0f)
Curve::vertex_container::iterator __B
Interface0DIterator castToInterface0DIterator() const
value_type norm() const
Definition VecMat.h:94
local_group_size(16, 16) .push_constant(Type b
draw_view in_light_buf[] float
ccl_device_inline float2 fabs(const float2 a)
inherits from class Rep
Definition AppCanvas.cpp:20
static const real M_EPSILON
Definition Precision.h:17
return ret