OpenWalnut  1.5.0dev
WBSplineSurface.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 WBSPLINESURFACE_H
26 #define WBSPLINESURFACE_H
27 
28 #include <vector>
29 
30 #include "core/common/math/linearAlgebra/WVectorFixed.h"
31 
32 /**
33  * A B-spline surface.
34  * @author Patrick Oesterling
35  *
36  numDeBoorPoints1 -> t-parameter (knots1)
37  0 1 2 3 4 5 .....
38  n ___________________________
39  u | | | | | | | | | |
40  m |__________________________|
41  D | | | | | | | | | |
42  e |__________________________|
43  B | | | | | | | | | |
44  o |__________________________|
45  o | | | | | | | | | |
46  r |__________________________|
47  P | | | | | | | | | |
48  2 |__________________________|
49  -> | | | | | | | | | |
50  u |__________________________|
51  - | | | | | | | | | |
52  param|__________________________|
53 (knots2)| | | | | | | | | |
54  |__________________________|
55 
56 
57 */
59 {
60 public:
61  /**
62  * Constructor for the surface that takes the orders and de Boor points of the underlying splines
63  * while constructing normalized knotVectors automatically.
64  * \param order1 Order of the spline in first direction.
65  * \param order2 Order of the spline in second direction.
66  * \param deBoorPoints The de Boor points for the spline
67  * \param numDeBoorPoints1 The number of de Boor points for the spline in the first direction.
68  * \param numDeBoorPoints2 The number of de Boor points for the spline in the second direction.
69  */
70  WBSplineSurface( int order1,
71  int order2,
72  std::vector< WVector3d > deBoorPoints,
73  int numDeBoorPoints1,
74  int numDeBoorPoints2 );
75  /**
76  * Constructor for the surface that takes the orders, de Boor points
77  * knots of the underlying splines.
78  * \param order1 Order of the spline in first direction.
79  * \param order2 Order of the spline in second direction.
80  * \param deBoorPoints The de Boor points for the spline
81  * \param numDeBoorPoints1 The number of de Boor points for the spline in the first direction.
82  * \param numDeBoorPoints2 The number of de Boor points for the spline in the second direction.
83  * \param knots1 The new knots for the spline in the first direction.
84  * \param knots2 The new knots for the spline in the second direction.
85  */
86  WBSplineSurface( int order1,
87  int order2,
88  std::vector< WVector3d > deBoorPoints,
89  int numDeBoorPoints1,
90  int numDeBoorPoints2,
91  std::vector<double> knots1,
92  std::vector<double> knots2 );
93 
94  /**
95  * Empty destructor.
96  */
98 
99  /**
100  * Returns the stored de Boor points.
101  * \return All de Boor points of the B-spline
102  */
103  std::vector< WVector3d > getDeBoorPoints();
104 
105  /**
106  * Returns the number of de Boor points in the first direction.
107  * \return Number of de Boor points in first direction
108  */
109  int getNumDeBoorPoints1();
110  /**
111  * Returns the number of de Boor points in the second direction.
112  * \return Number of de Boor points in second direction
113  */
114  int getNumDeBoorPoints2();
115 
116  /**
117  * Returns the stored knots in the first direction.
118  * \return Number of knots in the first direction
119  */
120  std::vector<double> getKnots1();
121 
122  /**
123  * Returns the stored knots in the second direction.
124  * \return Number of knots in the second direction
125  */
126  std::vector<double> getKnots2();
127 
128  /**
129  * Returns the order of the spline in the first direction.
130  * \return The order of the spline in the first direction.
131  */
132  int getOrder1();
133 
134  /**
135  * Returns the order of the spline in the second direction.
136  * \return The order of the spline in the second direction.
137  */
138  int getOrder2();
139 
140  /**
141  * Returns the number of sample points in the first direction that were used for the last call to samplePoints().
142  * \return the number of sample points in the first direction that were used for the last call to samplePoints().
143  */
144  int getNumSamplePointsT();
145 
146  /**
147  * Returns the number of sample points in the second direction that were used for the last call to samplePoints().
148  * \return the number of sample points in the second direction that were used for the last call to samplePoints().
149  */
150  int getNumSamplePointsU();
151 
152  /**
153  * Sets new de Boor points for the splines.
154  * \param deBoorPoints The new de Boor points for the splines.
155  * \param numDeBoorPoints1 The number of de Boor points for the spline in the first direction.
156  * \param numDeBoorPoints2 The number of de Boor points for the spline in the second direction.
157  */
158  void setDeBoorPoints( std::vector< WVector3d > deBoorPoints, int numDeBoorPoints1, int numDeBoorPoints2 );
159 
160  /**
161  * Sets new knots for the spline in the first direction.
162  * \param knots The new knots for the spline in the first direction.
163  */
164  void setKnots1( std::vector<double> knots );
165 
166  /**
167  * Sets new knots for the spline in the second direction.
168  * \param knots The new knots for the spline in the second direction.
169  */
170  void setKnots2( std::vector<double> knots );
171 
172  /**
173  * Sets a new order for the spline in the first direction.
174  * \param order The new order of the spline in the first direction.
175  */
176  void setOrder1( int order );
177 
178  /**
179  * Sets a new order for the spline in the second direction.
180  * \param order The new order of the spline in the second direction.
181  */
182  void setOrder2( int order );
183 
184  /**
185  * Compute sample points on the spline surface for a given resolution in the two directions.
186  * The sample points are stored in the vector given by the first argument.
187  * \param points The pointer for returning the sample points.
188  * \param tResolution The resolution in the first direction.
189  * \param uResolution The resolution in the second direction.
190  */
191  void samplePoints( std::vector< WVector3d > *points, double tResolution, double uResolution );
192 
193 private:
194  /**
195  * Compute a single sample point on the surface for the given parameters.
196  * \param t parameter for first direction.
197  * \param u parameter for second direction.
198  * \return Sample point at (t,u).
199  */
200  WVector3d f( double t, double u );
201 
202  int m_order1; //!< order for the spline in the first direction.
203  int m_order2; //!< order for the spline in the second direction.
204  int m_numDeBoorPoints1; //!< number of de Boor points for the spline in the first direction.
205  int m_numDeBoorPoints2; //!< number of de Boor points for the spline in the second direction.
206  int m_numSamplePointsT; //!< The number of sample points in the first direction that were used for the last call to samplePoints().
207  int m_numSamplePointsU; //!< The number of sample points in the second direction that were used for the last call to samplePoints().
208 
209  std::vector< WVector3d > m_deBoorPoints; //!< The de Boor points of the splines.
210 
211  std::vector<double> m_knots1; //!< The knots of the spline in the first direction.
212  std::vector<double> m_knots2; //!< The knots of the spline in the second direction.
213 };
214 
215 #endif // WBSPLINESURFACE_H
A B-spline surface.
~WBSplineSurface()
Empty destructor.
std::vector< double > m_knots1
The knots of the spline in the first direction.
void setDeBoorPoints(std::vector< WVector3d > deBoorPoints, int numDeBoorPoints1, int numDeBoorPoints2)
Sets new de Boor points for the splines.
int m_numDeBoorPoints1
number of de Boor points for the spline in the first direction.
int m_numSamplePointsU
The number of sample points in the second direction that were used for the last call to samplePoints(...
int m_numSamplePointsT
The number of sample points in the first direction that were used for the last call to samplePoints()...
void setKnots1(std::vector< double > knots)
Sets new knots for the spline in the first direction.
std::vector< double > getKnots1()
Returns the stored knots in the first direction.
int m_order1
order for the spline in the first direction.
WVector3d f(double t, double u)
Compute a single sample point on the surface for the given parameters.
int getNumSamplePointsT()
Returns the number of sample points in the first direction that were used for the last call to sample...
void setOrder1(int order)
Sets a new order for the spline in the first direction.
int m_numDeBoorPoints2
number of de Boor points for the spline in the second direction.
std::vector< WVector3d > getDeBoorPoints()
Returns the stored de Boor points.
void samplePoints(std::vector< WVector3d > *points, double tResolution, double uResolution)
Compute sample points on the spline surface for a given resolution in the two directions.
int getNumSamplePointsU()
Returns the number of sample points in the second direction that were used for the last call to sampl...
int getNumDeBoorPoints1()
Returns the number of de Boor points in the first direction.
int getNumDeBoorPoints2()
Returns the number of de Boor points in the second direction.
std::vector< WVector3d > m_deBoorPoints
The de Boor points of the splines.
int getOrder2()
Returns the order of the spline in the second direction.
std::vector< double > m_knots2
The knots of the spline in the second direction.
WBSplineSurface(int order1, int order2, std::vector< WVector3d > deBoorPoints, int numDeBoorPoints1, int numDeBoorPoints2)
Constructor for the surface that takes the orders and de Boor points of the underlying splines while ...
void setOrder2(int order)
Sets a new order for the spline in the second direction.
void setKnots2(std::vector< double > knots)
Sets new knots for the spline in the second direction.
int getOrder1()
Returns the order of the spline in the first direction.
std::vector< double > getKnots2()
Returns the stored knots in the second direction.
int m_order2
order for the spline in the second direction.