/Users/enrico/Ricerca/develop/PINS/pins-mechatronix/LibSources/submodules/Splines/src/Splines/SplineVec.hxx Source FileΒΆ

Splines: /Users/enrico/Ricerca/develop/PINS/pins-mechatronix/LibSources/submodules/Splines/src/Splines/SplineVec.hxx Source File
Splines
SplineVec.hxx
1/*--------------------------------------------------------------------------*\
2 | |
3 | Copyright (C) 2016 |
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
20/*\
21 | ____ _ _ __ __
22 | / ___| _ __ | (_)_ __ __\ \ / /__ ___
23 | \___ \| '_ \| | | '_ \ / _ \ \ / / _ \/ __|
24 | ___) | |_) | | | | | | __/\ V / __/ (__
25 | |____/| .__/|_|_|_| |_|\___| \_/ \___|\___|
26 | |_|
27\*/
28
29namespace Splines {
30
34 class SplineVec {
35
36 protected:
37
38 #ifndef DOXYGEN_SHOULD_SKIP_THIS
39
40 string const m_name;
41
42 Utils::Malloc<real_type> m_mem;
43 Utils::Malloc<real_type*> m_mem_p;
44
45 integer m_dim{0};
46 integer m_npts{0};
47 bool m_curve_is_closed{false};
48 bool m_curve_can_extend{true};
49
50 real_type * m_X{nullptr};
51 real_type ** m_Y{nullptr};
52 real_type ** m_Yp{nullptr};
53
54 #ifdef SPLINES_USE_THREADS
55 mutable std::mutex m_last_interval_mutex;
56 mutable std::map<std::thread::id,std::shared_ptr<integer>> m_last_interval;
57 #else
58 mutable integer m_last_interval;
59 #endif
60
61 void init_last_interval();
62 void allocate( integer dim, integer npts );
63 void compute_chords();
64
65 #endif
66
67 public:
68
69 SplineVec( SplineVec const & ) = delete;
70 SplineVec const & operator = ( SplineVec const & ) = delete;
71
76
82 SplineVec( string const & name = "SplineVec" );
83
87 virtual
88 ~SplineVec();
89
91
95 void search( std::pair<integer,real_type> & res ) const;
96
100 string const & name() const { return m_name; }
101
106
108 bool is_closed() const { return m_curve_is_closed; }
109
115 void make_closed() { m_curve_is_closed = true; }
116
122 void make_open() { m_curve_is_closed = false; }
123
127 bool can_extend() const { return m_curve_can_extend; }
128
134 void make_unbounded() { m_curve_can_extend = true; }
135
141 void make_buonded() { m_curve_can_extend = false; }
143
148
152 integer num_points() const { return m_npts; }
153
157 integer dimension() const { return m_dim; }
158
162 real_type const * x_nodes() const { return m_X; }
163
167 real_type x_node( integer npt ) const { return m_X[size_t(npt)]; }
168
172 real_type const * y_nodes( integer j ) const { return m_Y[size_t(j)]; }
173
178 y_node( integer npt, integer j ) const
179 { return m_Y[size_t(j)][size_t(npt)]; }
180
184 real_type x_min() const { return m_X[0]; }
185
189 real_type x_max() const { return m_X[size_t(m_npts-1)]; }
190
192
197
202 eval( real_type x, integer i ) const;
203
209 { return this->eval( x, i ); }
210
215 D( real_type x, integer i ) const;
216
222 { return this->D(x,i); }
223
228 DD( real_type x, integer i ) const;
229
235 { return this->DD(x,i); }
236
241 DDD( real_type x, integer i ) const;
242
248 { return this->DDD(x,i); }
249
254 DDDD( real_type x, integer i ) const;
255
261 { return this->DDDD(x,i); }
262
267 DDDDD( real_type x, integer i ) const;
268
274 { return this->DDDDD(x,i); }
275
277
282
287 void
288 eval(
289 real_type x,
290 real_type vals[],
291 integer inc
292 ) const;
293
298 void
299 eval_D(
300 real_type x,
301 real_type vals[],
302 integer inc
303 ) const;
304
309 void
310 eval_DD(
311 real_type x,
312 real_type vals[],
313 integer inc
314 ) const;
315
320 void
321 eval_DDD(
322 real_type x,
323 real_type vals[],
324 integer inc
325 ) const;
326
331 void
333 real_type x,
334 real_type vals[],
335 integer inc
336 ) const;
337
342 void
344 real_type x,
345 real_type vals[],
346 integer inc
347 ) const;
349
354
359 void eval( real_type x, vector<real_type> & vals ) const;
360
365 void eval_D( real_type x, vector<real_type> & vals ) const;
366
371 void eval_DD( real_type x, vector<real_type> & vals ) const;
372
377 void eval_DDD( real_type x, vector<real_type> & vals ) const;
378
383 void eval_DDDD( real_type x, vector<real_type> & vals ) const;
384
389 void eval_DDDDD( real_type x, vector<real_type> & vals ) const;
391
396
400 void
401 eval( real_type x, GenericContainer & vals ) const
402 { eval( x, vals.set_vec_real(m_dim) ); }
403
407 void
408 eval_D( real_type x, GenericContainer & vals ) const
409 { eval_D( x, vals.set_vec_real(m_dim) ); }
410
414 void
415 eval_DD( real_type x, GenericContainer & vals ) const
416 { eval_DD( x, vals.set_vec_real(m_dim) ); }
417
421 void
422 eval_DDD( real_type x, GenericContainer & vals ) const
423 { eval_DDD( x, vals.set_vec_real(m_dim) ); }
424
428 void
429 eval_DDDD( real_type x, GenericContainer & vals ) const
430 { eval_DDDD( x, vals.set_vec_real(m_dim) ); }
431
435 void
436 eval_DDDDD( real_type x, GenericContainer & vals ) const
437 { eval_DDDDD( x, vals.set_vec_real(m_dim) ); }
439
444
449 void
450 eval( vec_real_type const & x, GenericContainer & vals ) const;
451
456 void
457 eval_D( vec_real_type const & x, GenericContainer & vals ) const;
458
463 void
464 eval_DD( vec_real_type const & x, GenericContainer & vals ) const;
465
470 void
471 eval_DDD( vec_real_type const & x, GenericContainer & vals ) const;
472
477 void
478 eval_DDDD( vec_real_type const & x, GenericContainer & vals ) const;
479
484 void
485 eval_DDDDD( vec_real_type const & x, GenericContainer & vals ) const;
487
492
501 void
502 setup(
503 integer dim,
504 integer npts,
505 real_type const * Y[]
506 );
507
516 void
517 setup(
518 integer dim,
519 integer npts,
520 real_type const Y[],
521 integer ldY
522 );
523
527 void set_knots( real_type const X[] );
528
533
538
543
548 void catmull_rom();
549
553 void
554 build( GenericContainer const & gc )
555 { setup(gc); }
556
560 void setup( GenericContainer const & gc );
561
563
567 real_type curvature( real_type x ) const;
568
573
577 SplineType1D type() const { return SplineType1D::SPLINE_VEC; }
578
582 string info() const;
583
587 void
588 info( ostream_type & stream ) const
589 { stream << this->info() << '\n'; }
590
594 void
595 dump_table( ostream_type & s, integer num_points ) const;
596
597 #ifdef SPLINES_BACK_COMPATIBILITY
598 integer numPoints() const { return m_npts; }
599 real_type const * xNodes() const { return m_X; }
600 real_type xNode( integer npt ) const { return m_X[size_t(npt)]; }
601 real_type const * yNodes( integer j ) const { return m_Y[size_t(j)]; }
602 real_type yNode( integer npt, integer j ) const { return y_node(npt,j); }
603 real_type xMin() const { return m_X[0]; }
604 real_type xMax() const { return m_X[size_t(m_npts-1)]; }
605 void setKnots( real_type const X[] ) { this->set_knots( X ); }
606 void setKnotsChordLength() { this->set_knots_chord_length(); }
607 void setKnotsCentripetal() { this->set_knots_centripetal() }
608 void setKnotsFoley() { this->set_knots_foley(); }
609 void CatmullRom() { this->catmull_rom(); }
610 #endif
611
612 };
613
614}
615
616// EOF: SplineVec.hxx
Definition SplineVec.hxx:34
void catmull_rom()
Definition SplineVec.cc:276
real_type x_min() const
Definition SplineVec.hxx:184
real_type DD(real_type x, integer i) const
Definition SplineVec.cc:344
virtual ~SplineVec()
spline destructor
Definition SplineVec.cc:54
real_type x_max() const
Definition SplineVec.hxx:189
void eval_DDD(real_type x, GenericContainer &vals) const
Definition SplineVec.hxx:422
void eval_DDDD(real_type x, vector< real_type > &vals) const
void make_unbounded()
Definition SplineVec.hxx:134
real_type DDD(real_type x, integer i) const
Definition SplineVec.cc:359
void make_closed()
Definition SplineVec.hxx:115
real_type x_node(integer npt) const
Definition SplineVec.hxx:167
integer num_points() const
Definition SplineVec.hxx:152
void eval_DDDD(real_type x, GenericContainer &vals) const
Definition SplineVec.hxx:429
void eval_DDDD(vec_real_type const &x, GenericContainer &vals) const
real_type const * x_nodes() const
Definition SplineVec.hxx:162
void set_knots(real_type const X[])
Definition SplineVec.cc:202
bool can_extend() const
Definition SplineVec.hxx:127
void set_knots_centripetal()
Definition SplineVec.cc:262
real_type eval(real_type x, integer i) const
Definition SplineVec.cc:314
void eval_DDDDD(real_type x, vector< real_type > &vals) const
void eval_DDDDD(real_type x, real_type vals[], integer inc) const
real_type eval_D(real_type x, integer i) const
Definition SplineVec.hxx:221
void eval_DDDDD(real_type x, GenericContainer &vals) const
Definition SplineVec.hxx:436
void info(ostream_type &stream) const
Definition SplineVec.hxx:588
real_type operator()(real_type x, integer i) const
Definition SplineVec.hxx:208
string info() const
Definition SplineVec.cc:111
real_type const * y_nodes(integer j) const
Definition SplineVec.hxx:172
real_type curvature(real_type x) const
Definition SplineVec.cc:490
void eval_D(real_type x, GenericContainer &vals) const
Definition SplineVec.hxx:408
real_type DDDD(real_type x, integer i) const
void set_knots_chord_length()
Definition SplineVec.cc:246
void make_open()
Definition SplineVec.hxx:122
string const & name() const
Definition SplineVec.hxx:100
integer dimension() const
Definition SplineVec.hxx:157
void eval_DDDD(real_type x, real_type vals[], integer inc) const
real_type DDDDD(real_type x, integer i) const
real_type D(real_type x, integer i) const
Definition SplineVec.cc:329
void search(std::pair< integer, real_type > &res) const
Definition SplineVec.cc:62
void make_buonded()
Definition SplineVec.hxx:141
void build(GenericContainer const &gc)
Definition SplineVec.hxx:554
SplineType1D type() const
Definition SplineVec.hxx:577
bool is_closed() const
Definition SplineVec.hxx:108
real_type eval_DD(real_type x, integer i) const
Definition SplineVec.hxx:234
void eval_DD(real_type x, GenericContainer &vals) const
Definition SplineVec.hxx:415
real_type eval_DDD(real_type x, integer i) const
Definition SplineVec.hxx:247
void dump_table(ostream_type &s, integer num_points) const
Definition SplineVec.cc:118
real_type eval_DDDD(real_type x, integer i) const
Definition SplineVec.hxx:260
real_type curvature_D(real_type x) const
Definition SplineVec.cc:508
real_type eval_DDDDD(real_type x, integer i) const
Definition SplineVec.hxx:273
void eval(real_type x, GenericContainer &vals) const
Definition SplineVec.hxx:401
real_type y_node(integer npt, integer j) const
Definition SplineVec.hxx:178
void eval_DDDDD(vec_real_type const &x, GenericContainer &vals) const
void setup(integer dim, integer npts, real_type const *Y[])
Definition SplineVec.cc:174
Definition SplineAkima.cc:50
int integer
Signed integer type for splines.
Definition Splines.hh:58
enum class SplineType1D :integer { CONSTANT=0, LINEAR=1, CUBIC=2, AKIMA=3, BESSEL=4, PCHIP=5, QUINTIC=6, HERMITE=7, SPLINE_SET=8, SPLINE_VEC=9 } SplineType1D
Associate a number for each type of splines implemented.
Definition Splines.hh:71
double real_type
Floating point type for splines.
Definition Splines.hh:57