MIDSX 0.1
A x-ray transport code system for dosimetry
Loading...
Searching...
No Matches
interpolators.h
1#ifndef MC_XRAY_TRANSPORT_SPLINE_H
2#define MC_XRAY_TRANSPORT_SPLINE_H
3
4#include <Eigen/Core>
5#include <unsupported/Eigen/Splines>
6
7
8namespace Interpolator {
9
16 public:
17 virtual ~Interpolator() = default;
18 virtual double operator()(double x) const = 0;
19 };
20
26 class Spline : public Interpolator{
27 public:
28 Spline() = default;
34 explicit Spline(const Eigen::MatrixXd &data);
35
42 double operator()(double x) const override;
43 private:
44 double scaledValue(double x) const;
45 Eigen::RowVectorXd scaledValues(Eigen::VectorXd const &x_vec) const;
46
47 Eigen::VectorXd x_vec_;
48 Eigen::VectorXd y_vec_;
49 double x_min_ = 0.0;
50 double x_max_ = 0.0;
51 Eigen::Spline<double, 1> spline_;
52 };
53
57 class LogLogSpline : public Spline {
58 public:
59 LogLogSpline() = default; // Default constructor
65 explicit LogLogSpline(const Eigen::Matrix<double, Eigen::Dynamic, 2> &data);
66
73 double operator()(double x) const override;
74 };
75
79 class Linear : public Interpolator {
80 public:
81 Linear() = default; // Default constructor
87 explicit Linear(const Eigen::Matrix<double, Eigen::Dynamic, 2> &data);
88
95 double operator()(double x) const override;
96 private:
97 Eigen::VectorXd x_vec_;
98 Eigen::VectorXd y_vec_;
99
100 bool isXSmallerThanMin(double x) const;
101 bool isXBiggerThanMax(double x) const;
102 int findIndexOfNextLargestValue(double x) const;
103 double calculateInterpolatedY(int idx, double x) const;
104 };
105
109 class LogLogLinear : public Linear {
110 public:
111 LogLogLinear() = default; // Default constructor
117 explicit LogLogLinear(const Eigen::Matrix<double, Eigen::Dynamic, 2> &data);
118
125 double operator()(double x) const override;
126 };
127}
128
129#endif //MC_XRAY_TRANSPORT_SPLINE_H
Abstract base class for interpolators.
Class which performs linear interpolation.
Linear(const Eigen::Matrix< double, Eigen::Dynamic, 2 > &data)
Constructor for the Linear class.
double operator()(double x) const override
Performs linear interpolation.
Class which performs linear interpolation on a log-log scale.
double operator()(double x) const override
Performs linear interpolation on a log-log scale.
LogLogLinear(const Eigen::Matrix< double, Eigen::Dynamic, 2 > &data)
Constructor for the LogLogLinear class.
Class which performs 3rd order spline interpolation on a log-log scale.
double operator()(double x) const override
Performs 3rd order spline interpolation on a log-log scale.
LogLogSpline(const Eigen::Matrix< double, Eigen::Dynamic, 2 > &data)
Constructor for the LogLogSpline class.
Class which performs 3rd order spline interpolation.
Spline(const Eigen::MatrixXd &data)
Constructor for the Spline class.
double operator()(double x) const override
Performs 3rd order spline interpolation.