GteIntpAkima1.h
Go to the documentation of this file.
1 // David Eberly, Geometric Tools, Redmond WA 98052
2 // Copyright (c) 1998-2017
3 // Distributed under the Boost Software License, Version 1.0.
4 // http://www.boost.org/LICENSE_1_0.txt
5 // http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
6 // File Version: 3.0.0 (2016/06/19)
7 
8 #pragma once
9 
10 #include <LowLevel/GteLogger.h>
11 #include <algorithm>
12 #include <cmath>
13 #include <vector>
14 
15 namespace gte
16 {
17 
18 template <typename Real>
20 {
21 protected:
22  // Construction (abstract base class).
23  IntpAkima1(int quantity, Real const* F);
24 public:
25  // Abstract base class.
26  virtual ~IntpAkima1();
27 
28  // Member access.
29  inline int GetQuantity() const;
30  inline Real const* GetF() const;
31  virtual Real GetXMin() const = 0;
32  virtual Real GetXMax() const = 0;
33 
34  // Evaluate the function and its derivatives. The functions clamp the
35  // inputs to xmin <= x <= xmax. The first operator is for function
36  // evaluation. The second operator is for function or derivative
37  // evaluations. The 'order' argument is the order of the derivative or
38  // zero for the function itself.
39  Real operator()(Real x) const;
40  Real operator()(int order, Real x) const;
41 
42 protected:
43  class Polynomial
44  {
45  public:
46  // P(x) = c[0] + c[1]*x + c[2]*x^2 + c[3]*x^3
47  inline Real& operator[](int i);
48  Real operator()(Real x) const;
49  Real operator()(int order, Real x) const;
50 
51  private:
52  Real mCoeff[4];
53  };
54 
55  Real ComputeDerivative(Real* slope) const;
56  virtual void Lookup(Real x, int& index, Real& dx) const = 0;
57 
58  int mQuantity;
59  Real const* mF;
60  std::vector<Polynomial> mPoly;
61 };
62 
63 
64 template <typename Real>
65 IntpAkima1<Real>::IntpAkima1(int quantity, Real const* F)
66  :
67  mQuantity(quantity),
68  mF(F)
69 {
70  // At least three data points are needed to construct the estimates of
71  // the boundary derivatives.
72  LogAssert(mQuantity >= 3 && F, "Invalid input.");
73 
74  mPoly.resize(mQuantity - 1);
75 }
76 
77 template <typename Real>
79 {
80 }
81 
82 template <typename Real> inline
84 {
85  return mQuantity;
86 }
87 
88 template <typename Real> inline
89 Real const* IntpAkima1<Real>::GetF() const
90 {
91  return mF;
92 }
93 
94 template <typename Real>
96 {
97  x = std::min(std::max(x, GetXMin()), GetXMax());
98  int index;
99  Real dx;
100  Lookup(x, index, dx);
101  return mPoly[index](dx);
102 }
103 
104 template <typename Real>
105 Real IntpAkima1<Real>::operator()(int order, Real x) const
106 {
107  x = std::min(std::max(x, GetXMin()), GetXMax());
108  int index;
109  Real dx;
110  Lookup(x, index, dx);
111  return mPoly[index](order, dx);
112 }
113 
114 template <typename Real>
115 Real IntpAkima1<Real>::ComputeDerivative(Real* slope) const
116 {
117  if (slope[1] != slope[2])
118  {
119  if (slope[0] != slope[1])
120  {
121  if (slope[2] != slope[3])
122  {
123  Real ad0 = std::abs(slope[3] - slope[2]);
124  Real ad1 = std::abs(slope[0] - slope[1]);
125  return (ad0 * slope[1] + ad1 * slope[2]) / (ad0 + ad1);
126  }
127  else
128  {
129  return slope[2];
130  }
131  }
132  else
133  {
134  if (slope[2] != slope[3])
135  {
136  return slope[1];
137  }
138  else
139  {
140  return ((Real)0.5) * (slope[1] + slope[2]);
141  }
142  }
143  }
144  else
145  {
146  return slope[1];
147  }
148 }
149 
150 template <typename Real> inline
152 {
153  return mCoeff[i];
154 }
155 
156 template <typename Real>
158 {
159  return mCoeff[0] + x * (mCoeff[1] + x * (mCoeff[2] + x * mCoeff[3]));
160 }
161 
162 template <typename Real>
164 {
165  switch (order)
166  {
167  case 0:
168  return mCoeff[0] + x * (mCoeff[1] + x * (mCoeff[2] + x * mCoeff[3]));
169  case 1:
170  return mCoeff[1] + x * (((Real)2)*mCoeff[2] + x * ((Real)3) * mCoeff[3]);
171  case 2:
172  return ((Real)2) * mCoeff[2] + x * ((Real)6) * mCoeff[3];
173  case 3:
174  return ((Real)6) * mCoeff[3];
175  }
176 
177  return (Real)0;
178 }
179 
180 
181 }
GLfixed GLfixed GLint GLint order
Definition: glext.h:4927
std::vector< Polynomial > mPoly
Definition: GteIntpAkima1.h:60
virtual ~IntpAkima1()
Definition: GteIntpAkima1.h:78
gte::BSNumber< UIntegerType > abs(gte::BSNumber< UIntegerType > const &number)
Definition: GteBSNumber.h:966
#define LogAssert(condition, message)
Definition: GteLogger.h:86
Real operator()(Real x) const
GLint GLenum GLint x
Definition: glcorearb.h:404
Real ComputeDerivative(Real *slope) const
virtual Real GetXMax() const =0
Real const * mF
Definition: GteIntpAkima1.h:59
virtual Real GetXMin() const =0
GLuint index
Definition: glcorearb.h:781
Real operator()(Real x) const
Definition: GteIntpAkima1.h:95
IntpAkima1(int quantity, Real const *F)
Definition: GteIntpAkima1.h:65
Real const * GetF() const
Definition: GteIntpAkima1.h:89
virtual void Lookup(Real x, int &index, Real &dx) const =0
int GetQuantity() const
Definition: GteIntpAkima1.h:83


geometric_tools_engine
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 04:00:00