Version: SMASH-3.1
smash::InterpolateData2DSpline Class Reference

#include <interpolation2D.h>

Represent a bicubic spline interpolation.

Definition at line 20 of file interpolation2D.h.

Public Member Functions

 InterpolateData2DSpline (const std::vector< double > &x, const std::vector< double > &y, const std::vector< double > &z)
 Interpolate function f given discrete samples f(x_i, y_i) = z_i. More...
 
 ~InterpolateData2DSpline ()
 Destructor. More...
 
double operator() (double xi, double yi) const
 Calculate bicubic interpolation for given x and y. More...
 

Private Attributes

double first_x_
 First x value. More...
 
double last_x_
 Last x value. More...
 
double first_y_
 First y value. More...
 
double last_y_
 Last y value. More...
 
gsl_interp_accel * xacc_
 GSL iterator for interpolation lookups in x direction. More...
 
gsl_interp_accel * yacc_
 GSL iterator for interpolation lookupin y direction. More...
 
gsl_spline2d * spline_
 GSL spline in 2D. More...
 

Constructor & Destructor Documentation

◆ InterpolateData2DSpline()

smash::InterpolateData2DSpline::InterpolateData2DSpline ( const std::vector< double > &  x,
const std::vector< double > &  y,
const std::vector< double > &  z 
)

Interpolate function f given discrete samples f(x_i, y_i) = z_i.

Parameters
xx-values.
yy-values.
zz-values
Returns
The interpolation function.

A bicubic spline interpolation is used. Values outside the given samples will use the outmost sample as a constant extrapolation.

Definition at line 16 of file interpolation2D.cc.

18  {
19  const size_t M = x.size();
20  const size_t N = y.size();
21 
22  if (z.size() != N * M) {
23  throw std::runtime_error(
24  "Dimensions not suitable for 2D interpolation. DIM(z) != DIM(x) * "
25  "DIM(y).");
26  }
27 
28  if (M < 4 || N < 4) {
29  throw std::runtime_error(
30  "Need at least 4 data points in each dimension for bicubic spline "
31  "interpolation.");
32  }
33 
34  // Assign lower and upper bounds for constant extrapolation
35  first_x_ = x.front();
36  last_x_ = x.back();
37  first_y_ = y.front();
38  last_y_ = y.back();
39 
40  // cast vectors into arrays, as GSL functions can only handle arrays
41  const double* xa = &x[0];
42  const double* ya = &y[0];
43  const double* za = &z[0];
44 
45  // Create accelerator objects (interpolation lookups)
46  xacc_ = gsl_interp_accel_alloc();
47  yacc_ = gsl_interp_accel_alloc();
48 
49  // Initialize bicubic spline interpolation
50  spline_ = gsl_spline2d_alloc(gsl_interp2d_bicubic, M, N);
51  gsl_spline2d_init(spline_, xa, ya, za, M, N);
52 }
double first_y_
First y value.
gsl_interp_accel * xacc_
GSL iterator for interpolation lookups in x direction.
gsl_spline2d * spline_
GSL spline in 2D.
double first_x_
First x value.
gsl_interp_accel * yacc_
GSL iterator for interpolation lookupin y direction.

◆ ~InterpolateData2DSpline()

smash::InterpolateData2DSpline::~InterpolateData2DSpline ( )

Destructor.

Definition at line 54 of file interpolation2D.cc.

54  {
55  gsl_spline2d_free(spline_);
56  gsl_interp_accel_free(xacc_);
57  gsl_interp_accel_free(yacc_);
58 }

Member Function Documentation

◆ operator()()

double smash::InterpolateData2DSpline::operator() ( double  xi,
double  yi 
) const

Calculate bicubic interpolation for given x and y.

Parameters
xiInterpolation argument in first dimension.
yiInterpolation argument in second dimension.
Returns
Interpolated value.

Definition at line 60 of file interpolation2D.cc.

60  {
61  // constant extrapolation at the edges
62  xi = (xi < first_x_) ? first_x_ : xi;
63  xi = (xi > last_x_) ? last_x_ : xi;
64  yi = (yi < first_y_) ? first_y_ : yi;
65  yi = (yi > last_y_) ? last_y_ : yi;
66 
67  // bicubic spline interpolation
68  return gsl_spline2d_eval(spline_, xi, yi, xacc_, yacc_);
69 }

Member Data Documentation

◆ first_x_

double smash::InterpolateData2DSpline::first_x_
private

First x value.

Definition at line 52 of file interpolation2D.h.

◆ last_x_

double smash::InterpolateData2DSpline::last_x_
private

Last x value.

Definition at line 54 of file interpolation2D.h.

◆ first_y_

double smash::InterpolateData2DSpline::first_y_
private

First y value.

Definition at line 56 of file interpolation2D.h.

◆ last_y_

double smash::InterpolateData2DSpline::last_y_
private

Last y value.

Definition at line 58 of file interpolation2D.h.

◆ xacc_

gsl_interp_accel* smash::InterpolateData2DSpline::xacc_
private

GSL iterator for interpolation lookups in x direction.

Definition at line 61 of file interpolation2D.h.

◆ yacc_

gsl_interp_accel* smash::InterpolateData2DSpline::yacc_
private

GSL iterator for interpolation lookupin y direction.

Definition at line 63 of file interpolation2D.h.

◆ spline_

gsl_spline2d* smash::InterpolateData2DSpline::spline_
private

GSL spline in 2D.

Definition at line 65 of file interpolation2D.h.


The documentation for this class was generated from the following files: