OpenWalnut  1.5.0dev
WBSplineSurface.cpp
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 #include <vector>
26 
27 #include "WBSplineSurface.h"
28 #include "WBSpline.h"
29 
30 
32  int order2,
33  std::vector< WVector3d > deBoorPoints,
34  int numDeBoorPoints1,
35  int numDeBoorPoints2 )
36 {
37  m_order1 = order1;
38  m_order2 = order2;
39  m_deBoorPoints = deBoorPoints;
40  m_numDeBoorPoints1 = numDeBoorPoints1;
41  m_numDeBoorPoints2 = numDeBoorPoints2;
42 
43  //define a normalized knotVector1
44  int n = m_numDeBoorPoints1;
45  int k = m_order1;
46  for( int i = 0; i < ( n + k ); i++ )
47  {
48  int tempKnot = 0;
49  if( i < k )
50  tempKnot = k - 1;
51  if( ( i >= k ) && ( i < n ) )
52  tempKnot = i;
53  if( i >= n )
54  tempKnot = n;
55 
56  m_knots1.push_back( tempKnot );
57  }
58 
59  //define a normalized knotVector2
61  k = m_order2;
62  for( int i = 0; i < ( n + k ); i++ )
63  {
64  int tempKnot = 0;
65  if( i < k )
66  tempKnot = k - 1;
67  if( ( i >= k ) && ( i < n ) )
68  tempKnot = i;
69  if( i >= n )
70  tempKnot = n;
71 
72  m_knots2.push_back( tempKnot );
73  }
74 }
75 
77  int order2,
78  std::vector< WVector3d > deBoorPoints,
79  int numDeBoorPoints1,
80  int numDeBoorPoints2,
81  std::vector<double> knots1,
82  std::vector<double> knots2 )
83 {
84  m_order1 = order1;
85  m_order2 = order2;
86  m_deBoorPoints = deBoorPoints;
87  m_numDeBoorPoints1 = numDeBoorPoints1;
88  m_numDeBoorPoints2 = numDeBoorPoints2;
89  m_knots1 = knots1;
90  m_knots2 = knots2;
91 }
92 
94 {
95 }
96 
97 WVector3d WBSplineSurface::f( double _t, double _u )
98 {
99  // numDeBoorPoints1 -> t-parameter (knots1)
100  // n 0,0 _____________x_____________
101  // u | | | | | | | | | |
102  // m |_____________x____________|
103  // D | | | | | | | | | |
104  // e |_____________x____________| first all splines with t-param
105  // B | | | | | | | | | | then final spline with u-param
106  // o |_____________x____________|
107  // o | | | | | | | | | |
108  // r |____________[x]___________| f(t, u)
109  // P | | | | | | | | | |
110  // 2 |_____________x____________|
111  // -> | | | | | | | | | |
112  // u |_____________x____________|
113  // - | | | | | | | | | |
114  // param|_____________x____________|
115  // (knots2)| | | | | | | | | |
116  // |_____________x____________|
117 
118  std::vector< WVector3d > uSplineDeBoorPoints;
119 
120  for( int row = 0; row < m_numDeBoorPoints2; row++ )
121  {
122  std::vector< WVector3d > tSplineDeBoorPoints;
123 
124  for( int col = 0; col < m_numDeBoorPoints1; col++ )
125  {
126  tSplineDeBoorPoints.push_back( m_deBoorPoints[row * m_numDeBoorPoints1 + col] );
127  }
128 
129  WBSpline tSpline( m_order1, tSplineDeBoorPoints );
130  WVector3d dmyArray = tSpline.f( _t );
131 
132  uSplineDeBoorPoints.push_back( WVector3d( dmyArray[0], dmyArray[1], dmyArray[2] ) );
133  }
134 
135  WBSpline uSpline( m_order2, uSplineDeBoorPoints );
136  return uSpline.f( _u );
137 }
138 
139 std::vector< WVector3d > WBSplineSurface::getDeBoorPoints()
140 {
141  return m_deBoorPoints;
142 }
143 
145 {
146  return m_numDeBoorPoints1;
147 }
148 
150 {
151  return m_numDeBoorPoints2;
152 }
153 
154 std::vector<double> WBSplineSurface::getKnots1()
155 {
156  return m_knots1;
157 }
158 
159 std::vector<double> WBSplineSurface::getKnots2()
160 {
161  return m_knots2;
162 }
163 
165 {
166  return m_order1;
167 }
168 
170 {
171  return m_order2;
172 }
173 
175 {
176  return m_numSamplePointsT;
177 }
178 
180 {
181  return m_numSamplePointsU;
182 }
183 
184 void WBSplineSurface::setDeBoorPoints( std::vector< WVector3d > deBoorPoints, int numDeBoorPoints1, int numDeBoorPoints2 )
185 {
186  m_deBoorPoints = deBoorPoints;
187  m_numDeBoorPoints1 = numDeBoorPoints1;
188  m_numDeBoorPoints2 = numDeBoorPoints2;
189 }
190 
191 void WBSplineSurface::setKnots1( std::vector<double> knots )
192 {
193  m_knots1 = knots;
194 }
195 
196 void WBSplineSurface::setKnots2( std::vector<double> knots )
197 {
198  m_knots2 = knots;
199 }
200 
201 void WBSplineSurface::setOrder1( int order )
202 {
203  m_order1 = order;
204 }
205 
206 void WBSplineSurface::setOrder2( int order )
207 {
208  m_order2 = order;
209 }
210 
211 void WBSplineSurface::samplePoints( std::vector< WVector3d > *points, double tResolution, double uResolution )
212 {
213  double currentT = m_knots1[0];
214  double currentU = m_knots2[0];
215  double deltaT = tResolution;
216  double deltaU = uResolution;
217 
218 
219  int stepsT = static_cast< int >( ( m_knots1[m_knots1.size() - 1] - m_knots1[0] ) / deltaT + 1 );
220  m_numSamplePointsT = stepsT;
221  int stepT = 0;
222  int stepsU = static_cast< int >( ( m_knots2[m_knots2.size() - 1] - m_knots2[0] ) / deltaU + 1 );
223  m_numSamplePointsU = stepsU;
224  int stepU = 0;
225 
226  for( stepU = 0; stepU < stepsU; stepU++ )
227  {
228  currentU = m_knots2[0] + stepU * deltaU;
229  for( stepT = 0; stepT < stepsT; stepT++ )
230  {
231  currentT = m_knots1[0] + stepT * deltaT;
232  WVector3d samplePoint = f( currentT, currentU );
233  points->push_back( samplePoint );
234  }
235  }
236 
237  return;
238 }
~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.
A B-spline.
Definition: WBSpline.h:37
WVector3d f(double t)
Compute a single sample point on the spline for the given parameter.
Definition: WBSpline.cpp:67