5 #ifndef CNOID_UTIL_UNIFORM_CUBIC_BSPLINE_H_INCLUDED
6 #define CNOID_UTIL_UNIFORM_CUBIC_BSPLINE_H_INCLUDED
12 template <
class ElementType>
19 Eigen::Matrix<ElementType, 4, 4>
M;
23 : numSamples(numSamples),
32 void findKnotPosition(ElementType t,
int* out_knot, Eigen::Matrix<ElementType, 1, 4>& out_u) {
34 out_knot[1] = t * dtinv;
35 out_knot[0] = out_knot[1] - 1;
36 out_knot[2] = out_knot[1] + 1;
37 out_knot[3] = out_knot[1] + 2;
46 }
else if(out_knot[3] >= numSamples){
47 out_knot[3] = numSamples - 1;
48 if(out_knot[2] >= numSamples){
49 out_knot[2] = numSamples - 1;
50 if(out_knot[1] >= numSamples){
51 out_knot[1] = numSamples - 1;
56 t = fmod(t * dtinv, 1.0);
58 ElementType t2 = t * t;
59 out_u << (t2 * t), t2, t, 1.0;
64 template <
class ElementType>
78 Eigen::Matrix<ElementType, 1, 4> u;
81 Eigen::Matrix<ElementType, 4, 1> p;
82 p << x[knot[0]], x[knot[1]], x[knot[2]], x[knot[3]];
89 template <
class ContainerType,
class VectorType,
class ElementType>
93 const ContainerType& container;
98 typedef Eigen::Matrix<ElementType, Eigen::Dynamic, 1>
SolutionType;
102 container(container),
103 vectorSize(vectorSize) {
109 Eigen::Matrix<ElementType, 1, 4> u;
112 typedef Eigen::Matrix<ElementType, 4, Eigen::Dynamic> ValueMatrix;
113 ValueMatrix P(4, vectorSize);
115 for(
int i=0; i < 4; ++i){
116 VectorType value = container[knot[i]];
117 typename ValueMatrix::RowXpr p = P.row(i);
118 for(
int j=0; j < vectorSize; ++j){