BALL  1.4.79
 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_H
9 # include <BALL/common.h>
10 #endif
11 
12 #include <limits>
13 
14 namespace BALL
15 {
19  typedef std::vector<double> Coefficients;
20 
23  typedef std::pair<double,double> Interval;
24 
35  {
36  public:
37 
39 
40 
43 
47 
50  PiecewiseFunction(const PiecewiseFunction& function) ;
51 
54  PiecewiseFunction(const std::vector<Interval>& intervals,
55  const std::vector<Coefficients>& coeffs) ;
56 
59  virtual ~PiecewiseFunction() ;
60 
62 
65 
68  PiecewiseFunction& operator = (const PiecewiseFunction& function) ;
69 
72  void clear() ;
73 
75 
78 
83  void setIntervals(const std::vector<Interval>& intervals) ;
84 
87  const std::vector<Interval>& getIntervals() const ;
88 
92  const Interval& getInterval(double x) const;
93 
97  const Interval& getInterval(Position index) const;
98 
102  Position getIntervalIndex(double x) const;
103 
106  const Interval& getRange() const;
107 
112  void setCoefficients(const vector<Coefficients>& coefficients) ;
113 
115  const std::vector<Coefficients>& getCoefficients() const ;
116 
120  const Coefficients& getCoefficients(double x) const;
121 
125  const Coefficients& getCoefficients(Position index) const;
126 
129  virtual double operator () (double x) const;
130 
132  void set(const std::vector<Interval>& intervals,
133  const std::vector<Coefficients>& coeffs);
134 
136 
139 
142  bool isInRange(double x) const;
143 
146  virtual bool isValid() const;
147 
150  bool operator == (const PiecewiseFunction& function) const;
151 
153 
156 
159  virtual void dump (std::ostream& s = std::cout, Size depth = 0) const;
160 
162 
163  protected:
164 
165  /*_ This vector contains the intervals of the representation
166  */
167  std::vector<Interval> intervals_;
168 
169  /*_ This vector stores the coefficients for each interval
170  */
171  std::vector<Coefficients> coefficients_;
172 
173  bool valid_;
174 
175 
176  private:
177 
178  /*_ The range of the defnition, needed for isInRange() and getRange()
179  */
180  Interval range_;
181 
182  /*_ Set the internal range fields
183  */
184  void calculateRange();
185 
186  };
187 }
188 
189 #endif
std::pair< double, double > Interval
#define BALL_CREATE(name)
Definition: create.h:62
std::vector< Coefficients > coefficients_
std::vector< double > Coefficients
BALL_EXPORT bool operator==(const String &s1, const String &s2)
std::vector< Interval > intervals_
#define BALL_EXPORT
Definition: COMMON/global.h:50