/Users/enrico/Ricerca/develop/PINS/pins-mechatronix/LibSources/submodules/Clothoids/src/Clothoids/PolyLine.hxx Source File

Clothoids: /Users/enrico/Ricerca/develop/PINS/pins-mechatronix/LibSources/submodules/Clothoids/src/Clothoids/PolyLine.hxx Source File
Clothoids
PolyLine.hxx
1/*--------------------------------------------------------------------------*\
2 | |
3 | Copyright (C) 2017 |
4 | |
5 | , __ , __ |
6 | /|/ \ /|/ \ |
7 | | __/ _ ,_ | __/ _ ,_ |
8 | | \|/ / | | | | \|/ / | | | |
9 | |(__/|__/ |_/ \_/|/|(__/|__/ |_/ \_/|/ |
10 | /| /| |
11 | \| \| |
12 | |
13 | Enrico Bertolazzi |
14 | Dipartimento di Ingegneria Industriale |
15 | Universita` degli Studi di Trento |
16 | email: enrico.bertolazzi@unitn.it |
17 | |
18\*--------------------------------------------------------------------------*/
19
23
24namespace G2lib {
25
26 /*\
27 | ____ _ _ _
28 | | _ \ ___ | |_ _| | (_)_ __ ___
29 | | |_) / _ \| | | | | | | | '_ \ / _ \
30 | | __/ (_) | | |_| | |___| | | | | __/
31 | |_| \___/|_|\__, |_____|_|_| |_|\___|
32 | |___/
33 \*/
34
35 class CircleArc;
36 class Biarc;
37 class BiarcList;
38 class ClothoidCurve;
39 class ClothoidList;
40
42 class PolyLine : public BaseCurve {
43 friend class ClothoidList;
44 friend class BiarcList;
45 private:
46 vector<LineSegment> m_polyline_list;
47 vector<real_type> m_s0;
48 real_type m_xe;
49 real_type m_ye;
50
51 #ifdef CLOTHOIDS_USE_THREADS
52 mutable Utils::BinarySearch<integer> m_last_interval;
53 #else
54 mutable integer m_last_interval{0};
55 #endif
56
57 mutable bool m_aabb_done{false};
58 mutable AABB_TREE m_aabb_tree;
59
60 #ifdef CLOTHOIDS_USE_THREADS
61 mutable std::mutex m_aabb_mutex;
62 #endif
63
64 void
65 reset_last_interval() {
66 #ifdef CLOTHOIDS_USE_THREADS
67 bool ok;
68 integer & last_interval = *m_last_interval.search( std::this_thread::get_id(), ok );
69 #else
70 integer & last_interval = m_last_interval;
71 #endif
72 last_interval = 0;
73 }
74
75 public:
76
77 PolyLine() = delete;
78
79 //explicit
80 PolyLine( string const & name ) : BaseCurve( name )
81 { this->reset_last_interval(); }
82
83 void setup( GenericContainer const & gc ) override;
84
85 void init();
86
87 void copy( PolyLine const & l );
88
89 //explicit
90 PolyLine( PolyLine const & PL ) : BaseCurve( PL.name() )
91 { this->reset_last_interval(); this->copy(PL); }
92
93 integer find_at_s( real_type & s ) const;
94
95 explicit PolyLine( LineSegment const & LS );
96 explicit PolyLine( CircleArc const & C, real_type tol );
97 explicit PolyLine( Biarc const & B, real_type tol );
98 explicit PolyLine( ClothoidCurve const & B, real_type tol );
99 explicit PolyLine( ClothoidList const & B, real_type tol );
100 explicit PolyLine( BaseCurve const * pC );
101
102 CurveType type() const override { return CurveType::POLYLINE; }
103
104 PolyLine const & operator = ( PolyLine const & s )
105 { this->copy(s); return *this; }
106
107 LineSegment const &
108 getSegment( integer n ) const;
109
110 integer
111 num_segments() const
112 { return integer(m_polyline_list.size()); }
113
114 integer
115 numPoints() const
116 { return integer(m_s0.size()); }
117
118 void polygon( real_type x[], real_type y[] ) const;
119 void init( real_type x0, real_type y0 );
120 void push_back( real_type x, real_type y );
121 void push_back( LineSegment const & C );
122 void push_back( CircleArc const & C, real_type tol );
123 void push_back( Biarc const & C, real_type tol );
124 void push_back( ClothoidCurve const & C, real_type tol );
125 void push_back( ClothoidList const & L, real_type tol );
126
127 void
128 build(
129 integer npts,
130 real_type const x[],
131 real_type const y[]
132 );
133
134 void build( LineSegment const & L );
135 void build( CircleArc const & C, real_type tol );
136 void build( Biarc const & B, real_type tol );
137 void build( ClothoidCurve const & C, real_type tol );
138 void build( ClothoidList const & CL, real_type tol );
139
140 void build( CircleArc const & C );
141 void build( ClothoidCurve const & );
142 void build( Biarc const & );
143 void build( BiarcList const & );
144 void build( PolyLine const & );
145 void build( ClothoidList const & );
146 void build( Dubins const & );
147 void build( Dubins3p const & );
148
149 void
150 bbox(
151 real_type & xmin,
152 real_type & ymin,
153 real_type & xmax,
154 real_type & ymax
155 ) const override;
156
157 void
158 bbox_ISO(
159 real_type /* offs */,
160 real_type & /* xmin */,
161 real_type & /* ymin */,
162 real_type & /* xmax */,
163 real_type & /* ymax */
164 ) const override;
165
166 /*\
167 | _ _ _____ _ _
168 | | |__| |_|_ _| _(_)__ _ _ _ __ _| |___
169 | | '_ \ '_ \| || '_| / _` | ' \/ _` | / -_)
170 | |_.__/_.__/|_||_| |_\__,_|_||_\__, |_\___|
171 | |___/
172 \*/
173
174 void
176 vector<Triangle2D> & tvec,
177 real_type max_angle = Utils::m_pi/6, // 30 degree
178 real_type max_size = 1e100,
179 integer icurve = 0
180 ) const override;
181
182 void
184 real_type offs,
185 vector<Triangle2D> & tvec,
186 real_type max_angle = Utils::m_pi/6, // 30 degree
187 real_type max_size = 1e100,
188 integer icurve = 0
189 ) const override;
190
191 void
193 real_type offs,
194 vector<Triangle2D> & tvec,
195 real_type max_angle = Utils::m_pi/6, // 30 degree
196 real_type max_size = 1e100,
197 integer icurve = 0
198 ) const override {
199 this->bb_triangles_ISO( -offs, tvec, max_angle, max_size, icurve );
200 }
201
203 length() const override
204 { return m_s0.back(); }
205
207 length_ISO( real_type ) const override;
208
210 x_begin() const override
211 { return m_polyline_list.front().x_begin(); }
212
214 y_begin() const override
215 { return m_polyline_list.front().y_begin(); }
216
218 x_end() const override
219 { return m_polyline_list.back().x_end(); }
220
222 y_end() const override
223 { return m_polyline_list.back().y_end(); }
224
226 X( real_type s ) const override {
227 integer idx = this->find_at_s( s );
228 real_type ss = m_s0[idx];
229 return m_polyline_list[size_t(idx)].X(s-ss);
230 }
231
233 X_D( real_type s ) const override {
234 integer idx = this->find_at_s( s );
235 return m_polyline_list.at(size_t(idx)).m_c0;
236 }
237
239 X_DD( real_type ) const override
240 { return 0; }
241
243 X_DDD( real_type ) const override
244 { return 0; }
245
247 Y( real_type s ) const override {
248 integer idx = this->find_at_s( s );
249 real_type ss = m_s0[idx];
250 return m_polyline_list[size_t(idx)].Y(s-ss);
251 }
252
254 Y_D( real_type s ) const override {
255 integer idx = this->find_at_s( s );
256 return m_polyline_list[size_t(idx)].m_s0;
257 }
258
260 Y_DD( real_type ) const override
261 { return 0; }
262
264 Y_DDD( real_type ) const override
265 { return 0; }
266
267 real_type theta ( real_type s ) const override;
268 real_type theta_D ( real_type s ) const override;
269 real_type theta_DD ( real_type s ) const override;
270 real_type theta_DDD( real_type s ) const override;
271
272 void
274 real_type s,
275 real_type & x,
276 real_type & y
277 ) const override {
278 integer idx = this->find_at_s( s );
279 real_type ss = m_s0[idx];
280 m_polyline_list[size_t(idx)].eval( s-ss, x, y );
281 }
282
283 void
285 real_type s,
286 real_type & x_D,
287 real_type & y_D
288 ) const override {
289 integer idx = this->find_at_s( s );
290 real_type ss = m_s0[idx];
291 m_polyline_list[size_t(idx)].eval_D( s-ss, x_D, y_D );
292 }
293
294 void
296 real_type,
297 real_type & x_DD,
298 real_type & y_DD
299 ) const override
300 { x_DD = y_DD = 0; }
301
302 void
304 real_type,
305 real_type & x_DDD,
306 real_type & y_DDD
307 ) const override
308 { x_DDD = y_DDD = 0; }
309
310 // ---
311
312 void
314 real_type s,
315 real_type offs,
316 real_type & x,
317 real_type & y
318 ) const override {
319 integer idx{ this->find_at_s( s ) };
320 real_type ss{ m_s0[idx] };
321 m_polyline_list[size_t(idx)].eval_ISO( s-ss, offs, x, y );
322 }
323
324 void
326 real_type s,
327 real_type offs,
328 real_type & x_D,
329 real_type & y_D
330 ) const override {
331 integer idx{ this->find_at_s( s ) };
332 real_type ss{ m_s0[idx] };
333 m_polyline_list[size_t(idx)].eval_ISO_D( s-ss, offs, x_D, y_D );
334 }
335
336 void
338 real_type,
339 real_type,
340 real_type & x_DD,
341 real_type & y_DD
342 ) const override
343 { x_DD = y_DD = 0; }
344
345 void
347 real_type,
348 real_type,
349 real_type & x_DDD,
350 real_type & y_DDD
351 ) const override
352 { x_DDD = y_DDD = 0; }
353
354 /*\
355 | _ __
356 | | |_ _ __ __ _ _ __ ___ / _| ___ _ __ _ __ ___
357 | | __| '__/ _` | '_ \/ __| |_ / _ \| '__| '_ ` _ \
358 | | |_| | | (_| | | | \__ \ _| (_) | | | | | | | |
359 | \__|_| \__,_|_| |_|___/_| \___/|_| |_| |_| |_|
360 \*/
361
362 void
364 for ( auto & il : m_polyline_list ) il.translate( tx, ty );
365 }
366
367 void
369 real_type angle,
370 real_type cx,
371 real_type cy
372 ) override {
373 for ( auto & il : m_polyline_list ) il.rotate( angle, cx, cy );
374 }
375
376 void reverse() override;
377
378 void scale( real_type sc ) override;
379
380 void change_origin( real_type newx0, real_type newy0 ) override;
381
382 void trim( real_type s_begin, real_type s_end ) override;
383
384 void trim( real_type s_begin, real_type s_end, PolyLine & newPL ) const;
385
398 integer
400 real_type x,
401 real_type y,
402 real_type & X,
403 real_type & Y,
404 real_type & S,
405 real_type & T,
406 real_type & DST
407 ) const override;
408
409 integer
411 real_type /* x */,
412 real_type /* y */,
413 real_type /* offs */,
414 real_type & /* X */,
415 real_type & /* Y */,
416 real_type & /* S */,
417 real_type & /* T */,
418 real_type & /* DST */
419 ) const override;
420
421 /*\
422 | _ _ _ _
423 | ___ ___ | | (_)___(_) ___ _ __
424 | / __/ _ \| | | / __| |/ _ \| '_ \
425 | | (_| (_) | | | \__ \ | (_) | | | |
426 | \___\___/|_|_|_|___/_|\___/|_| |_|
427 \*/
428
429 bool
430 collision( PolyLine const & C ) const;
431
432 bool
433 collision_ISO(
434 real_type offs,
435 PolyLine const & CL,
436 real_type offs_CL
437 ) const;
438
439 bool
440 collision( BaseCurve const * pC ) const override;
441
442 bool
443 collision_ISO(
444 real_type offs,
445 BaseCurve const * pC,
446 real_type offs_C
447 ) const override;
448
449 /*\
450 | _ _ _
451 | (_)_ __ | |_ ___ _ __ ___ ___ ___| |_
452 | | | '_ \| __/ _ \ '__/ __|/ _ \/ __| __|
453 | | | | | | || __/ | \__ \ __/ (__| |_
454 | |_|_| |_|\__\___|_| |___/\___|\___|\__|
455 \*/
456
464 void
465 intersect(
466 PolyLine const & pl,
467 vector<real_type> & ss0,
468 vector<real_type> & ss1
469 ) const;
470
477 void
478 intersect(
479 PolyLine const & pl,
480 IntersectList & ilist
481 ) const;
482
491 void
493 real_type offs,
494 PolyLine const & pl,
495 real_type offs_pl,
496 IntersectList & ilist
497 ) const;
498
499 void
500 intersect(
501 BaseCurve const * pC,
502 IntersectList & ilist
503 ) const override;
504
505 void
507 real_type offs,
508 BaseCurve const * pC,
509 real_type offs_LS,
510 IntersectList & ilist
511 ) const override;
512
513 string info() const;
514
515 void
516 info( ostream_type & stream ) const override
517 { stream << info(); }
518
519 friend
521 operator << ( ostream_type & stream, PolyLine const & P );
522
523 void
524 build_AABBtree() const;
525
526#ifdef CLOTHOIDS_BACK_COMPATIBILITY
527#include "PolyLine_compatibility.hxx"
528#endif
529
530 };
531
532}
533
Definition BaseCurve.hxx:192
virtual real_type tx(real_type s) const
virtual real_type ty(real_type s) const
Definition Biarc.hxx:39
Definition BiarcList.hxx:42
Definition Circle.hxx:37
Definition Clothoid.hxx:48
Definition ClothoidList.hxx:861
Definition Line.hxx:37
Class to manage a collection of straight segment.
Definition PolyLine.hxx:42
real_type length() const override
Definition PolyLine.hxx:203
real_type X_D(real_type s) const override
Definition PolyLine.hxx:233
real_type X_DD(real_type) const override
Definition PolyLine.hxx:239
void bb_triangles(vector< Triangle2D > &tvec, real_type max_angle=Utils::m_pi/6, real_type max_size=1e100, integer icurve=0) const override
Definition PolyLine.cc:294
real_type x_begin() const override
Definition PolyLine.hxx:210
real_type x_end() const override
Definition PolyLine.hxx:218
CurveType type() const override
Definition PolyLine.hxx:102
void eval_ISO(real_type s, real_type offs, real_type &x, real_type &y) const override
Definition PolyLine.hxx:313
void eval_DDD(real_type, real_type &x_DDD, real_type &y_DDD) const override
Definition PolyLine.hxx:303
void intersect_ISO(real_type offs, PolyLine const &pl, real_type offs_pl, IntersectList &ilist) const
Definition PolyLine.cc:961
void eval_ISO_DDD(real_type, real_type, real_type &x_DDD, real_type &y_DDD) const override
Definition PolyLine.hxx:346
void eval_ISO_DD(real_type, real_type, real_type &x_DD, real_type &y_DD) const override
Definition PolyLine.hxx:337
real_type X_DDD(real_type) const override
Definition PolyLine.hxx:243
void bbox(real_type &xmin, real_type &ymin, real_type &xmax, real_type &ymax) const override
Definition PolyLine.cc:238
friend ostream_type & operator<<(ostream_type &stream, PolyLine const &P)
Definition PolyLine.cc:989
void scale(real_type sc) override
Definition PolyLine.cc:357
void intersect(PolyLine const &pl, vector< real_type > &ss0, vector< real_type > &ss1) const
Definition PolyLine.cc:903
real_type Y_D(real_type s) const override
Definition PolyLine.hxx:254
void eval_DD(real_type, real_type &x_DD, real_type &y_DD) const override
Definition PolyLine.hxx:295
real_type Y_DDD(real_type) const override
Definition PolyLine.hxx:264
real_type theta_D(real_type s) const override
Definition PolyLine.cc:331
void translate(real_type tx, real_type ty) override
translate curve by
Definition PolyLine.hxx:363
real_type Y(real_type s) const override
Definition PolyLine.hxx:247
void eval(real_type s, real_type &x, real_type &y) const override
Definition PolyLine.hxx:273
real_type theta_DD(real_type s) const override
Definition PolyLine.cc:337
void bbox_ISO(real_type, real_type &, real_type &, real_type &, real_type &) const override
Definition PolyLine.cc:275
void rotate(real_type angle, real_type cx, real_type cy) override
Definition PolyLine.hxx:368
void trim(real_type s_begin, real_type s_end) override
Definition PolyLine.cc:406
void reverse() override
Definition PolyLine.cc:374
void change_origin(real_type newx0, real_type newy0) override
Definition PolyLine.cc:395
void info(ostream_type &stream) const override
Definition PolyLine.hxx:516
real_type Y_DD(real_type) const override
Definition PolyLine.hxx:260
real_type X(real_type s) const override
Definition PolyLine.hxx:226
integer closest_point_ISO(real_type x, real_type y, real_type &X, real_type &Y, real_type &S, real_type &T, real_type &DST) const override
Definition PolyLine.cc:767
real_type y_begin() const override
Definition PolyLine.hxx:214
real_type y_end() const override
Definition PolyLine.hxx:222
real_type length_ISO(real_type) const override
Definition PolyLine.cc:150
real_type theta_DDD(real_type s) const override
Definition PolyLine.cc:343
void eval_D(real_type s, real_type &x_D, real_type &y_D) const override
Definition PolyLine.hxx:284
void bb_triangles_SAE(real_type offs, vector< Triangle2D > &tvec, real_type max_angle=Utils::m_pi/6, real_type max_size=1e100, integer icurve=0) const override
Definition PolyLine.hxx:192
real_type theta(real_type s) const override
Definition PolyLine.cc:323
void bb_triangles_ISO(real_type offs, vector< Triangle2D > &tvec, real_type max_angle=Utils::m_pi/6, real_type max_size=1e100, integer icurve=0) const override
Definition PolyLine.cc:308
void eval_ISO_D(real_type s, real_type offs, real_type &x_D, real_type &y_D) const override
Definition PolyLine.hxx:325
Definition BBox.cc:42
Utils::AABBtree< real_type > AABB_TREE
AABB tree type
Definition Clothoids.hh:81
GC_namespace::GenericContainer GenericContainer
Generic container object.
Definition Clothoids.hh:84
std::basic_ostream< char > ostream_type
output streaming
Definition Clothoids.hh:78
std::vector< Ipair > IntersectList
Vector of pair of two real number.
Definition BaseCurve.hxx:36
enum class CurveType :integer { LINE, POLYLINE, CIRCLE, BIARC, BIARC_LIST, CLOTHOID, CLOTHOID_LIST, DUBINS, DUBINS3P } CurveType
Definition Clothoids.hh:89
double real_type
real type number
Definition Clothoids.hh:79
int integer
integer type number
Definition Clothoids.hh:80