BALL  1.4.1
cubicSpline2D.h
Go to the documentation of this file.
00001 #ifndef BALL_MATHS_CUBICSPLINE2D_H
00002 #define BALL_MATHS_CUBICSPLINE2D_H
00003 
00004 #include <set>
00005 #include <map>
00006 
00007 #ifndef BALL_MATHS_CUBICSPLINE1D_H
00008 # include <BALL/MATHS/cubicSpline1D.h>
00009 #endif
00010 
00011 #ifndef BALL_COMMON_EXCEPTION_H
00012 #include <BALL/COMMON/exception.h>
00013 #endif
00014 
00015 namespace BALL 
00016 {
00017   class BALL_EXPORT CubicSpline2D
00018   {
00019     public:
00020 
00021       static const int VERBOSITY_LEVEL_DEBUG;
00022       static const int VERBOSITY_LEVEL_CRITICAL;
00023 
00024       BALL_CREATE(CubicSpline2D)
00025 
00026       //@}
00030 
00033       CubicSpline2D();
00034       
00035 
00052       CubicSpline2D(const std::vector<std::vector<float> >& sample_positions_x,
00053                     const std::vector<float>& sample_positions_y,
00054                     const std::vector<std::vector<float> >& sample_values, 
00055                     bool  return_average = false,
00056                     bool  is_natural = true,    
00057                     const std::vector<float>& x_lower_derivatives = std::vector<float>(),  
00058                     const std::vector<float>& x_upper_derivatives = std::vector<float>(),
00059                     float y_lower_derivative = 0., 
00060                     float y_upper_derivative = 0.,
00061                     int verbosity = VERBOSITY_LEVEL_DEBUG);
00062     
00063     
00064 
00081       CubicSpline2D(const std::vector<std::vector<float> >& sample_positions_x,
00082                     const std::vector<float>& sample_positions_y,
00083                     const std::vector<std::vector<float> >& sample_values, 
00084                     const std::vector<float>& x_default_values, 
00085                     float y_default_value, 
00086                     const std::vector<float>& x_lower_bounds,
00087                     const std::vector<float>& x_upper_bounds,
00088                     float y_lower_bound,
00089                     float y_upper_bound,
00090                     bool  is_natural = true,  
00091                     const std::vector<float>& x_lower_derivatives = std::vector<float>(), 
00092                     const std::vector<float>& x_upper_derivatives = std::vector<float>(),
00093                     float y_lower_derivative = 0.0,
00094                     float y_upper_derivative = 0.0,
00095                     int verbosity = VERBOSITY_LEVEL_DEBUG);
00096       
00097 //-------------------------- Constructors with equal x sample positions for all y ------------------------
00098      //Assumes that all rows have the same x-positions.
00099 
00100 
00117       CubicSpline2D(const std::vector<float>& sample_positions_x,
00118                     const std::vector<float>& sample_positions_y,
00119                     const std::vector<std::vector<float> >& sample_values, 
00120                     bool  return_average = false,
00121                     bool  is_natural = true,    
00122                     const std::vector<float>& x_lower_derivatives = std::vector<float>(),  
00123                     const std::vector<float>& x_upper_derivatives = std::vector<float>(),
00124                     float y_lower_derivative = 0., 
00125                     float y_upper_derivative = 0.,
00126                     int verbosity = VERBOSITY_LEVEL_DEBUG);
00127     
00144       CubicSpline2D(const std::vector<float>& sample_positions_x,
00145                     const std::vector<float>& sample_positions_y,
00146                     const std::vector<std::vector<float> >& sample_values, 
00147                     const std::vector<float>& x_default_values, 
00148                     float y_default_value, 
00149                     const std::vector<float>& x_lower_bounds,
00150                     const std::vector<float>& x_upper_bounds,
00151                     float y_lower_bound,
00152                     float y_upper_bound,
00153                     bool  is_natural = true,  
00154                     const std::vector<float>& x_lower_derivatives = std::vector<float>(), 
00155                     const std::vector<float>& x_upper_derivatives = std::vector<float>(),
00156                     float y_lower_derivative = 0.0,
00157                     float y_upper_derivative = 0.0,
00158                     int verbosity = VERBOSITY_LEVEL_DEBUG);
00159 
00160       
00163       CubicSpline2D(const CubicSpline2D& cs2D);
00164       
00167       virtual ~CubicSpline2D();
00168   
00170       void setVerbosity(int verbosity);
00171 
00182       float operator () (float x, float y); 
00183           
00187       float getXDefaultValue(Index x) const;
00188 
00191       float getYDefaultValue() const {return y_default_value_;}
00192 
00193       // Set the default values in x direction.
00194       void setXDefaultValues(vector<float> x_default_values) {x_default_values_ = x_default_values;}
00195 
00196       // Set the default values in y direction.
00197       void setYDefaultValue(float y_default_value) {y_default_value_ = y_default_value;} 
00198         
00199       
00200       // Set the lower/upper bound in y direction
00201       void  setYLowerBound(float lb) {y_lower_bound_ = lb;}
00202       void  setYUpperBound(float ub) {y_upper_bound_ = ub;}
00203       // Get the lower/upper bound in y direction
00204       float getYLowerBound() {return y_lower_bound_;}
00205       float getYUpperBound() {return y_upper_bound_;}
00206       // Set the lower/upper bounds in x direction
00207       void  setXLowerBounds(vector<float> lb) {x_lower_bounds_ = lb;}
00208       void  setXUpperBounds(vector<float> ub) {x_upper_bounds_ = ub;}
00209 
00212       const vector<float>&  getXLowerBounds() const {return x_lower_bounds_ ;}  
00213 
00216       const vector<float>&  getXUpperBounds() const {return x_upper_bounds_;}  
00217 
00221       float getXLowerBounds(Index x) const;  
00222 
00226       float getXUpperBounds(Index x) const;  
00227 
00230       bool isXNatural(Index x);
00231       vector<bool> isXNatural() const {return x_is_natural_;}
00232 
00236       void makeXNatural(Index x, bool recompute = true);
00237 
00241       void makeAllXNatural(bool recompute = true);
00242 
00247       void makeYNatural(bool y_is_natural, bool recompute = true);
00248 
00251       bool isYNatural() {return y_is_natural_;}
00252       
00253       // Set the lower/upper derivatives in x direction
00254       void  setXLowerDerivatives(vector<float> ld, bool recompute = true); 
00255       void  setXUpperDerivatives(vector<float> ud, bool recompute = true); 
00256 
00260       float getXLowerDerivatives(Index x);
00261 
00265       float getXUpperDerivatives(Index x); 
00266 
00267       vector<float>& getXLowerDerivatives() {return x_lower_derivatives_;}
00268       vector<float>& getXUpperDerivatives() {return x_upper_derivatives_;}
00269 
00270       // Set the lower/upper derivative in y direction
00271       void setYLowerDerivative (float ld, bool recompute = true); 
00272       void setYUpperDerivative (float ud, bool recompute = true);
00273 
00274       // Get the lower/upper derivative in y direction
00275       float getYLowerDerivative() {return y_lower_derivative_;}
00276       float getYUpperDerivative() {return y_upper_derivative_;}
00277 
00278       
00282       CubicSpline1D& getSpline(Position i); 
00283 
00287       const CubicSpline1D& getSpline(Position i) const;
00288 
00289       Size getNumberOfSplines() const {return splines_.size();} 
00290   
00291     private :
00292       
00301       void createBiCubicSpline(); 
00302         
00303       // Sample x positions of the spline.
00304       // Note: we allow for each y value different x positions.
00305       std::vector< std::vector<float> > sample_positions_x_;
00306       
00307       // Sample y positions of the spline.
00308       std::vector<float>                sample_positions_y_;
00309 
00310       // For each y position a 1D cubic spline is stored.
00311       std::vector<CubicSpline1D>        splines_;
00312       
00313       // Sample values of the spline.
00314       std::vector<std::vector<float> >  sample_values_;
00315       
00316       //
00317       //  Parameters 
00318       //
00319       
00320       // Flag to denote, if the default values should be set to the average of the spline averages. 
00321       bool                   return_average_;
00322       
00328       std::vector<float>    x_default_values_; 
00329       
00335       float                 y_default_value_; 
00336 
00340       float default_value_;
00341       
00342       // Lower bounds of the spline in x direction.
00343       vector<float>         x_lower_bounds_;
00344 
00345       // Upper bounds of the spline in x direction. 
00346       vector<float>         x_upper_bounds_;
00347       
00348       // Lower bound of the splines in y direction.
00349       float                 y_lower_bound_;
00350 
00351       // Upper bound of the splines in y direction. 
00352       float                 y_upper_bound_;
00353       
00354       
00355       // Flag to denote, if the splines in x direction is natural.
00356       vector<bool>          x_is_natural_;
00357       
00358       // Flag to denote, if the splines in y direction are natural.
00359       bool                  y_is_natural_;
00360 
00361       
00362       // Values of the first derivatives of the lower x sample position
00363       vector<float>         x_lower_derivatives_;
00364       
00365       // Values of the first derivatives of the upper x sample position
00366       vector<float>         x_upper_derivatives_;
00367       
00368       // Value of the first derivatives of the lower y sample position
00369       float                 y_lower_derivative_;
00370       
00371       // Value of the first derivatives of the upper y sample position
00372       float                 y_upper_derivative_;
00373 
00375       int                   verbosity_;
00376   };
00377 
00378 
00379 
00380 }
00381 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines