-
Notifications
You must be signed in to change notification settings - Fork 16
/
splines.hpp
110 lines (87 loc) · 3.96 KB
/
splines.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#ifndef SPLINES_HPP
#define SPLINES_HPP
#include <vector>
// =============================================================================
namespace spline {
// =============================================================================
enum Node_e {
eUNIFORM,
eOPEN_UNIFORM ///< Connected to the first and last control points
};
}// END ESPline ================================================================
/**
* @class Spline
*
* @brief Handling spline curves of arbitrary dimensions
* @note This class use the efficient blossom algorithm to compute a position on
* the curve.
*
* @tparam Point_t : type of a point operators such as '+' '*' must be correctly
* overloaded. The default constructor must be defined to return the
* null vector (0, 0 ,0 ...)
* @tparam Real_t ; floating point reprensentation of the points
* (float, double etc.)
*/
template<typename Point_t, typename Real_t>
class Spline {
public:
/// Type of the nodal vector
/// @param k : order of the spline (minimum is two)
/// @param node_type : nodal vector type (uniform, open_uniform)
/// This will define the behavior of the spline with its control points
/// as well as its speed according to its parameter.
Spline(int k = 2, spline::Node_e node_type = spline::eOPEN_UNIFORM);
/// Set the position of the spline control points.
void set_ctrl_points(const std::vector<Point_t>& point);
/// Get the control points of the spline
void get_ctrl_points(std::vector<Point_t>& points) const;
/// The the nodal vector type
void set_node_type( spline::Node_e type);
/// Evaluate position of the spline
/// @param u : curve parameter ranging from [0; 1]
Point_t eval_f(Real_t u) const;
/// Evaluate speed of the spline
Point_t eval_df(Real_t u) const;
int get_order() const { return _k; }
private:
// -------------------------------------------------------------------------
/// @name Class tools
// -------------------------------------------------------------------------
void assert_splines() const;
/// set value and size of the nodal vector depending on the current number
/// of control points
void set_nodal_vector();
/// Set values of the nodal vector to be uniform
void set_node_to_uniform();
/// Set values of the nodal vector to be open uniform
void set_node_to_open_uniform();
/// Evaluate the equation of a splines using the blossom algorithm
/// @param u : the curve parameter which range from the values
/// [node[k-1]; node[point.size()]]
/// @param point : the control points which size must be at least equal to
/// the order of the spline (point.size() >= k)
/// @param k : the spline order (degree == k-1)
/// @param node : the nodal vector which defines the speed of the spline
/// parameter u. The nodal vector size must be equal to (k + point.size())
/// @param off : offset to apply to the nodal vector 'node' before reading
/// from it. this is useful to compute derivatives.
Point_t eval(Real_t u,
const std::vector<Point_t>& point,
int k,
const std::vector<Real_t>& node,
int off = 0) const;
Point_t eval_rec(Real_t u,
std::vector<Point_t> p_in,
int k,
std::vector<Real_t> node_in) const;
// -------------------------------------------------------------------------
/// @name attributes
// -------------------------------------------------------------------------
spline::Node_e _node_type; ///< Nodal vector type
int _k; ///< spline order
std::vector<Point_t> _point; ///< Control points
std::vector<Point_t> _vec; ///< Control points differences
std::vector<Real_t> _node; ///< Nodal vector
};
#include "splines.inl"
#endif // SPLINES_HPP