00001
00002
00003
00004
00005
00006
00007 #ifndef BALL_MATHS_PIECEWISEFUNCTION_H
00008 #define BALL_MATHS_PIECEWISEFUNCTION_H
00009
00010 #ifndef BALL_COMMON_LIMITS_H
00011 # include <BALL/COMMON/limits.h>
00012 #endif
00013
00014 #ifndef BALL_COMMON_H
00015 # include <BALL/common.h>
00016 #endif
00017
00018 namespace BALL
00019 {
00023 typedef std::vector<double> Coefficients;
00024
00027 typedef std::pair<double,double> Interval;
00028 #ifdef INFINITY
00029 #undef INFINITY
00030 #endif
00031 static const double INFINITY = Limits<double>::max();
00032
00042 class BALL_EXPORT PiecewiseFunction
00043 {
00044 public:
00045
00046 BALL_CREATE(PiecewiseFunction)
00047
00048
00051
00054 PiecewiseFunction() ;
00055
00058 PiecewiseFunction(const PiecewiseFunction& function) ;
00059
00062 PiecewiseFunction(const std::vector<Interval>& intervals,
00063 const std::vector<Coefficients>& coeffs) ;
00064
00067 virtual ~PiecewiseFunction() ;
00068
00070
00073
00076 PiecewiseFunction& operator = (const PiecewiseFunction& function) ;
00077
00080 void clear() ;
00081
00083
00086
00091 void setIntervals(const std::vector<Interval>& intervals) ;
00092
00095 const std::vector<Interval>& getIntervals() const ;
00096
00099 const Interval& getInterval(double x) const
00100 throw(Exception::OutOfRange);
00101
00104 const Interval& getInterval(Position index) const
00105 throw(Exception::IndexOverflow);
00106
00109 Position getIntervalIndex(double x) const
00110 throw(Exception::OutOfRange);
00111
00114 const Interval& getRange() const ;
00115
00120 void setCoefficients(const vector<Coefficients>& coefficients) ;
00121
00123 const std::vector<Coefficients>& getCoefficients() const ;
00124
00127 const Coefficients& getCoefficients(double x) const
00128 throw(Exception::OutOfRange);
00129
00132 const Coefficients& getCoefficients(Position index) const
00133 throw(Exception::IndexOverflow);
00134
00137 virtual double operator () (double x) const ;
00138
00140 void set(const std::vector<Interval>& intervals,
00141 const std::vector<Coefficients>& coeffs) ;
00142
00144
00147
00150 bool isInRange(double x) const ;
00151
00154 virtual bool isValid() const ;
00155
00158 bool operator == (const PiecewiseFunction& function) const ;
00159
00161
00164
00167 virtual void dump (std::ostream& s = std::cout, Size depth = 0) const ;
00168
00170
00171 protected:
00172
00173
00174
00175 std::vector<Interval> intervals_;
00176
00177
00178
00179 std::vector<Coefficients> coefficients_;
00180
00181 bool valid_;
00182
00183
00184 private:
00185
00186
00187
00188 Interval range_;
00189
00190
00191
00192 void calculateRange() ;
00193
00194 };
00195 }
00196
00197 #endif