2 #ifndef vgl_cubic_spline_3d_h_ 3 #define vgl_cubic_spline_3d_h_ 28 # include <vcl_msvc_warnings.h> 40 std::vector<vgl_point_3d<Type> >
knots_;
54 Type
s()
const {
return s_;}
57 std::vector<vgl_point_3d<Type> >
knots()
const {
return knots_;}
66 Type
max_t()
const {
return static_cast<Type>(
knots_.size()-1);}
79 void coefficients(Type vm1, Type v0, Type v1, Type v2, Type& a0, Type& a1, Type& a2, Type& a3)
const;
82 void knot_indices(Type t,
unsigned& im1,
unsigned& i0,
unsigned& i1,
unsigned& i2, Type& u)
const;
100 Type& a0, Type& a1, Type& a2, Type& a3)
const{
101 a3= (2-s_)*v0+(s_-2)*v1-s_*vm1+s_*v2;
102 a2= (s_-3)*v0 + (3-2*s_)*v1 + 2*s_*vm1-s_*v2;
107 template <
class Type>
109 unsigned offset = static_cast<unsigned>(t);
111 if(offset == (static_cast<unsigned>(knots_.size())-1))
113 i0 = offset; i1 = offset+1;
118 im1 = static_cast<unsigned>(knots_.size()-1);
124 if(offset == static_cast<unsigned>(knots_.size()-2)){
132 u = t - static_cast<Type>(offset);
135 template <
class Type>
137 if(spl.
closed()!=closed_curve_)
return false;
138 if(spl.
s()!=s_)
return false;
139 std::vector<vgl_point_3d<Type> > knots = spl.
knots();
140 unsigned n = static_cast<unsigned>(knots.size());
141 if(n!= static_cast<unsigned>(knots_.size()))
return false;
142 for(
unsigned i =0; i<n; ++i)
143 if(knots[i] != knots_[i])
147 template <
class Type>
150 if(knots_.size() < 2)
152 assert(t>=Type(0) && t<=max_t());
153 unsigned im1, i0, i1, i2;
155 knot_indices(t, im1, i0, i1, i2, u);
159 Type u2 = u*u, u3 = u2*u;
161 Type a0x, a1x, a2x, a3x;
162 Type a0y, a1y, a2y, a3y;
163 Type a0z, a1z, a2z, a3z;
164 coefficients(pm1.
x(), p0.x(), p1.
x(), p2.x(), a0x, a1x, a2x, a3x);
165 coefficients(pm1.
y(), p0.y(), p1.
y(), p2.y(), a0y, a1y, a2y, a3y);
166 coefficients(pm1.
z(), p0.z(), p1.
z(), p2.z(), a0z, a1z, a2z, a3z);
168 Type x = a3x*u3 + a2x*u2 + a1x*u + a0x;
169 Type y = a3y*u3 + a2y*u2 + a1y*u + a0y;
170 Type z = a3z*u3 + a2z*u2 + a1z*u + a0z;
175 template <
class Type>
177 Type zero = static_cast<Type>(0);
179 Type del = static_cast<Type>(0.01);
216 template <
class Type>
219 std::cout <<
"Bad ostream in write vgl_cubic_spline_3d to stream\n";
226 ostr << ic <<
' ' << s <<
'\n';
227 std::vector<vgl_point_3d<Type> > knots = spl.
knots();
228 for(
unsigned i =0; i<static_cast<unsigned>(knots.size()); i++){
230 ostr << p.
x() <<
',' << p.
y() <<
',' << p.
z() <<
'\n';
235 template <
class Type>
238 std::cout <<
"Bad istream in read vgl_cubic_spline_3d from stream\n";
247 std::vector<vgl_point_3d<Type> > knots;
251 while(istr >> x >> c){
253 std::cout <<
"Bad file format\n";
259 std::cout <<
"Bad file format\n";
270 #endif // vgl_cubic_spline_3d_h_ Type max_t() const
maximum value of the spline parameter.
vgl_vector_3d< Type > tangent(Type t) const
tangent to the curve at parameter t.
std::vector< vgl_point_3d< Type > > const & const_knots() const
vgl_cubic_spline_3d()
Default constructor.
direction vector in Euclidean 3D space
Represents a cartesian 3D point.
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...
std::ostream & operator<<(std::ostream &s, vgl_orient_box_3d< Type > const &p)
Write box to stream.
vgl_point_3d< 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_3d< Type > &spl) const
Equality operator.
a point in 3D nonhomogeneous space
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...
bool closed() const
accessors.
std::vector< vgl_point_3d< Type > > knots_
double length() const
Return the length of this vector.
bool closed_curve_
members.
Represents a Euclidean 3D plane.
std::vector< vgl_point_3d< Type > > knots() const
std::istream & operator>>(std::istream &is, vgl_orient_box_3d< Type > &p)
Read box from stream.
vgl_cubic_spline_3d(std::vector< vgl_point_3d< Type > > knots, Type s=Type(0.5), bool closed=false)
Construct from set of knots.
void set(Type px, Type py, Type pz)
Set x, y and z.
a plane in 3D nonhomogeneous space
vgl_plane_3d< Type > normal_plane(Type t)
normal plane to the curve at parameter t.
bool operator!=(vgl_cubic_spline_3d< Type >const &spl) const
void set_knots(std::vector< vgl_point_3d< Type > > const &knots, bool closed)