CARMA C++
QuadraticInterpolator.h
1 #ifndef SZA_UTIL_QUADRATICINTERPOLATOR_H
2 #define SZA_UTIL_QUADRATICINTERPOLATOR_H
3 
11 #include <pthread.h>
12 
17 #define QP_ANGLE_FN(fn) double (fn)(double angle)
18 
19 namespace sza {
20  namespace util {
21 
48 
49  public:
50 
54  static const double pi_;
55  static const double twopi_;
56 
61  enum QuadType {
62 
67 
72 
77  };
78 
79  //------------------------------------------------------------
80  // Public methods
81  //------------------------------------------------------------
82 
86  virtual ~QuadraticInterpolator();
87 
98  void empty();
99 
134  void extend(double x, double y);
135 
139  double evaluate(double x);
140 
144  double gradient(double x);
145 
149  void lock();
150 
154  void unlock();
155 
160  bool tryLock();
161 
166  bool canBracket(double x);
167 
172  unsigned getNpt();
173 
178  double getXmin();
179 
184  double getXmax();
185 
186  protected:
187 
192 
203 
208  void setEmptyValue(double emptyValue);
209 
210  private:
211 
212  //------------------------------------------------------------
213  // Resources for locking this container
214  //------------------------------------------------------------
215 
219  bool mutexIsReady_;
220 
224  pthread_mutex_t mutex_;
225 
226  //------------------------------------------------------------
227  // Structs used by this class.
228  //------------------------------------------------------------
229 
233  struct QuadSample {
234  double x;
235  double y;
236  };
237 
242  struct QuadData {
243 
258  int npt;
259 
263  QuadSample s[3];
264 
268  void init();
269  };
270 
271  //------------------------------------------------------------
272  // Private data members
273  //------------------------------------------------------------
274 
275  double emptyValue_; // The value to use when npt==0
276  double x0_; // A value which will be subtracted off
277  // of the x-value to maintain accuracy
278  double a_,b_,c_; // The coefficients of the quadratic
279  // equation that interpolates x[],y[]
280  QuadSample s_[3]; // The samples to interpolate between
281  int npt_; // The number of values in x[] and y[]
282 
283  //------------------------------------------------------------
284  // Private methods
285  //------------------------------------------------------------
286 
296  virtual double fixAngle(double angle);
297 
303  void get(QuadData* data);
304 
323  void set(QuadData* data);
324 
329  double extendAngle(double a, double b);
330  };
331  };
332 };
333 
334 #endif
double getXmin()
A method to query the minimum x-value in our interpolation container.
QuadType type_
The type of ordinate we are interpolating.
void unlock()
A public method to unlock this container.
void empty()
Empty the coordinate table of a QuadraticInterpolator object.
Angles defined modulo 2.pi between 0 &lt;= v &lt; 2.pi.
Angles defined modulo 2.pi between -pi &lt;= v &lt; pi.
bool canBracket(double x)
A method to query if the container can bracket the requested value.
static const double pi_
Define constants.
unsigned getNpt()
A method to query the number of points currently in our interpolation container.
void extend(double x, double y)
Append or prepend an x,y coordinate pair to the three-entry circular table of a quadratic interpolati...
double getXmax()
A method to query the maximum x-value in our interpolation container.
double evaluate(double x)
Return the value of the function at x.
QuadType
Enumerate the various types of ephemeris types we might handle.
void lock()
A public method to lock this container.
void setEmptyValue(double emptyValue)
A method to set the value to be returned while the interpolation container is empty.
The QuadraticInterpolator class is used to perform quadrature interpolation of arbitrary continuous f...
double gradient(double x)
Return the gradient of the function at x.
bool tryLock()
A public method to attempt to lock this container.
virtual ~QuadraticInterpolator()
Destructor.
QuadraticInterpolator()
Constructor function.