2 #ifndef vgl_cubic_spline_2d_h_ 3 #define vgl_cubic_spline_2d_h_ 27 # include <vcl_msvc_warnings.h> 37 std::vector<vgl_point_2d<Type> >
knots_;
50 Type
s()
const {
return s_;}
51 std::vector<vgl_point_2d<Type> >
knots()
const {
return knots_;}
58 Type
max_t()
const {
return static_cast<Type>(
knots_.size()-1);}
74 void coefficients(Type vm1, Type v0, Type v1, Type v2, Type& a0, Type& a1, Type& a2, Type& a3)
const;
77 void knot_indices(Type t,
unsigned& im1,
unsigned& i0,
unsigned& i1,
unsigned& i2, Type& u)
const;
89 Type& a0, Type& a1, Type& a2, Type& a3)
const{
90 a3= (2-s_)*v0+(s_-2)*v1-s_*vm1+s_*v2;
91 a2= (s_-3)*v0 + (3-2*s_)*v1 + 2*s_*vm1-s_*v2;
98 unsigned offset = static_cast<unsigned>(t);
100 if(offset == (static_cast<unsigned>(knots_.size())-1))
102 i0 = offset; i1 = offset+1;
107 im1 = static_cast<unsigned>(knots_.size()-1);
113 if(offset == static_cast<unsigned>(knots_.size()-2)){
121 u = t - static_cast<Type>(offset);
124 template <
class Type>
126 if(spl.
closed()!=closed_curve_)
return false;
127 if(spl.
s()!=s_)
return false;
128 std::vector<vgl_point_2d<Type> > knots = spl.
knots();
129 unsigned n = static_cast<unsigned>(knots.size());
130 if(n!= knots_.size())
return false;
131 for(
unsigned i =0; i<n; ++i)
132 if(knots[i] != knots_[i])
137 template <
class Type>
140 if(knots_.size() < 2)
142 assert(t>=Type(0) && t<=max_t());
143 unsigned im1, i0, i1, i2;
145 knot_indices(t, im1, i0, i1, i2, u);
149 Type u2 = u*u, u3 = u2*u;
151 Type a0x, a1x, a2x, a3x;
152 Type a0y, a1y, a2y, a3y;
153 coefficients(pm1.
x(), p0.x(), p1.
x(), p2.x(), a0x, a1x, a2x, a3x);
154 coefficients(pm1.
y(), p0.y(), p1.
y(), p2.y(), a0y, a1y, a2y, a3y);
156 Type x = a3x*u3 + a2x*u2 + a1x*u + a0x;
157 Type y = a3y*u3 + a2y*u2 + a1y*u + a0y;
161 template <
class Type>
163 Type zero = static_cast<Type>(0);
165 Type del = static_cast<Type>(0.01);
202 template <
class Type>
205 std::cout <<
"Bad ostream in write vgl_cubic_spline_2d to stream\n";
212 ostr << ic <<
' ' << s <<
'\n';
213 std::vector<vgl_point_2d<Type> > knots = spl.
knots();
214 for(
unsigned i =0; i<static_cast<unsigned>(knots.size()); i++){
216 ostr << p.
x() <<
',' << p.
y() <<
'\n';
221 template <
class Type>
224 std::cout <<
"Bad istream in read vgl_cubic_spline_2d from stream\n";
233 std::vector<vgl_point_2d<Type> > knots;
237 while(istr >> x >> c){
239 std::cout <<
"Bad file format\n";
250 #endif // vgl_cubic_spline_2d_h_ void knot_indices(Type t, unsigned &im1, unsigned &i0, unsigned &i1, unsigned &i2, Type &u) const
the indices for the knots bounding the interval containing t, u is the local parameter in the interva...
a point in 2D nonhomogeneous space
vgl_cubic_spline_2d(std::vector< vgl_point_2d< Type > > knots, Type s=Type(0.5), bool closed=false)
Construct from set of knots.
std::vector< vgl_point_2d< Type > > knots() const
bool operator!=(vgl_cubic_spline_2d< Type >const &spl) const
void set_knots(std::vector< vgl_point_2d< Type > > const &knots, bool closed)
vgl_cubic_spline_2d()
Default constructor - does not initialise!.
double length() const
Return the length of this vector.
std::ostream & operator<<(std::ostream &s, vgl_orient_box_3d< Type > const &p)
Write box to stream.
void coefficients(Type vm1, Type v0, Type v1, Type v2, Type &a0, Type &a1, Type &a2, Type &a3) const
The next two accessors are useful for interpolating other quantities than position with the same spat...
vgl_point_2d< Type > operator()(Type t) const
function value at t, where 0 <= t <= n-1 and n is the number of knots.
bool operator==(const vgl_cubic_spline_2d< Type > &spl) const
Equality operator.
bool closed() const
accessors.
void set(Type px, Type py)
Set x and y.
vgl_vector_2d< Type > tangent(Type t) const
direction vector in Euclidean 2D space
std::vector< vgl_point_2d< Type > > knots_
std::istream & operator>>(std::istream &is, vgl_orient_box_3d< Type > &p)
Read box from stream.
Represents a cartesian 2D point.
Type max_t() const
maximum value of the spline parameter.