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

Splines: /Users/enrico/Ricerca/develop/PINS/pins-mechatronix/LibSources/submodules/Splines/src/Splines.hh Source File
Splines
Splines.hh
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#pragma once
21
22#ifndef SPLINES_HH
23#define SPLINES_HH
24
25#ifdef __GNUC__
26#pragma GCC diagnostic push
27#endif
28
29#ifdef __clang__
30#pragma clang diagnostic push
31#pragma clang diagnostic ignored "-Wc++98-compat"
32#pragma clang diagnostic ignored "-Wglobal-constructors"
33#pragma clang diagnostic ignored "-Wc++98-compat-pedantic"
34#pragma clang diagnostic ignored "-Wpoison-system-directories"
35#endif
36
37#include "SplinesConfig.hh"
38#include <fstream>
39
43namespace Splines {
44
45 using std::vector;
46 using std::string;
47 using std::exception;
48 using std::runtime_error;
49 using std::basic_ostream;
50 using std::basic_istream;
51 using std::lower_bound;
52 using std::pair;
53 using std::cout;
54 using std::cin;
55 using std::cerr;
56
57 typedef double real_type;
58 typedef int integer;
59
60 #ifndef DOXYGEN_SHOULD_SKIP_THIS
61 using Malloc_real = Utils::Malloc<real_type>;
62 using ostream_type = basic_ostream<char>;
63 using istream_type = basic_istream<char>;
64
65 void backtrace( ostream_type & );
66 #endif
67
68 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
69
71 using SplineType1D = enum class SplineType1D : integer {
72 CONSTANT = 0,
73 LINEAR = 1,
74 CUBIC = 2,
75 AKIMA = 3,
76 BESSEL = 4,
77 PCHIP = 5,
78 QUINTIC = 6,
79 HERMITE = 7,
80 SPLINE_SET = 8,
81 SPLINE_VEC = 9
82 };
83
84 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
85
87 using SplineType2D = enum class SplineType2D : integer {
88 BILINEAR = 0,
89 BICUBIC = 1,
90 BIQUINTIC = 2,
91 AKIMA2D = 3
92 };
93
94 #ifndef DOXYGEN_SHOULD_SKIP_THIS
95 extern SplineType1D string_to_splineType1D( string const & n );
96 extern SplineType2D string_to_splineType2D( string const & n );
97 extern char const * to_string( SplineType2D t );
98 extern char const * to_string( SplineType1D t );
99 #endif
100
101 using GC_namespace::GenericContainer;
102 using GC_namespace::vec_real_type;
103 using GC_namespace::vec_string_type;
104 using GC_namespace::vector_type;
105 using GC_namespace::map_type;
106
107 /*
108 // _ _ _ _
109 // | | | | ___ _ __ _ __ ___ (_) |_ ___
110 // | |_| |/ _ \ '__| '_ ` _ \| | __/ _ \
111 // | _ | __/ | | | | | | | | || __/
112 // |_| |_|\___|_| |_| |_| |_|_|\__\___|
113 */
114
115 #ifndef DOXYGEN_SHOULD_SKIP_THIS
116
117 void Hermite3( real_type x, real_type H, real_type base[4] );
118 void Hermite3_D( real_type x, real_type H, real_type base_D[4] );
119 void Hermite3_DD( real_type x, real_type H, real_type base_DD[4] );
120 void Hermite3_DDD( real_type x, real_type H, real_type base_DDD[4] );
121
122 void Hermite5( real_type x, real_type H, real_type base[6] );
123 void Hermite5_D( real_type x, real_type H, real_type base_D[6] );
124 void Hermite5_DD( real_type x, real_type H, real_type base_DD[6] );
125 void Hermite5_DDD( real_type x, real_type H, real_type base_DDD[6] );
126 void Hermite5_DDDD( real_type x, real_type H, real_type base_DDDD[6] );
127 void Hermite5_DDDDD( real_type x, real_type H, real_type base_DDDDD[6] );
128
129 #endif
130
141 static
142 inline
143 void
144 Hermite3_to_poly(
145 real_type H,
146 real_type P0,
147 real_type P1,
148 real_type DP0,
149 real_type DP1,
150 real_type & A,
151 real_type & B,
152 real_type & C,
153 real_type & D
154 ) {
155 real_type H2{ H*H };
156 real_type P10{ P1-P0 };
157 A = (DP0+DP1-2*P10/H)/H2;
158 B = (3*P10/H-(2*DP0+DP1))/H;
159 C = DP0;
160 D = P0;
161 }
162
177 static
178 inline
179 void
180 Hermite5_to_poly(
181 real_type h,
182 real_type P0,
183 real_type P1,
184 real_type DP0,
185 real_type DP1,
186 real_type DDP0,
187 real_type DDP1,
188 real_type & A,
189 real_type & B,
190 real_type & C,
191 real_type & D,
192 real_type & E,
193 real_type & F
194 ) {
195 real_type h2{ h*h };
196 real_type h3{ h*h2 };
197 real_type P10{ P1-P0 };
198 A = ( (DDP1-DDP0)/2+(6*P10/h-3*(DP0+DP1))/h)/h3;
199 B = ( (1.5*DDP0-DDP1)+ ((8*DP0+7*DP1)-15*P10/h)/h )/h2;
200 C = ( 0.5*DDP1-1.5*DDP0 + (10*P10/h -(6*DP0+4*DP1))/h )/h;
201 D = DDP0/2;
202 E = DP0;
203 F = P0;
204 }
205
206 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
207
208 /*
209 // ____ _ _ _
210 // | __ )(_) (_)_ __ ___ __ _ _ __
211 // | _ \| | | | '_ \ / _ \/ _` | '__|
212 // | |_) | | | | | | | __/ (_| | |
213 // |____/|_|_|_|_| |_|\___|\__,_|_|
214 */
215
216 #ifndef DOXYGEN_SHOULD_SKIP_THIS
217
219 bilinear3(
220 real_type const p[4],
221 real_type const M[4][4],
222 real_type const q[4]
223 );
224
226 bilinear5(
227 real_type const p[6],
228 real_type const M[6][6],
229 real_type const q[6]
230 );
231
232 integer
234 real_type const X[],
235 real_type const Y[],
236 real_type const Yp[],
237 integer npts
238 );
239
240 #endif
241
242 /*\
243 | ____ _ _ _ _
244 | | _ \ __ _ _ __ __ _ _ __ ___ ___| |_ _ __(_)______ _| |_(_) ___ _ __
245 | | |_) / _` | '__/ _` | '_ ` _ \ / _ \ __| '__| |_ / _` | __| |/ _ \| '_ \
246 | | __/ (_| | | | (_| | | | | | | __/ |_| | | |/ / (_| | |_| | (_) | | | |
247 | |_| \__,_|_| \__,_|_| |_| |_|\___|\__|_| |_/___\__,_|\__|_|\___/|_| |_|
248 |
249 \*/
250
260 void
261 uniform(
262 integer dim,
263 integer npts,
264 real_type const pnts[],
265 integer ld_pnts,
266 real_type t[]
267 );
268
278 void
279 chordal(
280 integer dim,
281 integer npts,
282 real_type const pnts[],
283 integer ld_pnts,
284 real_type t[]
285 );
286
297 void
299 integer dim,
300 integer npts,
301 real_type const pnts[],
302 integer ld_pnts,
303 real_type alpha,
304 real_type t[]
305 );
306
316 void
318 integer dim,
319 integer npts,
320 real_type const pnts[],
321 integer ld_pnts,
322 real_type t[]
323 );
324
334 void
336 integer dim,
337 integer npts,
338 real_type const pnts[],
339 integer ld_pnts,
340 real_type t[]
341 );
342
352 void
354 integer dim,
355 integer npts,
356 real_type const pnts[],
357 integer ld_pnts,
358 real_type t[]
359 );
360
361 /*\
362 | ____ _ _
363 | / ___| _ __ | (_)_ __ ___
364 | \___ \| '_ \| | | '_ \ / _ \
365 | ___) | |_) | | | | | | __/
366 | |____/| .__/|_|_|_| |_|\___|
367 | |_|
368 \*/
372 class Spline {
373 friend class SplineSet;
374 protected:
375
376 #ifndef DOXYGEN_SHOULD_SKIP_THIS
377
378 string m_name;
379 bool m_curve_is_closed{false};
380 bool m_curve_can_extend{true};
381 bool m_curve_extended_constant{false};
382
383 integer m_npts{0};
384 integer m_npts_reserved{0};
385 real_type * m_X{nullptr}; // allocated in the derived class!
386 real_type * m_Y{nullptr}; // allocated in the derived class!
387
388 #ifdef SPLINES_USE_THREADS
389 mutable std::mutex m_last_interval_mutex;
390 mutable std::map<std::thread::id,std::shared_ptr<integer>> m_last_interval;
391 #else
392 mutable integer m_last_interval;
393 #endif
394
395 void init_last_interval();
396
397 Spline( Spline const & ) = delete;
398 Spline const & operator = ( Spline const & ) = delete;
399
400 #endif
401
402 public:
403
406
410 Spline( string const & name = "Spline" )
411 : m_name(name)
412 {
413 this->init_last_interval();
414 }
415
419 virtual
421 {}
422
424
428 void search( std::pair<integer,real_type> & res ) const;
429
434
438 string const & name() const { return m_name; }
439
441 bool is_closed() const { return m_curve_is_closed; }
447 void make_closed() { m_curve_is_closed = true; }
453 void make_opened() { m_curve_is_closed = false; }
454
458 bool is_bounded() const { return !m_curve_can_extend; }
464 void make_unbounded() { m_curve_can_extend = true; }
470 void make_bounded() { m_curve_can_extend = false; }
471
475 bool is_extended_constant() const { return m_curve_extended_constant; }
481 void make_extended_constant() { m_curve_extended_constant = true; }
487 void make_extended_not_constant() { m_curve_extended_constant = false; }
488
490
493
497 integer num_points() const { return m_npts; }
498
502 real_type x_node( integer i ) const { return m_X[size_t(i)]; }
503
507 real_type y_node( integer i ) const { return m_Y[size_t(i)]; }
508
512 real_type x_begin() const { return m_X[0]; }
513
517 real_type y_begin() const { return m_Y[0]; }
518
522 real_type x_end() const { return m_X[size_t(m_npts-1)]; }
523
527 real_type y_end() const { return m_Y[size_t(m_npts-1)]; }
528
532 real_type x_min() const { return m_X[0]; }
533
537 real_type x_max() const { return m_X[m_npts-1]; }
538
543 y_min() const {
544 integer N{m_npts};
545 if ( type() == SplineType1D::CONSTANT ) --N;
546 return *std::min_element(m_Y,m_Y+N);
547 }
548
553 y_max() const {
554 integer N{m_npts};
555 if ( type() == SplineType1D::CONSTANT ) --N;
556 return *std::max_element(m_Y,m_Y+N);
557 }
558
570 virtual
571 void
572 y_min_max(
573 integer & i_min_pos,
574 real_type & x_min_pos,
576 integer & i_max_pos,
577 real_type & x_max_pos,
579 ) const;
580
592 virtual
593 void
594 y_min_max(
595 vector<integer> & i_min_pos,
596 vector<real_type> & x_min_pos,
597 vector<real_type> & y_min,
598 vector<integer> & i_max_pos,
599 vector<real_type> & x_max_pos,
600 vector<real_type> & y_max
601 ) const;
602
604
607
611 void
612 build( GenericContainer const & gc )
613 { setup(gc); }
614
624 virtual
625 void
626 build(
627 real_type const x[], integer incx,
628 real_type const y[], integer incy,
629 integer n
630 );
631
639 inline
640 void
642 real_type const x[],
643 real_type const y[],
644 integer n
645 )
646 { this->build( x, 1, y, 1, n ); }
647
654 inline
655 void
656 build( vector<real_type> const & x, vector<real_type> const & y ) {
657 integer N = integer(x.size());
658 if ( N > integer(y.size()) ) N = integer(y.size());
659 this->build( &x.front(), 1, &y.front(), 1, N );
660 }
661
665 virtual
666 void build() = 0;
667
674 virtual
675 void setup( GenericContainer const & gc );
676
678
681
685 virtual void reserve( integer npts ) = 0;
686
690 void push_back( real_type x, real_type y );
691
695 void drop_back() { if ( m_npts > 0 ) --m_npts; }
696
700 virtual void clear() = 0;
701
703
706
710 void set_origin( real_type x0 );
711
715 void set_range( real_type xmin, real_type xmax );
716
718
721
725 void
726 dump(
727 ostream_type & s,
728 integer nintervals,
729 char const header[] = "x\ty"
730 ) const;
731
735 void
737 char const fname[],
738 integer nintervals,
739 char const header[] = "x\ty"
740 ) const {
741 std::ofstream file(fname);
742 this->dump( file, nintervals, header );
743 file.close();
744 }
745
749 virtual void write_to_stream( ostream_type & s ) const = 0;
750
752
755
759 virtual real_type eval( real_type x ) const = 0;
760
764 virtual real_type D( real_type x ) const = 0;
765
769 virtual real_type DD( real_type x ) const = 0;
770
774 virtual real_type DDD( real_type x ) const = 0;
775
779 virtual real_type DDDD( real_type ) const { return real_type(0); }
780
784 virtual real_type DDDDD( real_type ) const { return real_type(0); }
785
787
795 real_type operator () ( real_type x ) const { return this->eval(x); }
799 real_type eval_D( real_type x ) const { return this->D(x); }
803 real_type eval_DD( real_type x ) const { return this->DD(x); }
807 real_type eval_DDD( real_type x ) const { return this->DDD(x); }
811 real_type eval_DDDD( real_type x ) const { return this->DDDD(x); }
815 real_type eval_DDDDD( real_type x ) const { return this->DDDDD(x); }
817
822
826 virtual real_type id_eval( integer ni, real_type x ) const = 0;
827
831 virtual real_type id_D( integer ni, real_type x ) const = 0;
832
836 virtual real_type id_DD( integer ni, real_type x ) const = 0;
837
841 virtual real_type id_DDD( integer ni, real_type x ) const = 0;
842
846 virtual real_type id_DDDD( integer, real_type ) const { return real_type(0); }
847
851 virtual real_type id_DDDDD( integer, real_type ) const { return real_type(0); }
852
854
857
861 virtual
862 integer // order
864 real_type cfs[],
865 real_type nodes[],
866 bool transpose = false
867 ) const = 0;
868
872 virtual integer order() const = 0;
873
877 char const *
878 type_name() const
879 { return to_string(type()); }
880
884 virtual SplineType1D type() const = 0;
885
889 string info() const;
890
894 void
895 info( ostream_type & stream ) const
896 { stream << this->info() << '\n'; }
897
899
900 #ifdef SPLINES_BACK_COMPATIBILITY
901 void pushBack( real_type x, real_type y ) { push_back(x,y); }
902 void dropBack() { drop_back(); }
903 void setOrigin( real_type x0 ) { set_origin(x0); }
904 void setRange( real_type xmin, real_type xmax ) { set_range( xmin, xmax ); }
905 void writeToStream( ostream_type & s ) const { write_to_stream(s); }
906 #endif
907
908 };
909
913 real_type curvature( real_type s, Spline const & X, Spline const & Y );
914
918 real_type curvature_D( real_type s, Spline const & X, Spline const & Y );
919
923 real_type curvature_DD( real_type s, Spline const & X, Spline const & Y );
924
925 /*\
926 | ____ _ _ ____ _ _ ____
927 | / ___| _| |__ (_) ___ / ___| _ __ | (_)_ __ ___ | __ ) __ _ ___ ___
928 | | | | | | | '_ \| |/ __| \___ \| '_ \| | | '_ \ / _ \ | _ \ / _` / __|/ _ \
929 | | |__| |_| | |_) | | (__ ___) | |_) | | | | | | __/ | |_) | (_| \__ \ __/
930 | \____\__,_|_.__/|_|\___| |____/| .__/|_|_|_| |_|\___| |____/ \__,_|___/\___|
931 | |_|
932 \*/
936 class CubicSplineBase : public Spline {
937 protected:
938
939 #ifndef DOXYGEN_SHOULD_SKIP_THIS
940 Malloc_real m_mem_cubic;
941 real_type * m_Yp{nullptr};
942 bool m_external_alloc{false};
943 #endif
944
945 public:
946
947 #ifndef DOXYGEN_SHOULD_SKIP_THIS
948 using Spline::build;
949 #endif
950
957 CubicSplineBase( string const & name = "CubicSplineBase" );
958
959 ~CubicSplineBase() override {}
961
965 void copy_spline( CubicSplineBase const & S );
966
970 real_type yp_node( integer i ) const { return m_Yp[size_t(i)]; }
971
975 void set_range( real_type xmin, real_type xmax );
976
980 void
982 integer n,
983 real_type * & p_x,
984 real_type * & p_y,
985 real_type * & p_dy
986 );
987
988 void
990 integer & i_min_pos,
991 real_type & x_min_pos,
993 integer & i_max_pos,
994 real_type & x_max_pos,
996 ) const override;
997
998 void
1000 vector<integer> & i_min_pos,
1001 vector<real_type> & x_min_pos,
1002 vector<real_type> & y_min,
1003 vector<integer> & i_max_pos,
1004 vector<real_type> & x_max_pos,
1005 vector<real_type> & y_max
1006 ) const override;
1007
1008 // --------------------------- VIRTUALS -----------------------------------
1009
1014 real_type eval( real_type x ) const override;
1015 real_type D( real_type x ) const override;
1016 real_type DD( real_type x ) const override;
1017 real_type DDD( real_type x ) const override;
1018 real_type DDDD( real_type ) const override { return 0; }
1019 real_type DDDDD( real_type ) const override { return 0; }
1021
1025 real_type id_eval( integer ni, real_type x ) const override;
1026 real_type id_D( integer ni, real_type x ) const override;
1027 real_type id_DD( integer ni, real_type x ) const override;
1028 real_type id_DDD( integer ni, real_type x ) const override;
1029 real_type id_DDDD( integer, real_type ) const override { return 0; }
1030 real_type id_DDDDD( integer, real_type ) const override { return 0; }
1032
1033 void write_to_stream( ostream_type & s ) const override;
1034
1035 // --------------------------- VIRTUALS -----------------------------------
1036
1041
1053 void
1055 real_type const x[], integer incx,
1056 real_type const y[], integer incy,
1057 real_type const yp[], integer incyp,
1058 integer n
1059 );
1060
1069 inline
1070 void
1072 real_type const x[],
1073 real_type const y[],
1074 real_type const yp[],
1075 integer n
1076 ) {
1077 this->build( x, 1, y, 1, yp, 1, n );
1078 }
1079
1087 void
1089 vector<real_type> const & x,
1090 vector<real_type> const & y,
1091 vector<real_type> const & yp
1092 );
1093
1094 void reserve( integer npts ) override;
1095
1097
1098 void clear() override;
1099
1100 integer // order
1102 real_type cfs[],
1103 real_type nodes[],
1104 bool transpose = false
1105 ) const override;
1106
1107 integer order() const override;
1108
1109 #ifdef SPLINES_BACK_COMPATIBILITY
1110 void copySpline( CubicSplineBase const & S ) { this->copy_spline(S); }
1111 integer numPoints() const { return m_npts; }
1112 real_type xNode( integer i ) const { return m_X[size_t(i)]; }
1113 real_type yNode( integer i ) const { return m_Y[size_t(i)]; }
1114 real_type ypNode( integer i ) const { return this->yp_node(i); }
1115 real_type xBegin() const { return m_X[0]; }
1116 real_type yBegin() const { return m_Y[0]; }
1117 real_type xEnd() const { return m_X[size_t(m_npts-1)]; }
1118 real_type yEnd() const { return m_Y[size_t(m_npts-1)]; }
1119 real_type xMin() const { return m_X[0]; }
1120 real_type xMax() const { return m_X[m_npts-1]; }
1121 real_type yMin() const { return y_min(); }
1122 real_type yMax() const { return y_max(); }
1123 #endif
1124
1125 };
1126
1127 /*\
1128 | ____ _ _ ____ __
1129 | / ___| _ __ | (_)_ __ ___/ ___| _ _ _ __ / _|
1130 | \___ \| '_ \| | | '_ \ / _ \___ \| | | | '__| |_
1131 | ___) | |_) | | | | | | __/___) | |_| | | | _|
1132 | |____/| .__/|_|_|_| |_|\___|____/ \__,_|_| |_|
1133 | |_|
1134 \*/
1135
1140
1141 SplineSurf( SplineSurf const & ) = delete; // block copy constructor
1142 SplineSurf const & operator = ( SplineSurf const & ) = delete; // block copy method
1143
1144 Malloc_real m_mem;
1145
1146 protected:
1147
1148 #ifndef DOXYGEN_SHOULD_SKIP_THIS
1149
1150 string const m_name;
1151 bool m_x_closed{false};
1152 bool m_y_closed{false};
1153 bool m_x_can_extend{true};
1154 bool m_y_can_extend{true};
1155
1156 integer m_nx{0};
1157 integer m_ny{0};
1158
1159 real_type * m_X{nullptr};
1160 real_type * m_Y{nullptr};
1161 real_type * m_Z{nullptr};
1162
1163 real_type m_Z_min{0};
1164 real_type m_Z_max{0};
1165
1166 #ifdef SPLINES_USE_THREADS
1167 mutable std::mutex m_last_interval_x_mutex;
1168 mutable std::mutex m_last_interval_y_mutex;
1169 mutable std::map<std::thread::id,std::shared_ptr<integer>> m_last_interval_x;
1170 mutable std::map<std::thread::id,std::shared_ptr<integer>> m_last_interval_y;
1171 #else
1172 mutable integer m_last_interval_x;
1173 mutable integer m_last_interval_y;
1174 #endif
1175
1176 integer search_x( real_type & x ) const;
1177 integer search_y( real_type & y ) const;
1178
1179 void init_last_interval_x();
1180 void init_last_interval_y();
1181
1182 integer
1183 ipos_C( integer i, integer j, integer ldZ ) const
1184 { return i*ldZ + j; }
1185
1186 integer
1187 ipos_F( integer i, integer j, integer ldZ ) const
1188 { return i + ldZ*j; }
1189
1190 integer
1191 ipos_C( integer i, integer j ) const
1192 { return this->ipos_C(i,j,m_ny); }
1193
1194 integer
1195 ipos_F( integer i, integer j ) const
1196 { return this->ipos_F(i,j,m_nx); }
1197
1198 virtual void make_spline() = 0;
1199
1200 void
1201 load_Z(
1202 real_type const z[],
1203 integer ldZ,
1204 bool fortran_storage,
1205 bool transposed
1206 );
1207
1208 #endif
1209
1210 public:
1211
1215 SplineSurf( string const & name = "Spline" )
1216 : m_mem("SplineSurf")
1217 , m_name(name)
1218 {
1219 this->init_last_interval_x();
1220 this->init_last_interval_y();
1221 }
1222
1226 virtual
1228
1233
1237 bool is_x_closed() const { return m_x_closed; }
1238
1242 void make_x_closed() { m_x_closed = true; }
1243
1247 void make_x_opened() { m_x_closed = false; }
1248
1252 bool is_y_closed() const { return m_y_closed; }
1253
1257 void make_y_closed() { m_y_closed = true; }
1258
1262 void make_y_opened() { m_y_closed = false; }
1263
1269 bool is_x_bounded() const { return m_x_can_extend; }
1270
1274 void make_x_unbounded() { m_x_can_extend = true; }
1275
1279 void make_x_bounded() { m_x_can_extend = false; }
1280
1286 bool is_y_bounded() const { return m_y_can_extend; }
1287
1291 void make_y_unbounded() { m_y_can_extend = true; }
1292
1296 void make_y_bounded() { m_y_can_extend = false; }
1297
1299
1303 void clear();
1304
1309
1313 string const & name() const { return m_name; }
1314
1318 integer num_point_x() const { return m_nx; }
1319
1323 integer num_point_y() const { return m_ny; }
1324
1328 real_type x_node( integer i ) const { return m_X[size_t(i)]; }
1329
1333 real_type y_node( integer i ) const { return m_Y[size_t(i)]; }
1334
1338 real_type
1339 z_node( integer i, integer j ) const
1340 { return m_Z[size_t(this->ipos_C(i,j))]; }
1341
1345 real_type x_min() const { return m_X[0]; }
1346
1350 real_type x_max() const { return m_X[m_nx-1]; }
1351
1355 real_type y_min() const { return m_Y[0]; }
1356
1360 real_type y_max() const { return m_Y[m_ny-1]; }
1361
1365 real_type z_min() const { return m_Z_min; }
1366
1370 real_type z_max() const { return m_Z_max; }
1371
1373
1378
1395 void
1396 build(
1397 real_type const x[], integer incx,
1398 real_type const y[], integer incy,
1399 real_type const z[], integer ldZ,
1400 integer nx, integer ny,
1401 bool fortran_storage = false,
1402 bool transposed = false
1403 );
1404
1416 void
1418 vector<real_type> const & x,
1419 vector<real_type> const & y,
1420 vector<real_type> const & z,
1421 bool fortran_storage = false,
1422 bool transposed = false
1423 ) {
1424 bool xyswp = (fortran_storage && transposed) ||
1425 (!fortran_storage && !transposed);
1426 this->build(
1427 &x.front(), 1,
1428 &y.front(), 1,
1429 &z.front(), integer(xyswp ? y.size() : x.size()),
1430 integer(x.size()), integer(y.size()),
1431 fortran_storage, transposed
1432 );
1433 }
1434
1435 void
1436 build(
1437 real_type const z[],
1438 integer ldZ,
1439 integer nx,
1440 integer ny,
1441 bool fortran_storage = false,
1442 bool transposed = false
1443 );
1444
1458 void
1460 vector<real_type> const & z,
1461 integer nx,
1462 integer ny,
1463 bool fortran_storage = false,
1464 bool transposed = false
1465 ) {
1466 this->build( &z.front(), nx, ny, fortran_storage ? nx : ny, fortran_storage, transposed );
1467 }
1468
1472 void
1473 setup( GenericContainer const & gc );
1474
1478 void
1479 build( GenericContainer const & gc )
1480 { setup(gc); }
1481
1483
1488
1492 virtual
1493 real_type
1494 eval( real_type x, real_type y ) const = 0;
1495
1503 virtual
1504 void
1505 D( real_type x, real_type y, real_type d[3] ) const = 0;
1506
1511 virtual
1512 real_type
1513 Dx( real_type x, real_type y ) const = 0;
1514
1519 virtual
1520 real_type
1521 Dy( real_type x, real_type y ) const = 0;
1522
1533 virtual
1534 void
1535 DD( real_type x, real_type y, real_type dd[6] ) const = 0;
1536
1541 virtual
1542 real_type
1543 Dxx( real_type x, real_type y ) const = 0;
1544
1548 virtual
1549 real_type
1550 Dxy( real_type x, real_type y ) const = 0;
1551
1556 virtual
1557 real_type
1558 Dyy( real_type x, real_type y ) const = 0;
1559
1563 real_type
1565 { return this->eval(x,y); }
1566
1570 real_type
1572 { return this->Dx(x,y); }
1573
1577 real_type
1579 { return this->Dy(x,y); }
1580
1584 real_type
1586 { return this->Dxx(x,y); }
1587
1591 real_type
1593 { return this->Dxy(x,y); }
1594
1598 real_type
1600 { return this->Dyy(x,y); }
1601
1603
1607 virtual void write_to_stream( ostream_type & s ) const = 0;
1608
1612 virtual char const * type_name() const = 0;
1613
1617 virtual string info() const;
1618
1622 void
1623 info( ostream_type & stream ) const
1624 { stream << this->info() << '\n'; }
1625
1629 void dump_data( ostream_type & s ) const;
1630
1631 #ifdef SPLINES_BACK_COMPATIBILITY
1632 integer numPointX() const { return m_nx; }
1633 integer numPointY() const { return m_ny; }
1634 real_type xNode( integer i ) const { return m_X[size_t(i)]; }
1635 real_type yNode( integer i ) const { return m_Y[size_t(i)]; }
1636 real_type zNode( integer i, integer j ) const { return z_node(i,j); }
1637 real_type xMin() const { return this->x_min(); }
1638 real_type xMax() const { return this->x_max(); }
1639 real_type yMin() const { return this->y_min(); }
1640 real_type yMax() const { return this->y_max(); }
1641 real_type zMin() const { return m_Z_min; }
1642 real_type zMax() const { return m_Z_max; }
1643 void writeToStream( ostream_type & s ) const { write_to_stream(s); }
1644 #endif
1645
1646 };
1647
1648}
1649
1650#include "Splines/SplineAkima.hxx"
1651#include "Splines/SplineBessel.hxx"
1652#include "Splines/SplineConstant.hxx"
1653#include "Splines/SplineLinear.hxx"
1654#include "Splines/SplineCubic.hxx"
1655#include "Splines/SplineHermite.hxx"
1656#include "Splines/SplinePchip.hxx"
1657#include "Splines/SplineQuinticBase.hxx"
1658#include "Splines/SplineQuintic.hxx"
1659#include "Splines/SplineBilinear.hxx"
1660#include "Splines/SplineBiCubic.hxx"
1661#include "Splines/SplineAkima2D.hxx"
1662#include "Splines/SplineBiQuintic.hxx"
1663
1664#include "Splines/SplineVec.hxx"
1665#include "Splines/SplineSet.hxx"
1666#include "Splines/Splines1D.hxx"
1667#include "Splines/Splines2D.hxx"
1668
1669#ifndef DOXYGEN_SHOULD_SKIP_THIS
1670
1671namespace SplinesLoad {
1672
1673 using Splines::Spline;
1682 using Splines::Spline1D;
1683
1688 using Splines::Spline2D;
1689
1690 using Splines::SplineVec;
1691 using Splines::SplineSet;
1692
1695}
1696
1697#endif
1698
1699#ifdef __GNUC__
1700#pragma GCC diagnostic pop
1701#endif
1702#ifdef __clang__
1703#pragma clang diagnostic pop
1704#endif
1705
1706#endif
Definition SplineAkima2D.hxx:40
Definition SplineAkima.hxx:50
Definition SplineBessel.hxx:46
Definition SplineBiCubic.hxx:154
cubic spline base class
Definition SplineBiQuintic.hxx:164
bilinear spline base class
Definition SplineBilinear.hxx:32
Picewise constants spline class.
Definition SplineConstant.hxx:32
Definition Splines.hh:936
real_type DDDDD(real_type) const override
Definition Splines.hh:1019
real_type DD(real_type x) const override
integer order() const override
real_type eval(real_type x) const override
void y_min_max(integer &i_min_pos, real_type &x_min_pos, real_type &y_min, integer &i_max_pos, real_type &x_max_pos, real_type &y_max) const override
void build(real_type const x[], real_type const y[], real_type const yp[], integer n)
Definition Splines.hh:1071
void reserve_external(integer n, real_type *&p_x, real_type *&p_y, real_type *&p_dy)
void write_to_stream(ostream_type &s) const override
real_type id_DDDD(integer, real_type) const override
Definition Splines.hh:1029
void build(real_type const x[], integer incx, real_type const y[], integer incy, real_type const yp[], integer incyp, integer n)
real_type id_DDDDD(integer, real_type) const override
Definition Splines.hh:1030
real_type id_eval(integer ni, real_type x) const override
CubicSplineBase(string const &name="CubicSplineBase")
void set_range(real_type xmin, real_type xmax)
real_type DDDD(real_type) const override
Definition Splines.hh:1018
real_type id_DDD(integer ni, real_type x) const override
integer coeffs(real_type cfs[], real_type nodes[], bool transpose=false) const override
void y_min_max(vector< integer > &i_min_pos, vector< real_type > &x_min_pos, vector< real_type > &y_min, vector< integer > &i_max_pos, vector< real_type > &x_max_pos, vector< real_type > &y_max) const override
real_type D(real_type x) const override
real_type id_D(integer ni, real_type x) const override
real_type yp_node(integer i) const
Definition Splines.hh:970
void clear() override
void copy_spline(CubicSplineBase const &S)
real_type DDD(real_type x) const override
real_type id_DD(integer ni, real_type x) const override
void reserve(integer npts) override
void build(vector< real_type > const &x, vector< real_type > const &y, vector< real_type > const &yp)
Definition SplineCubic.hxx:69
Linear spline class.
Definition SplineLinear.hxx:32
Pchip (Piecewise Cubic Hermite Interpolating Polynomial) spline class.
Definition SplinePchip.hxx:39
Quintic spline class.
Definition SplineQuintic.hxx:44
Spline Management Class.
Definition Splines1D.hxx:32
Definition Splines2D.hxx:34
Definition Splines.hh:372
void build(vector< real_type > const &x, vector< real_type > const &y)
Definition Splines.hh:656
void make_extended_not_constant()
Definition Splines.hh:487
string info() const
Definition Splines.cc:427
virtual real_type id_D(integer ni, real_type x) const =0
real_type x_max() const
Definition Splines.hh:537
virtual real_type id_DDDD(integer, real_type) const
Definition Splines.hh:846
void make_extended_constant()
Definition Splines.hh:481
void dump(char const fname[], integer nintervals, char const header[]="x\ty") const
Definition Splines.hh:736
real_type y_max() const
Definition Splines.hh:553
void drop_back()
Definition Splines.hh:695
bool is_bounded() const
Definition Splines.hh:458
real_type eval_D(real_type x) const
Definition Splines.hh:799
virtual real_type DDDDD(real_type) const
Definition Splines.hh:784
real_type y_end() const
Definition Splines.hh:527
virtual void build()=0
void push_back(real_type x, real_type y)
Definition Splines.cc:443
real_type operator()(real_type x) const
Definition Splines.hh:795
virtual void y_min_max(integer &i_min_pos, real_type &x_min_pos, real_type &y_min, integer &i_max_pos, real_type &x_max_pos, real_type &y_max) const
Definition Splines.cc:515
virtual real_type id_DDDDD(integer, real_type) const
Definition Splines.hh:851
Spline(string const &name="Spline")
Definition Splines.hh:410
real_type eval_DD(real_type x) const
Definition Splines.hh:803
void build(real_type const x[], real_type const y[], integer n)
Definition Splines.hh:641
virtual real_type eval(real_type x) const =0
bool is_closed() const
Definition Splines.hh:441
real_type y_min() const
Definition Splines.hh:543
real_type eval_DDD(real_type x) const
Definition Splines.hh:807
virtual void write_to_stream(ostream_type &s) const =0
virtual void setup(GenericContainer const &gc)
Definition Splines.cc:647
void make_unbounded()
Definition Splines.hh:464
void dump(ostream_type &s, integer nintervals, char const header[]="x\ty") const
Definition Splines.cc:499
virtual SplineType1D type() const =0
void make_closed()
Definition Splines.hh:447
virtual real_type DD(real_type x) const =0
real_type x_begin() const
Definition Splines.hh:512
virtual real_type id_DDD(integer ni, real_type x) const =0
void info(ostream_type &stream) const
Definition Splines.hh:895
real_type y_begin() const
Definition Splines.hh:517
void set_origin(real_type x0)
Definition Splines.cc:477
void make_opened()
Definition Splines.hh:453
virtual real_type id_DD(integer ni, real_type x) const =0
virtual void reserve(integer npts)=0
real_type x_min() const
Definition Splines.hh:532
virtual real_type DDDD(real_type) const
Definition Splines.hh:779
virtual real_type id_eval(integer ni, real_type x) const =0
string const & name() const
Definition Splines.hh:438
real_type x_end() const
Definition Splines.hh:522
void make_bounded()
Definition Splines.hh:470
virtual real_type D(real_type x) const =0
virtual real_type DDD(real_type x) const =0
real_type eval_DDDDD(real_type x) const
Definition Splines.hh:815
void search(std::pair< integer, real_type > &res) const
Definition Splines.cc:242
virtual integer coeffs(real_type cfs[], real_type nodes[], bool transpose=false) const =0
real_type eval_DDDD(real_type x) const
Definition Splines.hh:811
real_type y_node(integer i) const
Definition Splines.hh:507
integer num_points() const
Definition Splines.hh:497
bool is_extended_constant() const
Definition Splines.hh:475
void set_range(real_type xmin, real_type xmax)
Definition Splines.cc:486
virtual ~Spline()
Definition Splines.hh:420
virtual void clear()=0
real_type x_node(integer i) const
Definition Splines.hh:502
virtual integer order() const =0
void build(GenericContainer const &gc)
Definition Splines.hh:612
char const * type_name() const
Definition Splines.hh:878
Splines Management Class.
Definition SplineSet.hxx:32
Definition Splines.hh:1139
virtual char const * type_name() const =0
SplineSurf(string const &name="Spline")
Definition Splines.hh:1215
virtual real_type Dx(real_type x, real_type y) const =0
void make_x_unbounded()
Definition Splines.hh:1274
void build(GenericContainer const &gc)
Definition Splines.hh:1479
virtual void D(real_type x, real_type y, real_type d[3]) const =0
virtual string info() const
virtual real_type Dxy(real_type x, real_type y) const =0
virtual real_type Dyy(real_type x, real_type y) const =0
real_type z_node(integer i, integer j) const
Definition Splines.hh:1339
void make_x_bounded()
Definition Splines.hh:1279
bool is_y_closed() const
Definition Splines.hh:1252
real_type eval_D_2_2(real_type x, real_type y) const
Definition Splines.hh:1599
real_type x_min() const
Definition Splines.hh:1345
real_type eval_D_1(real_type x, real_type y) const
Definition Splines.hh:1571
virtual void write_to_stream(ostream_type &s) const =0
void make_y_bounded()
Definition Splines.hh:1296
void make_y_unbounded()
Definition Splines.hh:1291
void setup(GenericContainer const &gc)
Definition SplinesBivariate.cc:599
real_type eval_D_2(real_type x, real_type y) const
Definition Splines.hh:1578
bool is_y_bounded() const
Definition Splines.hh:1286
virtual void DD(real_type x, real_type y, real_type dd[6]) const =0
void dump_data(ostream_type &s) const
string const & name() const
Definition Splines.hh:1313
real_type y_max() const
Definition Splines.hh:1360
real_type x_node(integer i) const
Definition Splines.hh:1328
void make_y_closed()
Definition Splines.hh:1257
real_type x_max() const
Definition Splines.hh:1350
void make_x_closed()
Definition Splines.hh:1242
void info(ostream_type &stream) const
Definition Splines.hh:1623
virtual real_type Dy(real_type x, real_type y) const =0
void make_x_opened()
Definition Splines.hh:1247
void build(vector< real_type > const &z, integer nx, integer ny, bool fortran_storage=false, bool transposed=false)
Definition Splines.hh:1459
real_type eval_D_1_2(real_type x, real_type y) const
Definition Splines.hh:1592
void build(real_type const x[], integer incx, real_type const y[], integer incy, real_type const z[], integer ldZ, integer nx, integer ny, bool fortran_storage=false, bool transposed=false)
Definition SplinesBivariate.cc:144
real_type z_max() const
Definition Splines.hh:1370
real_type y_node(integer i) const
Definition Splines.hh:1333
real_type eval_D_1_1(real_type x, real_type y) const
Definition Splines.hh:1585
real_type y_min() const
Definition Splines.hh:1355
real_type operator()(real_type x, real_type y) const
Definition Splines.hh:1564
bool is_x_closed() const
Definition Splines.hh:1237
virtual real_type eval(real_type x, real_type y) const =0
void build(vector< real_type > const &x, vector< real_type > const &y, vector< real_type > const &z, bool fortran_storage=false, bool transposed=false)
Definition Splines.hh:1417
integer num_point_x() const
Definition Splines.hh:1318
virtual real_type Dxx(real_type x, real_type y) const =0
integer num_point_y() const
Definition Splines.hh:1323
void make_y_opened()
Definition Splines.hh:1262
real_type z_min() const
Definition Splines.hh:1365
bool is_x_bounded() const
Definition Splines.hh:1269
Definition SplineVec.hxx:34
Definition SplineAkima.cc:50
int integer
Signed integer type for splines.
Definition Splines.hh:58
void FangHung(integer dim, integer npts, real_type const pnts[], integer ld_pnts, real_type t[])
void uniform(integer, integer npts, real_type const [], integer, real_type t[])
Definition Splines.cc:67
void universal(integer dim, integer npts, real_type const pnts[], integer ld_pnts, real_type t[])
integer check_cubic_spline_monotonicity(real_type const X[], real_type const Y[], real_type const Yp[], integer npts)
Check if cubic spline with this data is monotone, return -1 no, 0 yes, 1 strictly monotone.
Definition Splines.cc:370
real_type curvature_DD(real_type s, Spline const &X, Spline const &Y)
Definition Splines.cc:595
void centripetal(integer dim, integer npts, real_type const pnts[], integer ld_pnts, real_type alpha, real_type t[])
Definition Splines.cc:108
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
real_type curvature(real_type s, Spline const &X, Spline const &Y)
Definition Splines.cc:557
void chordal(integer dim, integer npts, real_type const pnts[], integer ld_pnts, real_type t[])
Definition Splines.cc:83
void FoleyNielsen(integer dim, integer npts, real_type const pnts[], integer ld_pnts, real_type t[])
enum class SplineType2D :integer { BILINEAR=0, BICUBIC=1, BIQUINTIC=2, AKIMA2D=3 } SplineType2D
Associate a number for each type of splines implemented.
Definition Splines.hh:87
real_type curvature_D(real_type s, Spline const &X, Spline const &Y)
Definition Splines.cc:572
double real_type
Floating point type for splines.
Definition Splines.hh:57