5#include <gsl/gsl_errno.h>
6#include <gsl/gsl_interp2d.h>
7#include <gsl/gsl_spline.h>
8#include <gsl/gsl_spline2d.h>
19 namespace INTERPOLATION {
32#ifndef SPLINE_FIDUCIAL_INTERPOL_TYPE
33#define SPLINE_FIDUCIAL_INTERPOL_TYPE gsl_interp_cspline
35#ifndef SPLINE_FIDUCIAL_INTERPOL_TYPE_2D
36#define SPLINE_FIDUCIAL_INTERPOL_TYPE_2D gsl_interp2d_bicubic
38#ifndef SPLINE_FIDUCIAL_SPLINE_WARNING
39#define SPLINE_FIDUCIAL_SPLINE_WARNING false
83 gsl_spline * spline{
nullptr};
87 std::vector<gsl_interp_accel *> xaccs{};
89 gsl_interp_accel * xacc{
nullptr};
92 const gsl_interp_type * interpoltype_used = SPLINE_FIDUCIAL_INTERPOL_TYPE;
100 std::string name{
"NoName"};
103 bool out_of_bounds_warning = SPLINE_FIDUCIAL_SPLINE_WARNING;
104 void out_of_bounds_check(
double x)
const;
107 void throw_error(std::string errormessage)
const;
119 std::string splinename =
"NoName",
120 const gsl_interp_type * interpoltype = SPLINE_FIDUCIAL_INTERPOL_TYPE);
124 std::string splinename =
"NoName",
125 const gsl_interp_type * interpoltype = SPLINE_FIDUCIAL_INTERPOL_TYPE);
131 explicit operator bool()
const;
137 std::string splinename =
"NoName",
138 const gsl_interp_type * interpoltype = SPLINE_FIDUCIAL_INTERPOL_TYPE);
142 std::string splinename =
"NoName",
143 const gsl_interp_type * interpoltype = SPLINE_FIDUCIAL_INTERPOL_TYPE);
149 double eval(
double x)
const;
177 gsl_spline2d * spline{
nullptr};
181 std::vector<gsl_interp_accel *> xaccs{};
182 std::vector<gsl_interp_accel *> yaccs{};
184 gsl_interp_accel * xacc{
nullptr};
185 gsl_interp_accel * yacc{
nullptr};
187 const gsl_interp2d_type * interpoltype_used = SPLINE_FIDUCIAL_INTERPOL_TYPE_2D;
200 std::string name{
"NoName"};
203 bool out_of_bounds_warning = SPLINE_FIDUCIAL_SPLINE_WARNING;
204 void out_of_bounds_check(
double x,
double y)
const;
209 *evalfunc)(
const gsl_spline2d *, double, double, gsl_interp_accel *, gsl_interp_accel *);
211 std::vector<evalfunc> derivfunc{gsl_spline2d_eval,
212 gsl_spline2d_eval_deriv_x,
213 gsl_spline2d_eval_deriv_xx,
214 gsl_spline2d_eval_deriv_y,
215 gsl_spline2d_eval_deriv_xy,
217 gsl_spline2d_eval_deriv_yy};
220 void throw_error(std::string errormessage)
const;
230 std::string splinename =
"NoName",
231 const gsl_interp2d_type * interpoltype = SPLINE_FIDUCIAL_INTERPOL_TYPE_2D);
235 std::string splinename =
"NoName",
236 const gsl_interp2d_type * interpoltype = SPLINE_FIDUCIAL_INTERPOL_TYPE_2D);
240 std::string splinename =
"NoName",
241 const gsl_interp2d_type * interpoltype = SPLINE_FIDUCIAL_INTERPOL_TYPE_2D);
247 explicit operator bool()
const;
255 std::string splinename =
"NoName",
256 const gsl_interp2d_type * interpoltype = SPLINE_FIDUCIAL_INTERPOL_TYPE_2D);
261 std::string splinename =
"NoName",
262 const gsl_interp2d_type * interpoltype = SPLINE_FIDUCIAL_INTERPOL_TYPE_2D);
267 std::string splinename =
"NoName",
268 const gsl_interp2d_type * interpoltype = SPLINE_FIDUCIAL_INTERPOL_TYPE_2D);
274 double eval(
double x,
double y)
const;
277 double eval_deriv(
double x,
double y,
int derivx,
int derivy)
const;
279 double deriv_x(
double x,
double y)
const;
285 double deriv_y(
double x,
double y)
const;
double deriv_xy(double x, double y) const
Get the value of the x,y-derivative of the spline.
GSLSpline2D & operator=(const GSLSpline2D &rhs)
void create(const double *x, const double *y, const double *z, int nx, int ny, std::string splinename="NoName", const gsl_interp2d_type *interpoltype=SPLINE_FIDUCIAL_INTERPOL_TYPE_2D)
Create a spline from pointers to x, y and z. z must have nx * ny elements.
double eval(double x, double y) const
Get the value of the spline (if out of bounds we use the closest value)
double eval_deriv(double x, double y, int derivx, int derivy) const
General method to fetch derivatives.
void free()
Free up memory associated with the spline.
double operator()(double x, double y) const
Overload of the () operator for easy evaluation of the spline.
double deriv_x(double x, double y) const
Get the value of the x-derivative of the spline.
double deriv_yy(double x, double y) const
Get the value of the second y-derivative of the spline.
DVector get_z_data()
Get the raw GSL data for z=f(x,y) used to create the spline.
std::pair< double, double > get_xrange() const
Get the x-range the spline was created on.
DVector get_y_data()
Get the raw GSL data for y used to create the spline.
double deriv_y(double x, double y) const
Get the value of the y-derivative of the spline.
void set_out_of_bounds_warning(bool v)
Turn on/off warnings if we try to evaluate out of bounds (we use closest value in that case)
std::string get_name() const
Get the name of the spline.
double deriv_xx(double x, double y) const
Get the value of the second x-derivative of the spline.
DVector get_x_data()
Get the raw GSL data for x used to create the spline.
std::pair< double, double > get_yrange() const
Get the y-range the spline was created on.
This is a wrapper class for easy use of GSL splines It is (OpenMP) thread safe as long as splines are...
DVector get_y_data()
Get the raw GSL data for y=f(x) used to create the spline.
double eval(double x) const
Get the value of the spline (if out of bounds we use the closest value)
void create(const double *x, const double *y, int nx, std::string splinename="NoName", const gsl_interp_type *interpoltype=SPLINE_FIDUCIAL_INTERPOL_TYPE)
Create a spline from pointers to x and y. Both must have nx elements.
double eval_deriv(double x, int deriv) const
double deriv_x(double x) const
Get the value of the first derivative of the spline.
double operator()(double x) const
Overload of the () operator for easy evaluation of the spline.
DVector get_x_data()
Get the raw GSL data for x used to create the spline.
GSLSpline & operator=(const GSLSpline &rhs)
std::string get_name() const
Get the name of the spline.
void free()
Free up memory associated with the spline.
void set_out_of_bounds_warning(bool v)
Turn on/off warnings if we try to evaluate out of bounds (we use closest value in that case)
double deriv_xx(double x) const
Get the value of the second derivative of the spline.
std::pair< double, double > get_xrange() const
Get the range the spline was created on.
std::vector< DVector > DVector2D
std::vector< double > DVector