BALL  1.4.1
piecewiseFunction.h
Go to the documentation of this file.
00001 // -*- Mode: C++; tab-width: 2; -*-
00002 // vi: set ts=2:
00003 //
00004 
00005 #ifndef BALL_MATHS_PIECEWISEFUNCTION_H
00006 #define BALL_MATHS_PIECEWISEFUNCTION_H
00007 
00008 #ifndef BALL_COMMON_LIMITS_H
00009 # include <BALL/COMMON/limits.h>
00010 #endif
00011 
00012 #ifndef BALL_COMMON_H
00013 # include <BALL/common.h>
00014 #endif
00015 
00016 namespace BALL
00017 {
00021   typedef std::vector<double> Coefficients;
00022 
00025   typedef std::pair<double,double> Interval;
00026   #ifdef INFINITY
00027   #undef INFINITY
00028   #endif
00029   static const double INFINITY = Limits<double>::max();
00030 
00040   class BALL_EXPORT PiecewiseFunction
00041   {
00042     public:
00043 
00044     BALL_CREATE(PiecewiseFunction)
00045 
00046     
00049 
00052     PiecewiseFunction() ;
00053 
00056     PiecewiseFunction(const PiecewiseFunction& function) ;
00057 
00060     PiecewiseFunction(const std::vector<Interval>& intervals, 
00061       const std::vector<Coefficients>& coeffs) ;
00062 
00065     virtual ~PiecewiseFunction() ;
00066 
00068 
00071 
00074     PiecewiseFunction& operator = (const PiecewiseFunction& function) ;
00075 
00078     void clear() ;
00079 
00081 
00084 
00089     void setIntervals(const std::vector<Interval>& intervals) ;
00090 
00093     const std::vector<Interval>& getIntervals() const ;
00094 
00098     const Interval& getInterval(double x) const;
00099 
00103     const Interval& getInterval(Position index) const;
00104 
00108     Position getIntervalIndex(double x) const;
00109 
00112     const Interval& getRange() const;
00113 
00118     void setCoefficients(const vector<Coefficients>& coefficients) ;
00119 
00121     const std::vector<Coefficients>& getCoefficients() const ;
00122 
00126     const Coefficients& getCoefficients(double x) const;
00127 
00131     const Coefficients& getCoefficients(Position index) const;
00132     
00135     virtual double operator () (double x) const;
00136 
00138     void set(const std::vector<Interval>& intervals,
00139         const std::vector<Coefficients>& coeffs);
00140 
00142 
00145 
00148     bool isInRange(double x) const;
00149 
00152     virtual bool isValid() const;
00153 
00156     bool operator == (const PiecewiseFunction& function) const;
00157 
00159 
00162 
00165     virtual void dump (std::ostream& s = std::cout, Size depth = 0) const;
00166 
00168 
00169     protected:
00170 
00171     /*_ This vector contains the intervals of the representation 
00172     */
00173     std::vector<Interval> intervals_;
00174 
00175     /*_ This vector stores the coefficients for each interval 
00176     */
00177     std::vector<Coefficients> coefficients_;
00178 
00179     bool valid_;
00180 
00181 
00182     private:
00183 
00184     /*_ The range of the defnition, needed for isInRange() and getRange() 
00185     */
00186     Interval range_;
00187 
00188     /*_ Set the internal range fields 
00189     */
00190     void calculateRange();
00191 
00192   };
00193 }
00194 
00195 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines