26#pragma GCC diagnostic push
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"
37#include "SplinesConfig.hh"
48 using std::runtime_error;
49 using std::basic_ostream;
50 using std::basic_istream;
51 using std::lower_bound;
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>;
65 void backtrace( ostream_type & );
94 #ifndef DOXYGEN_SHOULD_SKIP_THIS
95 extern SplineType1D string_to_splineType1D(
string const & n );
96 extern SplineType2D string_to_splineType2D(
string const & n );
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;
115 #ifndef DOXYGEN_SHOULD_SKIP_THIS
157 A = (DP0+DP1-2*P10/H)/H2;
158 B = (3*P10/H-(2*DP0+DP1))/H;
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;
216 #ifndef DOXYGEN_SHOULD_SKIP_THIS
376 #ifndef DOXYGEN_SHOULD_SKIP_THIS
379 bool m_curve_is_closed{
false};
380 bool m_curve_can_extend{
true};
381 bool m_curve_extended_constant{
false};
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;
392 mutable integer m_last_interval;
395 void init_last_interval();
413 this->init_last_interval();
428 void search( std::pair<integer,real_type> & res )
const;
438 string const &
name()
const {
return m_name; }
545 if (
type() == SplineType1D::CONSTANT ) --N;
546 return *std::min_element(m_Y,m_Y+N);
555 if (
type() == SplineType1D::CONSTANT ) --N;
556 return *std::max_element(m_Y,m_Y+N);
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
612 build( GenericContainer
const & gc )
646 { this->
build( x, 1, y, 1, n ); }
656 build( vector<real_type>
const & x, vector<real_type>
const & y ) {
659 this->
build( &x.front(), 1, &y.front(), 1, N );
675 void setup( GenericContainer
const & gc );
729 char const header[] =
"x\ty"
739 char const header[] =
"x\ty"
741 std::ofstream file(fname);
742 this->
dump( file, nintervals, header );
866 bool transpose =
false
879 {
return to_string(
type()); }
895 info( ostream_type & stream )
const
896 { stream << this->
info() <<
'\n'; }
900 #ifdef SPLINES_BACK_COMPATIBILITY
939 #ifndef DOXYGEN_SHOULD_SKIP_THIS
940 Malloc_real m_mem_cubic;
942 bool m_external_alloc{
false};
947 #ifndef DOXYGEN_SHOULD_SKIP_THIS
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
1077 this->
build( x, 1, y, 1, yp, 1, n );
1089 vector<real_type>
const & x,
1090 vector<real_type>
const & y,
1091 vector<real_type>
const & yp
1104 bool transpose =
false
1109 #ifdef SPLINES_BACK_COMPATIBILITY
1111 integer numPoints()
const {
return m_npts; }
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]; }
1148 #ifndef DOXYGEN_SHOULD_SKIP_THIS
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};
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;
1172 mutable integer m_last_interval_x;
1173 mutable integer m_last_interval_y;
1179 void init_last_interval_x();
1180 void init_last_interval_y();
1184 {
return i*ldZ + j; }
1188 {
return i + ldZ*j; }
1192 {
return this->ipos_C(i,j,m_ny); }
1196 {
return this->ipos_F(i,j,m_nx); }
1198 virtual void make_spline() = 0;
1204 bool fortran_storage,
1216 : m_mem(
"SplineSurf")
1219 this->init_last_interval_x();
1220 this->init_last_interval_y();
1313 string const &
name()
const {
return m_name; }
1340 {
return m_Z[size_t(this->ipos_C(i,j))]; }
1401 bool fortran_storage =
false,
1402 bool transposed =
false
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
1424 bool xyswp = (fortran_storage && transposed) ||
1425 (!fortran_storage && !transposed);
1429 &z.front(),
integer(xyswp ? y.size() : x.size()),
1431 fortran_storage, transposed
1441 bool fortran_storage =
false,
1442 bool transposed =
false
1460 vector<real_type>
const & z,
1463 bool fortran_storage =
false,
1464 bool transposed =
false
1466 this->
build( &z.front(), nx, ny, fortran_storage ? nx : ny, fortran_storage, transposed );
1473 setup( GenericContainer
const & gc );
1565 {
return this->
eval(x,y); }
1572 {
return this->
Dx(x,y); }
1579 {
return this->
Dy(x,y); }
1586 {
return this->
Dxx(x,y); }
1593 {
return this->
Dxy(x,y); }
1600 {
return this->
Dyy(x,y); }
1623 info( ostream_type & stream )
const
1624 { stream << this->
info() <<
'\n'; }
1631 #ifdef SPLINES_BACK_COMPATIBILITY
1632 integer numPointX()
const {
return m_nx; }
1633 integer numPointY()
const {
return m_ny; }
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; }
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"
1664#include "Splines/SplineVec.hxx"
1665#include "Splines/SplineSet.hxx"
1666#include "Splines/Splines1D.hxx"
1667#include "Splines/Splines2D.hxx"
1669#ifndef DOXYGEN_SHOULD_SKIP_THIS
1671namespace SplinesLoad {
1700#pragma GCC diagnostic pop
1703#pragma clang diagnostic pop
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 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
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
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