27#ifndef EASY3D_CORE_SPLINE_CURVE_INTERPOLATION_H
28#define EASY3D_CORE_SPLINE_CURVE_INTERPOLATION_H
34#include <easy3d/core/spline_interpolation.h>
58 template<
typename Po
int_t>
61 typedef typename Point_t::FT FT;
75 left_value_(0.0), right_value_(0.0), dim_(0), largest_t_(0.0) {
83 BoundaryType right, FT right_value);
93 void set_points(
const std::vector<FT> ¶meters,
const std::vector<Point_t> &points,
bool cubic_spline =
true);
103 void set_points(
const std::vector<Point_t> &points,
bool cubic_spline =
true);
110 Point_t
eval_f(FT u)
const;
116 BoundaryType left_, right_;
117 FT left_value_, right_value_;
120 std::vector< SplineInterpolation<FT> > interpolators_;
129 template<
typename Po
int_t>
132 typename SplineCurveInterpolation<Point_t>::BoundaryType right,
134 assert(interpolators_.size() == 0);
137 left_value_ = left_value;
138 right_value_ = right_value;
142 template<
typename Po
int_t>
144 const std::vector<Point_t> &input_points,
bool cubic_spline) {
145 if (input_parameters.empty() || input_parameters.size() != input_points.size())
149 std::vector<FT> parameters;
150 std::vector<Point_t> points;
151 for (std::size_t i=0; i<input_parameters.size(); ++i) {
152 const FT para = input_parameters[i];
153 if (i == 0 || para > parameters.back()) {
154 parameters.push_back(para);
155 points.push_back(input_points[i]);
158 const auto diff = input_points.size() - points.size();
159 LOG_IF(diff > 0, WARNING) << diff <<
" data points discarded because the input has to be monotonously increasing";
161 dim_ = points[0].dimension();
162 largest_t_ = parameters.back();
165 std::vector< std::vector<FT> > coords(dim_, std::vector<FT>(points.size()));
168 for (std::size_t i = 0; i < points.size(); ++i) {
169 const auto &p = points[i];
172 for (std::size_t j = 0; j<dim_; ++j)
177 interpolators_.resize(dim_);
178 for (std::size_t i=0; i<dim_; ++i) {
180 interpolators_[i].set_boundary(
188 interpolators_[i].set_data(parameters, coords[i]);
193 template<
typename Po
int_t>
195 if (points.size() < 2)
199 std::vector<FT> parameters(points.size(), FT(0));
202 for (std::size_t i = 1; i < points.size(); ++i) {
203 const auto &p = points[i];
208 set_points(parameters, points, cubic_spline);
212 template<
typename Po
int_t>
215 for (std::size_t i=0; i<dim_; ++i)
216 p[i] = interpolators_[i](u * largest_t_);
Cubic spline curve interpolation for arbitrary dimensions.
Definition: spline_curve_interpolation.h:59
void set_points(const std::vector< FT > ¶meters, const std::vector< Point_t > &points, bool cubic_spline=true)
Definition: spline_curve_interpolation.h:143
SplineCurveInterpolation()
Definition: spline_curve_interpolation.h:74
void set_boundary(BoundaryType left, FT left_value, BoundaryType right, FT right_value)
Definition: spline_curve_interpolation.h:130
Point_t eval_f(FT u) const
Definition: spline_curve_interpolation.h:213
Cubic spline interpolation.
Definition: spline_interpolation.h:85
Definition: collider.cpp:182
T distance(const Vec< N, T > &v1, const Vec< N, T > &v2)
Computes the distance between two vectors/points.
Definition: vec.h:295