15 template<
class T,
class U = T>
28 func_ = std::make_shared<CubicHermiteSpline<Vector1d>>(1, std::map<double, std::pair<Vector1d, Vector1d>>{});
39 func_ = std::make_shared<CubicHermiteSpline<Vector1d>>(*inst.
func_);
43 virtual std::shared_ptr<Interpolator<T, U>>
clone()
const override
53 virtual void appendPoint(
const std::pair<double, T> & point)
override
63 throw std::out_of_range(
"[CubicInterpolator] Number of points should be 2 or more: "
64 + std::to_string(this->
points_.size()));
69 auto it = this->
points_.begin();
70 for(
size_t i = 0; i < this->
points_.size(); i++)
72 func_->appendPoint(std::make_pair(
73 it->first, std::make_pair((
Vector1d() <<
static_cast<double>(i)).finished(), Vector1d::Zero())));
77 func_->setDomainLowerLimit(this->
points_.begin()->first);
86 size_t idx =
func_->index(t);
87 double ratio = (*func_)(t)[0] -
static_cast<double>(idx);
88 return interpolate<T>(std::next(this->
points_.begin(), idx)->second,
89 std::next(this->points_.begin(), idx + 1)->second, std::clamp(ratio, 0.0, 1.0));
98 virtual U
derivative(
double t,
int order = 1)
const override
100 size_t idx =
func_->index(t);
101 double ratio = (*func_)(t)[0] -
static_cast<double>(idx);
102 return func_->derivative(t, order)[0]
103 * interpolateDerivative<T, U>(std::next(this->
points_.begin(), idx)->second,
104 std::next(this->points_.begin(), idx + 1)->second, std::clamp(ratio, 0.0, 1.0),
110 std::shared_ptr<CubicHermiteSpline<Vector1d>>
func_;
virtual U derivative(double t, int order=1) const override
Calculate the derivative of interpolated value.
virtual std::shared_ptr< Interpolator< T, U > > clone() const override
Clone this instance and get shared pointer.
virtual void appendPoint(const std::pair< double, T > &point) override
Add point.
std::shared_ptr< CubicHermiteSpline< Vector1d > > func_
Function to calculate the ratio of interpolation points.
CubicInterpolator(const CubicInterpolator &inst)
Copy constructor.
Eigen::Matrix< double, 1, 1 > Vector1d
1D vector
virtual void calcCoeff() override
Calculate coefficients.
CubicInterpolator(const std::map< double, T > &points={})
Constructor.
virtual T operator()(double t) const override
Calculate interpolated value.
Interpolator of a sequence of waypoints.
const std::map< double, T > & points() const
Get points.
std::map< double, T > points_
Times and values to be interpolated.