GteIntpAkimaUniform1.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 
11 
12 namespace gte
13 {
14 
15 template <typename Real>
16 class IntpAkimaUniform1 : public IntpAkima1<Real>
17 {
18 public:
19  // Construction and destruction. The interpolator is for uniformly
20  // spaced x-values.
21  virtual ~IntpAkimaUniform1();
22  IntpAkimaUniform1(int quantity, Real xMin, Real xSpacing, Real const* F);
23 
24  // Member access.
25  inline virtual Real GetXMin() const override;
26  inline virtual Real GetXMax() const override;
27  inline Real GetXSpacing() const;
28 
29 protected:
30  virtual void Lookup(Real x, int& index, Real& dx) const override;
31 
33 };
34 
35 
36 template <typename Real>
38 {
39 }
40 
41 template <typename Real>
43  Real xSpacing, Real const* F)
44  :
45  IntpAkima1<Real>(quantity, F),
46  mXMin(xMin),
47  mXSpacing(xSpacing)
48 {
49  LogAssert(mXSpacing > (Real)0, "Spacing must be positive.");
50 
51  mXMax = mXMin + mXSpacing * static_cast<Real>(quantity - 1);
52 
53  // Compute slopes.
54  Real invDX = ((Real)1) / mXSpacing;
55  std::vector<Real> slope(quantity + 3);
56  int i, ip1, ip2;
57  for (i = 0, ip1 = 1, ip2 = 2; i < quantity - 1; ++i, ++ip1, ++ip2)
58  {
59  slope[ip2] = (this->mF[ip1] - this->mF[i]) * invDX;
60  }
61 
62  slope[1] = ((Real)2) * slope[2] - slope[3];
63  slope[0] = ((Real)2) * slope[1] - slope[2];
64  slope[quantity + 1] = ((Real)2) * slope[quantity] - slope[quantity - 1];
65  slope[quantity + 2] = ((Real)2) * slope[quantity + 1] - slope[quantity];
66 
67  // Construct derivatives.
68  std::vector<Real> FDer(quantity);
69  for (i = 0; i < quantity; ++i)
70  {
71  FDer[i] = this->ComputeDerivative(&slope[i]);
72  }
73 
74  // Construct polynomials.
75  Real invDX2 = ((Real)1) / (mXSpacing * mXSpacing);
76  Real invDX3 = invDX2 / mXSpacing;
77  for (i = 0, ip1 = 1; i < quantity - 1; ++i, ++ip1)
78  {
79  auto& poly = this->mPoly[i];
80 
81  Real F0 = F[i];
82  Real F1 = F[ip1];
83  Real df = F1 - F0;
84  Real FDer0 = FDer[i];
85  Real FDer1 = FDer[ip1];
86 
87  poly[0] = F0;
88  poly[1] = FDer0;
89  poly[2] = (((Real)3) * df - mXSpacing * (FDer1 + ((Real)2) * FDer0)) * invDX2;
90  poly[3] = (mXSpacing * (FDer0 + FDer1) - ((Real)2) * df) * invDX3;
91  }
92 }
93 
94 template <typename Real> inline
96 {
97  return mXMin;
98 }
99 
100 template <typename Real> inline
102 {
103  return mXMax;
104 }
105 
106 template <typename Real> inline
108 {
109  return mXSpacing;
110 }
111 
112 template <typename Real>
113 void IntpAkimaUniform1<Real>::Lookup(Real x, int& index, Real& dx) const
114 {
115  // The caller has ensured that mXMin <= x <= mXMax.
116  for (index = 0; index + 1 < this->mQuantity; ++index)
117  {
118  if (x < mXMin + mXSpacing * (index + 1))
119  {
120  dx = x - (mXMin + mXSpacing * index);
121  return;
122  }
123  }
124 
125  --index;
126  dx = x - (mXMin + mXSpacing * index);
127 }
128 
129 
130 }
std::vector< Polynomial > mPoly
Definition: GteIntpAkima1.h:60
#define LogAssert(condition, message)
Definition: GteLogger.h:86
virtual Real GetXMax() const override
GLint GLenum GLint x
Definition: glcorearb.h:404
IntpAkimaUniform1(int quantity, Real xMin, Real xSpacing, Real const *F)
Real ComputeDerivative(Real *slope) const
virtual void Lookup(Real x, int &index, Real &dx) const override
Real const * mF
Definition: GteIntpAkima1.h:59
GLuint index
Definition: glcorearb.h:781
virtual Real GetXMin() const override


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