GteIntpAkimaNonuniform1.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 IntpAkimaNonuniform1 : public IntpAkima1<Real>
17 {
18 public:
19  // Construction. The interpolator is for arbitrarily spaced x-values.
20  // The input arrays must have 'quantity' elements and the X[] array
21  // must store increasing values: X[i + 1] > X[i] for all i.
22  IntpAkimaNonuniform1(int quantity, Real const* X, Real const* F);
23 
24  // Member access.
25  Real const* GetX() const;
26  virtual Real GetXMin() const override;
27  virtual Real GetXMax() const override;
28 
29 protected:
30  virtual void Lookup(Real x, int& index, Real& dx) const override;
31 
32  Real const* mX;
33 };
34 
35 template <typename Real>
37  Real const* F)
38  :
39  IntpAkima1<Real>(quantity, F),
40  mX(X)
41 {
42 #if !defined(GTE_NO_LOGGER)
43  LogAssert(X != nullptr, "Invalid input.");
44  for (int j0 = 0, j1 = 1; j1 < quantity; ++j0, ++j1)
45  {
46  LogAssert(X[j1] > X[j0], "Invalid input.");
47  }
48 #endif
49 
50  // Compute slopes.
51  std::vector<Real> slope(quantity + 3);
52  int i, ip1, ip2;
53  for (i = 0, ip1 = 1, ip2 = 2; i < quantity - 1; ++i, ++ip1, ++ip2)
54  {
55  Real dx = X[ip1] - X[i];
56  Real df = F[ip1] - F[i];
57  slope[ip2] = df / dx;
58  }
59 
60  slope[1] = ((Real)2) * slope[2] - slope[3];
61  slope[0] = ((Real)2) * slope[1] - slope[2];
62  slope[quantity + 1] = ((Real)2) * slope[quantity] - slope[quantity - 1];
63  slope[quantity + 2] = ((Real)2) * slope[quantity + 1] - slope[quantity];
64 
65  // Construct derivatives.
66  std::vector<Real> FDer(quantity);
67  for (i = 0; i < quantity; ++i)
68  {
69  FDer[i] = this->ComputeDerivative(&slope[i]);
70  }
71 
72  // Construct polynomials.
73  for (i = 0, ip1 = 1; i < quantity - 1; ++i, ++ip1)
74  {
75  auto& poly = this->mPoly[i];
76 
77  Real F0 = F[i];
78  Real F1 = F[ip1];
79  Real FDer0 = FDer[i];
80  Real FDer1 = FDer[ip1];
81  Real df = F1 - F0;
82  Real dx = X[ip1] - X[i];
83  Real dx2 = dx * dx;
84  Real dx3 = dx2 * dx;
85 
86  poly[0] = F0;
87  poly[1] = FDer0;
88  poly[2] = (((Real)3) * df - dx * (FDer1 + ((Real)2) * FDer0)) / dx2;
89  poly[3] = (dx * (FDer0 + FDer1) - ((Real)2) * df) / dx3;
90  }
91 }
92 
93 template <typename Real>
95 {
96  return mX;
97 }
98 
99 template <typename Real>
101 {
102  return mX[0];
103 }
104 
105 template <typename Real>
107 {
108  return mX[this->mQuantity - 1];
109 }
110 
111 template <typename Real>
112 void IntpAkimaNonuniform1<Real>::Lookup(Real x, int& index, Real& dx) const
113 {
114  // The caller has ensured that mXMin <= x <= mXMax.
115  for (index = 0; index + 1 < this->mQuantity; ++index)
116  {
117  if (x < mX[index + 1])
118  {
119  dx = x - mX[index];
120  return;
121  }
122  }
123 
124  --index;
125  dx = x - mX[index];
126 }
127 
128 }
std::vector< Polynomial > mPoly
Definition: GteIntpAkima1.h:60
#define LogAssert(condition, message)
Definition: GteLogger.h:86
GLint GLenum GLint x
Definition: glcorearb.h:404
Real ComputeDerivative(Real *slope) const
virtual Real GetXMax() const override
virtual Real GetXMin() const override
virtual void Lookup(Real x, int &index, Real &dx) const override
GLuint index
Definition: glcorearb.h:781
IntpAkimaNonuniform1(int quantity, Real const *X, Real const *F)


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