BALL  1.4.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
cubicSpline2D.h
Go to the documentation of this file.
1 #ifndef BALL_MATHS_CUBICSPLINE2D_H
2 #define BALL_MATHS_CUBICSPLINE2D_H
3 
4 #include <set>
5 #include <map>
6 
7 #ifndef BALL_MATHS_CUBICSPLINE1D_H
9 #endif
10 
11 #ifndef BALL_COMMON_EXCEPTION_H
12 #include <BALL/COMMON/exception.h>
13 #endif
14 
15 namespace BALL
16 {
18  {
19  public:
20 
21  static const int VERBOSITY_LEVEL_DEBUG;
22  static const int VERBOSITY_LEVEL_CRITICAL;
23 
25 
26  //@}
30 
33  CubicSpline2D();
34 
35 
52  CubicSpline2D(const std::vector<std::vector<float> >& sample_positions_x,
53  const std::vector<float>& sample_positions_y,
54  const std::vector<std::vector<float> >& sample_values,
55  bool return_average = false,
56  bool is_natural = true,
57  const std::vector<float>& x_lower_derivatives = std::vector<float>(),
58  const std::vector<float>& x_upper_derivatives = std::vector<float>(),
59  float y_lower_derivative = 0.,
60  float y_upper_derivative = 0.,
61  int verbosity = VERBOSITY_LEVEL_DEBUG);
62 
63 
64 
81  CubicSpline2D(const std::vector<std::vector<float> >& sample_positions_x,
82  const std::vector<float>& sample_positions_y,
83  const std::vector<std::vector<float> >& sample_values,
84  const std::vector<float>& x_default_values,
85  float y_default_value,
86  const std::vector<float>& x_lower_bounds,
87  const std::vector<float>& x_upper_bounds,
88  float y_lower_bound,
89  float y_upper_bound,
90  bool is_natural = true,
91  const std::vector<float>& x_lower_derivatives = std::vector<float>(),
92  const std::vector<float>& x_upper_derivatives = std::vector<float>(),
93  float y_lower_derivative = 0.0,
94  float y_upper_derivative = 0.0,
95  int verbosity = VERBOSITY_LEVEL_DEBUG);
96 
97 //-------------------------- Constructors with equal x sample positions for all y ------------------------
98  //Assumes that all rows have the same x-positions.
99 
100 
117  CubicSpline2D(const std::vector<float>& sample_positions_x,
118  const std::vector<float>& sample_positions_y,
119  const std::vector<std::vector<float> >& sample_values,
120  bool return_average = false,
121  bool is_natural = true,
122  const std::vector<float>& x_lower_derivatives = std::vector<float>(),
123  const std::vector<float>& x_upper_derivatives = std::vector<float>(),
124  float y_lower_derivative = 0.,
125  float y_upper_derivative = 0.,
126  int verbosity = VERBOSITY_LEVEL_DEBUG);
127 
144  CubicSpline2D(const std::vector<float>& sample_positions_x,
145  const std::vector<float>& sample_positions_y,
146  const std::vector<std::vector<float> >& sample_values,
147  const std::vector<float>& x_default_values,
148  float y_default_value,
149  const std::vector<float>& x_lower_bounds,
150  const std::vector<float>& x_upper_bounds,
151  float y_lower_bound,
152  float y_upper_bound,
153  bool is_natural = true,
154  const std::vector<float>& x_lower_derivatives = std::vector<float>(),
155  const std::vector<float>& x_upper_derivatives = std::vector<float>(),
156  float y_lower_derivative = 0.0,
157  float y_upper_derivative = 0.0,
158  int verbosity = VERBOSITY_LEVEL_DEBUG);
159 
160 
163  CubicSpline2D(const CubicSpline2D& cs2D);
164 
167  virtual ~CubicSpline2D();
168 
170  void setVerbosity(int verbosity);
171 
182  float operator () (float x, float y);
183 
187  float getXDefaultValue(Index x) const;
188 
191  float getYDefaultValue() const {return y_default_value_;}
192 
193  // Set the default values in x direction.
194  void setXDefaultValues(vector<float> x_default_values) {x_default_values_ = x_default_values;}
195 
196  // Set the default values in y direction.
197  void setYDefaultValue(float y_default_value) {y_default_value_ = y_default_value;}
198 
199 
200  // Set the lower/upper bound in y direction
201  void setYLowerBound(float lb) {y_lower_bound_ = lb;}
202  void setYUpperBound(float ub) {y_upper_bound_ = ub;}
203  // Get the lower/upper bound in y direction
204  float getYLowerBound() {return y_lower_bound_;}
205  float getYUpperBound() {return y_upper_bound_;}
206  // Set the lower/upper bounds in x direction
207  void setXLowerBounds(vector<float> lb) {x_lower_bounds_ = lb;}
208  void setXUpperBounds(vector<float> ub) {x_upper_bounds_ = ub;}
209 
212  const vector<float>& getXLowerBounds() const {return x_lower_bounds_ ;}
213 
216  const vector<float>& getXUpperBounds() const {return x_upper_bounds_;}
217 
221  float getXLowerBounds(Index x) const;
222 
226  float getXUpperBounds(Index x) const;
227 
230  bool isXNatural(Index x);
231  vector<bool> isXNatural() const {return x_is_natural_;}
232 
236  void makeXNatural(Index x, bool recompute = true);
237 
241  void makeAllXNatural(bool recompute = true);
242 
247  void makeYNatural(bool y_is_natural, bool recompute = true);
248 
251  bool isYNatural() {return y_is_natural_;}
252 
253  // Set the lower/upper derivatives in x direction
254  void setXLowerDerivatives(vector<float> ld, bool recompute = true);
255  void setXUpperDerivatives(vector<float> ud, bool recompute = true);
256 
260  float getXLowerDerivatives(Index x);
261 
265  float getXUpperDerivatives(Index x);
266 
267  vector<float>& getXLowerDerivatives() {return x_lower_derivatives_;}
268  vector<float>& getXUpperDerivatives() {return x_upper_derivatives_;}
269 
270  // Set the lower/upper derivative in y direction
271  void setYLowerDerivative (float ld, bool recompute = true);
272  void setYUpperDerivative (float ud, bool recompute = true);
273 
274  // Get the lower/upper derivative in y direction
275  float getYLowerDerivative() {return y_lower_derivative_;}
276  float getYUpperDerivative() {return y_upper_derivative_;}
277 
278 
282  CubicSpline1D& getSpline(Position i);
283 
287  const CubicSpline1D& getSpline(Position i) const;
288 
289  Size getNumberOfSplines() const {return splines_.size();}
290 
291  private :
292 
301  void createBiCubicSpline();
302 
303  // Sample x positions of the spline.
304  // Note: we allow for each y value different x positions.
305  std::vector< std::vector<float> > sample_positions_x_;
306 
307  // Sample y positions of the spline.
308  std::vector<float> sample_positions_y_;
309 
310  // For each y position a 1D cubic spline is stored.
311  std::vector<CubicSpline1D> splines_;
312 
313  // Sample values of the spline.
314  std::vector<std::vector<float> > sample_values_;
315 
316  //
317  // Parameters
318  //
319 
320  // Flag to denote, if the default values should be set to the average of the spline averages.
322 
328  std::vector<float> x_default_values_;
329 
336 
341 
342  // Lower bounds of the spline in x direction.
343  vector<float> x_lower_bounds_;
344 
345  // Upper bounds of the spline in x direction.
346  vector<float> x_upper_bounds_;
347 
348  // Lower bound of the splines in y direction.
350 
351  // Upper bound of the splines in y direction.
353 
354 
355  // Flag to denote, if the splines in x direction is natural.
356  vector<bool> x_is_natural_;
357 
358  // Flag to denote, if the splines in y direction are natural.
360 
361 
362  // Values of the first derivatives of the lower x sample position
363  vector<float> x_lower_derivatives_;
364 
365  // Values of the first derivatives of the upper x sample position
366  vector<float> x_upper_derivatives_;
367 
368  // Value of the first derivatives of the lower y sample position
370 
371  // Value of the first derivatives of the upper y sample position
373 
376  };
377 
378 
379 
380 }
381 #endif