OpenWalnut  1.5.0dev
WBSpline.h
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #ifndef WBSPLINE_H
26 #define WBSPLINE_H
27 
28 #include <vector>
29 #include "core/common/math/linearAlgebra/WVectorFixed.h"
30 
31 
32 /**
33  * A B-spline.
34  * @author Patrick Oesterling
35  */
36 class WBSpline
37 {
38 public:
39  /**
40  * Constructor for the spline that takes the order and de Boor points while constructing a normalized knotVector automatically.
41  * \param order Order of the spline.
42  * \param deBoorPoints The de Boor points for the spline
43  */
44  WBSpline( int order, std::vector< WVector3d > deBoorPoints );
45 
46  /**
47  * Constructor for the spline that takes the order de Boor points and knots as arguments.
48  * \param order Order of the spline.
49  * \param deBoorPoints The de Boor points for the spline
50  * \param knots The knots for the spline
51  */
52  WBSpline( int order, std::vector< WVector3d > deBoorPoints, std::vector<double> knots );
53 
54  /**
55  * Empty destructor.
56  */
57  ~WBSpline();
58 
59  /**
60  * Returns the stored de Boor points.
61  * \return The stored de Boor points
62  */
63  std::vector< WVector3d > getDeBoorPoints();
64 
65  /**
66  * Returns the stored knots.
67  * \return The stored knots
68  */
69  std::vector<double> getKnots();
70 
71  /**
72  * Returns the order of the spline.
73  * \return The order of the spline
74  */
75  int getOrder();
76 
77  /**
78  * Sets new de Boor points for the spline.
79  * \param deBoorPoints The new de Boor points for the spline.
80  */
81  void setDeBoorPoints( std::vector< WVector3d > deBoorPoints );
82 
83  /**
84  * Sets new knots for the spline.
85  * \param knots The new knots for the spline.
86  */
87  void setKnots( std::vector<double> knots );
88 
89  /**
90  * Sets a new order for the spline.
91  * \param order The new order of the spline.
92  */
93  void setOrder( int order );
94 
95  /**
96  * Compute sample points on the spline for a given resolution.
97  * The sample points are stored in the vector given by the first argument.
98  * \param p The pointer for returning the sample points.
99  * \param resolution The resolution of the sample points.
100  */
101  void samplePoints( std::vector< WVector3d > *p, double resolution );
102 
103  /**
104  * Compute a single sample point on the spline for the given parameter.
105  * \param t parameter on spline curve.
106  * \return Sample point on the curve at t.
107  */
108  WVector3d f( double t );
109 
110 private:
111  int m_order; //!< The order of the spline.
112  std::vector< WVector3d > m_deBoorPoints; //!< The de Boor points of the spline.
113  std::vector<double> m_knots; //!< The knots of the spline.
114  double m_t; //!< The parameter value of the last spline evaluation i.e. the last call to f().
115 
116  /**
117  * Compute the alpha of the de Boor algorithm for the given parameters
118  * \param _i First recursion parameter.
119  * \param _j Second recursion parameter.
120  * \return De Boor alpha for (_i,_j)
121  */
122  double getAlpha_i_j( int _i, int _j );
123 
124  /**
125  * Compute a control point of the de Boor algorithm for the given parameters
126  * \param _i First recursion parameter.
127  * \param _j Second recursion parameter.
128  * \return De Boor control point at (_i,_j).
129  */
130  WVector3d controlPoint_i_j( int _i, int _j );
131 };
132 
133 #endif // WBSPLINE_H
A B-spline.
Definition: WBSpline.h:37
void setOrder(int order)
Sets a new order for the spline.
Definition: WBSpline.cpp:136
double m_t
The parameter value of the last spline evaluation i.e. the last call to f().
Definition: WBSpline.h:114
std::vector< WVector3d > getDeBoorPoints()
Returns the stored de Boor points.
Definition: WBSpline.cpp:111
void setKnots(std::vector< double > knots)
Sets new knots for the spline.
Definition: WBSpline.cpp:131
void samplePoints(std::vector< WVector3d > *p, double resolution)
Compute sample points on the spline for a given resolution.
Definition: WBSpline.cpp:141
WVector3d controlPoint_i_j(int _i, int _j)
Compute a control point of the de Boor algorithm for the given parameters.
Definition: WBSpline.cpp:162
int getOrder()
Returns the order of the spline.
Definition: WBSpline.cpp:121
WVector3d f(double t)
Compute a single sample point on the spline for the given parameter.
Definition: WBSpline.cpp:67
WBSpline(int order, std::vector< WVector3d > deBoorPoints)
Constructor for the spline that takes the order and de Boor points while constructing a normalized kn...
Definition: WBSpline.cpp:29
void setDeBoorPoints(std::vector< WVector3d > deBoorPoints)
Sets new de Boor points for the spline.
Definition: WBSpline.cpp:126
int m_order
The order of the spline.
Definition: WBSpline.h:111
std::vector< double > getKnots()
Returns the stored knots.
Definition: WBSpline.cpp:116
std::vector< double > m_knots
The knots of the spline.
Definition: WBSpline.h:113
~WBSpline()
Empty destructor.
Definition: WBSpline.cpp:63
double getAlpha_i_j(int _i, int _j)
Compute the alpha of the de Boor algorithm for the given parameters.
Definition: WBSpline.cpp:156
std::vector< WVector3d > m_deBoorPoints
The de Boor points of the spline.
Definition: WBSpline.h:112