X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=include%2Finterpolator.h;h=267c937d609dbd2bb1932e7e700c4cfc73160f93;hb=87ab55294bcd767d86786ad1caae8b1b36b49de0;hp=cea4961809cda3300db2c8b227d7639c3d1d734e;hpb=3ea498d51ce4597e9649cd21f155b51175ea0bea;p=ctsim.git diff --git a/include/interpolator.h b/include/interpolator.h index cea4961..267c937 100644 --- a/include/interpolator.h +++ b/include/interpolator.h @@ -2,7 +2,7 @@ ** This is part of the CTSim program ** Copyright (c) 1983-2001 Kevin Rosenberg ** -** $Id: interpolator.h,v 1.2 2001/03/21 21:45:31 kevin Exp $ +** $Id: interpolator.h,v 1.7 2002/06/27 03:19:23 kevin Exp $ ** ** This program is free software; you can redistribute it and/or modify ** it under the terms of the GNU General Public License (version 2) as @@ -34,6 +34,7 @@ public: double interpolate (double x); }; + class CubicPolyInterpolator { private: const double* const m_pdY; @@ -52,8 +53,8 @@ template class BilinearInterpolator { private: T** const m_ppMatrix; - const unsigned int m_nx; - const unsigned int m_ny; + const int m_nx; + const int m_ny; public: BilinearInterpolator (T** ppMatrix, unsigned int nx, unsigned int ny) @@ -62,8 +63,8 @@ public: T interpolate (double dXPos, double dYPos) { - int iFloorX = floor (dXPos); - int iFloorY = floor (dYPos); + int iFloorX = static_cast(floor(dXPos)); + int iFloorY = static_cast(floor (dYPos)); double dXFrac = dXPos - iFloorX; double dYFrac = dYPos - iFloorY; @@ -88,20 +89,49 @@ public: }; +template +class BicubicPolyInterpolator { +private: + T** const m_ppMatrix; + const unsigned int m_nx; + const unsigned int m_ny; + +public: + BicubicPolyInterpolator (T** ppMatrix, unsigned int nx, unsigned int ny) + : m_ppMatrix(ppMatrix), m_nx(nx), m_ny(ny) + {} + + T interpolate (double dXPos, double dYPos) + { + // int iFloorX = static_cast(floor (dXPos)); + // int iFloorY = static_cast(floor (dYPos)); + // double dXFrac = dXPos - iFloorX; + // double dYFrac = dYPos - iFloorY; + + T result = 0; + + // Need to add code + + return result; + } +}; + + template class LinearInterpolator { private: - T* const m_pY; T* const m_pX; - const unsigned int m_n; + T* const m_pY; + const int m_n; + const bool m_bZeroOutsideRange; public: - LinearInterpolator (T* pY, unsigned int n) - : m_pY(pY), m_pX(0), m_n(n) + LinearInterpolator (T* pY, unsigned int n, bool bZeroOutside = true) + : m_pX(0), m_pY(pY), m_n(n), m_bZeroOutsideRange(bZeroOutside) {} - LinearInterpolator (T* pY, T* pX, unsigned int n) - : m_pY(pY), m_pX(pX), m_n(n) + LinearInterpolator (T* pX, T* pY, unsigned int n, bool bZeroOutside = true) + : m_pX(pX), m_pY(pY), m_n(n), m_bZeroOutsideRange(bZeroOutside) {} double interpolate (double dX, int* piLastFloor = NULL) @@ -111,14 +141,20 @@ public: if (! m_pX) { if (dX == 0) result = m_pY[0]; - else if (dX < 0) - result = 0; - else if (dX == m_n - 1) + else if (dX < 0) { + if (m_bZeroOutsideRange) + result = 0; + else + result = m_pY[0]; + } else if (dX == m_n - 1) result = m_pY[m_n-1]; - else if (dX > m_n - 1) - result = 0; - else { - int iFloor = floor(dX); + else if (dX > m_n - 1) { + if (m_bZeroOutsideRange) + result = 0; + else + result = m_pY[m_n - 1]; + } else { + int iFloor = static_cast(floor(dX)); result = m_pY[iFloor] + (m_pY[iFloor+1] - m_pY[iFloor]) * (dX - iFloor); } } else { @@ -136,13 +172,19 @@ public: } if (dX == m_pX[0]) result = m_pY[0]; - else if (dX < m_pX[0]) - result = 0; - else if (dX == m_pX[m_n-1]) + else if (dX < m_pX[0]) { + if (m_bZeroOutsideRange) + result = 0; + else + result = m_pY[0]; + } else if (dX == m_pX[m_n-1]) result = m_pY[m_n-1]; - else if (dX > m_pX[m_n-1]) - result = 0; - else { + else if (dX > m_pX[m_n - 1]) { + if (m_bZeroOutsideRange) + result = 0; + else + result = m_pY[m_n - 1]; + } else { if (iLower < 0 || iLower >= m_n) { sys_error (ERR_SEVERE, "Coordinate out of range [linearInterpolate]"); return 0;