CARMA C++
QuadraticInterpolator.h
1 #ifndef CARMA_UTIL_QUADRATICINTERPOLATOR_H
2 #define CARMA_UTIL_QUADRATICINTERPOLATOR_H
3 
11 #if 0
12 #include <iostream>
13 #endif
14 #include <pthread.h>
15 
16 
17 // Define pi
18 
19 //#define pi 3.1415926535897932384626433832795028841971693993751
20 
21 // Define 2*pi
22 
23 //#define twopi 6.2831853071795864769252867665590057683943387987502
24 
29 #define QP_ANGLE_FN(fn) double (fn)(double angle)
30 
31 namespace carma {
32  namespace util {
33 
60 
61  public:
62 
66  static const double pi_;
67  static const double twopi_;
68 
73  enum QuadType {
74 
79 
84 
89  };
90 
91  //------------------------------------------------------------
92  // Public methods
93  //------------------------------------------------------------
94 
98  virtual ~QuadraticInterpolator();
99 
110  void empty();
111 
146  void extend(double x, double y);
147 
151  double evaluate(double x);
152 
156  double gradient(double x);
157 
161  void lock();
162 
166  void unlock();
167 
172  bool tryLock();
173 
178  bool canBracket(double x);
179 
184  unsigned getNpt();
185 
190  double getXmin();
191 
196  double getXmax();
197 
198  void getXvals( double xVals[3], unsigned * numXvals );
199 
200 #if 0
201 
204  friend std::ostream& operator<<(std::ostream& os, QuadraticInterpolator& quad);
205 #endif
206  void print();
207 
208  protected:
209 
214 
225 
230  void setEmptyValue(double emptyValue);
231 
232  private:
233 
234  //------------------------------------------------------------
235  // Resources for locking this container
236  //------------------------------------------------------------
237 
241  bool mutexIsReady_;
242 
246  pthread_mutex_t mutex_;
247 
248  //------------------------------------------------------------
249  // Structs used by this class.
250  //------------------------------------------------------------
251 
255  struct QuadSample {
256  double x;
257  double y;
258  };
259 
264  struct QuadData {
265 
280  int npt;
281 
285  QuadSample s[3];
286 
290  void init();
291  };
292 
293  //------------------------------------------------------------
294  // Private data members
295  //------------------------------------------------------------
296 
297  double emptyValue_; // The value to use when npt==0
298  double x0_; // A value which will be subtracted off
299  // of the x-value to maintain accuracy
300  double a_,b_,c_; // The coefficients of the quadratic
301  // equation that interpolates x[],y[]
302  QuadSample s_[3]; // The samples to interpolate between
303  int npt_; // The number of values in x[] and y[]
304 
305  //------------------------------------------------------------
306  // Private methods
307  //------------------------------------------------------------
308 
318  virtual double fixAngle(double angle);
319 
325  void get(QuadData* data);
326 
345  void set(QuadData* data);
346 
351  double extendAngle(double a, double b);
352  };
353  };
354 };
355 
356 #endif
QuadType
Enumerate the various types of ephemeris types we might handle.
void lock()
A public method to lock this container.
QuadType type_
The type of ordinate we are interpolating.
Angles defined modulo 2.pi between 0 &lt;= v &lt; 2.pi.
double getXmax()
A method to query the maximum x-value in our interpolation container.
QuadraticInterpolator()
Constructor function.
static const double pi_
Define constants.
void setEmptyValue(double emptyValue)
A method to set the value to be returned while the interpolation container is empty.
void unlock()
A public method to unlock this container.
unsigned getNpt()
A method to query the number of points currently in our interpolation container.
double getXmin()
A method to query the minimum x-value in our interpolation container.
Angles defined modulo 2.pi between -pi &lt;= v &lt; pi.
The QuadraticInterpolator class is used to perform quadrature interpolation of arbitrary continuous f...
virtual ~QuadraticInterpolator()
Destructor.
bool tryLock()
A public method to attempt to lock this container.
double gradient(double x)
Return the gradient of the function at x.
void empty()
Empty the coordinate table of a QuadraticInterpolator object.
double evaluate(double x)
Return the value of the function at x.
bool canBracket(double x)
A method to query if the container can bracket the requested value.
void extend(double x, double y)
Append or prepend an x,y coordinate pair to the three-entry circular table of a quadratic interpolati...