BALL  1.4.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
piecewiseFunction.h
Go to the documentation of this file.
1 // -*- Mode: C++; tab-width: 2; -*-
2 // vi: set ts=2:
3 //
4 
5 #ifndef BALL_MATHS_PIECEWISEFUNCTION_H
6 #define BALL_MATHS_PIECEWISEFUNCTION_H
7 
8 #ifndef BALL_COMMON_LIMITS_H
9 # include <BALL/COMMON/limits.h>
10 #endif
11 
12 #ifndef BALL_COMMON_H
13 # include <BALL/common.h>
14 #endif
15 
16 namespace BALL
17 {
21  typedef std::vector<double> Coefficients;
22 
25  typedef std::pair<double,double> Interval;
26  #ifdef INFINITY
27  #undef INFINITY
28  #endif
29  static const double INFINITY = Limits<double>::max();
30 
41  {
42  public:
43 
45 
46 
49 
53 
56  PiecewiseFunction(const PiecewiseFunction& function) ;
57 
60  PiecewiseFunction(const std::vector<Interval>& intervals,
61  const std::vector<Coefficients>& coeffs) ;
62 
65  virtual ~PiecewiseFunction() ;
66 
68 
71 
74  PiecewiseFunction& operator = (const PiecewiseFunction& function) ;
75 
78  void clear() ;
79 
81 
84 
89  void setIntervals(const std::vector<Interval>& intervals) ;
90 
93  const std::vector<Interval>& getIntervals() const ;
94 
98  const Interval& getInterval(double x) const;
99 
103  const Interval& getInterval(Position index) const;
104 
108  Position getIntervalIndex(double x) const;
109 
112  const Interval& getRange() const;
113 
118  void setCoefficients(const vector<Coefficients>& coefficients) ;
119 
121  const std::vector<Coefficients>& getCoefficients() const ;
122 
126  const Coefficients& getCoefficients(double x) const;
127 
131  const Coefficients& getCoefficients(Position index) const;
132 
135  virtual double operator () (double x) const;
136 
138  void set(const std::vector<Interval>& intervals,
139  const std::vector<Coefficients>& coeffs);
140 
142 
145 
148  bool isInRange(double x) const;
149 
152  virtual bool isValid() const;
153 
156  bool operator == (const PiecewiseFunction& function) const;
157 
159 
162 
165  virtual void dump (std::ostream& s = std::cout, Size depth = 0) const;
166 
168 
169  protected:
170 
171  /*_ This vector contains the intervals of the representation
172  */
173  std::vector<Interval> intervals_;
174 
175  /*_ This vector stores the coefficients for each interval
176  */
177  std::vector<Coefficients> coefficients_;
178 
179  bool valid_;
180 
181 
182  private:
183 
184  /*_ The range of the defnition, needed for isInRange() and getRange()
185  */
187 
188  /*_ Set the internal range fields
189  */
190  void calculateRange();
191 
192  };
193 }
194 
195 #endif