wmlintpakimauniform2.cpp
来自「3D Game Engine Design Source Code非常棒」· C++ 代码 · 共 472 行 · 第 1/2 页
CPP
472 行
int IntpAkimaUniform2<Real>::GetYBound () const
{
return m_iYBound;
}
//----------------------------------------------------------------------------
template <class Real>
int IntpAkimaUniform2<Real>::GetQuantity () const
{
return m_iQuantity;
}
//----------------------------------------------------------------------------
template <class Real>
Real** IntpAkimaUniform2<Real>::GetF () const
{
return m_aafF;
}
//----------------------------------------------------------------------------
template <class Real>
typename IntpAkimaUniform2<Real>::Polynomial**
IntpAkimaUniform2<Real>::GetPolynomials () const
{
return m_aakPoly;
}
//----------------------------------------------------------------------------
template <class Real>
const typename IntpAkimaUniform2<Real>::Polynomial&
IntpAkimaUniform2<Real>::GetPolynomial (int iX, int iY) const
{
assert( iX < m_iXBound-1 && iY < m_iYBound-1 );
return m_aakPoly[iY][iX];
}
//----------------------------------------------------------------------------
template <class Real>
Real IntpAkimaUniform2<Real>::GetXMin () const
{
return m_fXMin;
}
//----------------------------------------------------------------------------
template <class Real>
Real IntpAkimaUniform2<Real>::GetXMax () const
{
return m_fXMax;
}
//----------------------------------------------------------------------------
template <class Real>
Real IntpAkimaUniform2<Real>::GetXSpacing () const
{
return m_fXSpacing;
}
//----------------------------------------------------------------------------
template <class Real>
Real IntpAkimaUniform2<Real>::GetYMin () const
{
return m_fYMin;
}
//----------------------------------------------------------------------------
template <class Real>
Real IntpAkimaUniform2<Real>::GetYMax () const
{
return m_fYMax;
}
//----------------------------------------------------------------------------
template <class Real>
Real IntpAkimaUniform2<Real>::GetYSpacing () const
{
return m_fYSpacing;
}
//----------------------------------------------------------------------------
template <class Real>
Real IntpAkimaUniform2<Real>::ComputeDerivative (Real* afSlope) const
{
if ( afSlope[1] != afSlope[2] )
{
if ( afSlope[0] != afSlope[1] )
{
if ( afSlope[2] != afSlope[3] )
{
Real fAD0 = Math<Real>::FAbs(afSlope[3] - afSlope[2]);
Real fAD1 = Math<Real>::FAbs(afSlope[0] - afSlope[1]);
return (fAD0*afSlope[1]+fAD1*afSlope[2])/(fAD0+fAD1);
}
else
{
return afSlope[2];
}
}
else
{
if ( afSlope[2] != afSlope[3] )
return afSlope[1];
else
return ((Real)0.5)*(afSlope[1]+afSlope[2]);
}
}
else
{
return afSlope[1];
}
}
//----------------------------------------------------------------------------
template <class Real>
void IntpAkimaUniform2<Real>::Construct (Polynomial& rkPoly, Real aafF[2][2],
Real aafFX[2][2], Real aafFY[2][2], Real aafFXY[2][2])
{
Real fDX = m_fXSpacing;
Real fDY = m_fYSpacing;
Real fInvDX = ((Real)1.0)/fDX, fInvDX2 = fInvDX*fInvDX;
Real fInvDY = ((Real)1.0)/fDY, fInvDY2 = fInvDY*fInvDY;
Real fB0, fB1, fB2, fB3;
rkPoly.A(0,0) = aafF[0][0];
rkPoly.A(1,0) = aafFX[0][0];
rkPoly.A(0,1) = aafFY[0][0];
rkPoly.A(1,1) = aafFXY[0][0];
fB0 = (aafF[1][0] - rkPoly(0,0,fDX,(Real)0.0))*fInvDX2;
fB1 = (aafFX[1][0] - rkPoly(1,0,fDX,(Real)0.0))*fInvDX;
rkPoly.A(2,0) = ((Real)3.0)*fB0 - fB1;
rkPoly.A(3,0) = (-((Real)2.0)*fB0 + fB1)*fInvDX;
fB0 = (aafF[0][1] - rkPoly(0,0,(Real)0.0,fDY))*fInvDY2;
fB1 = (aafFY[0][1] - rkPoly(0,1,(Real)0.0,fDY))*fInvDY;
rkPoly.A(0,2) = ((Real)3.0)*fB0 - fB1;
rkPoly.A(0,3) = (-((Real)2.0)*fB0 + fB1)*fInvDY;
fB0 = (aafFY[1][0] - rkPoly(0,1,fDX,(Real)0.0))*fInvDX2;
fB1 = (aafFXY[1][0] - rkPoly(1,1,fDX,(Real)0.0))*fInvDX;
rkPoly.A(2,1) = ((Real)3.0)*fB0 - fB1;
rkPoly.A(3,1) = (-((Real)2.0)*fB0 + fB1)*fInvDX;
fB0 = (aafFX[0][1] - rkPoly(1,0,(Real)0.0,fDY))*fInvDY2;
fB1 = (aafFXY[0][1] - rkPoly(1,1,(Real)0.0,fDY))*fInvDY;
rkPoly.A(1,2) = ((Real)3.0)*fB0 - fB1;
rkPoly.A(1,3) = (-((Real)2.0)*fB0 + fB1)*fInvDY;
fB0 = (aafF[1][1] - rkPoly(0,0,fDX,fDY))*fInvDX2*fInvDY2;
fB1 = (aafFX[1][1] - rkPoly(1,0,fDX,fDY))*fInvDX*fInvDY2;
fB2 = (aafFY[1][1] - rkPoly(0,1,fDX,fDY))*fInvDX2*fInvDY;
fB3 = (aafFXY[1][1] - rkPoly(1,1,fDX,fDY))*fInvDX*fInvDY;
rkPoly.A(2,2) = ((Real)9.0)*fB0 - ((Real)3.0)*fB1 - ((Real)3.0)*fB2 + fB3;
rkPoly.A(3,2) = (-((Real)6.0)*fB0 + ((Real)3.0)*fB1 + ((Real)2.0)*fB2 -
fB3)*fInvDX;
rkPoly.A(2,3) = (-((Real)6.0)*fB0 + ((Real)2.0)*fB1 + ((Real)3.0)*fB2 -
fB3)*fInvDY;
rkPoly.A(3,3) = (((Real)4.0)*fB0 - ((Real)2.0)*fB1 - ((Real)2.0)*fB2 +
fB3)*fInvDX*fInvDY;
}
//----------------------------------------------------------------------------
template <class Real>
bool IntpAkimaUniform2<Real>::XLookup (Real fX, int& riXIndex, Real& rfDX)
const
{
if ( fX >= m_fXMin )
{
if ( fX <= m_fXMax )
{
for (riXIndex = 0; riXIndex+1 < m_iXBound; riXIndex++)
{
if ( fX < m_fXMin + m_fXSpacing*(riXIndex+1) )
{
rfDX = fX - (m_fXMin + m_fXSpacing*riXIndex);
return true;
}
}
riXIndex--;
rfDX = fX - (m_fXMin + m_fXSpacing*riXIndex);
return true;
}
}
return false;
}
//----------------------------------------------------------------------------
template <class Real>
bool IntpAkimaUniform2<Real>::YLookup (Real fY, int& riYIndex, Real& rfDY)
const
{
if ( fY >= m_fYMin )
{
if ( fY <= m_fYMax )
{
for (riYIndex = 0; riYIndex+1 < m_iYBound; riYIndex++)
{
if ( fY < m_fYMin + m_fYSpacing*(riYIndex+1) )
{
rfDY = fY - (m_fYMin + m_fYSpacing*riYIndex);
return true;
}
}
riYIndex--;
rfDY = fY - (m_fYMin + m_fYSpacing*riYIndex);
return true;
}
}
return false;
}
//----------------------------------------------------------------------------
template <class Real>
Real IntpAkimaUniform2<Real>::operator() (Real fX, Real fY) const
{
int iX, iY;
Real fDX, fDY;
if ( XLookup(fX,iX,fDX) && YLookup(fY,iY,fDY) )
return m_aakPoly[iY][iX](fDX,fDY);
else
return Math<Real>::MAX_REAL;
}
//----------------------------------------------------------------------------
template <class Real>
Real IntpAkimaUniform2<Real>::operator() (int iXOrder, int iYOrder, Real fX,
Real fY) const
{
int iX, iY;
Real fDX, fDY;
if ( XLookup(fX,iX,fDX) && YLookup(fY,iY,fDY) )
return m_aakPoly[iY][iX](iXOrder,iYOrder,fDX,fDY);
else
return Math<Real>::MAX_REAL;
}
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
// explicit instantiation
//----------------------------------------------------------------------------
namespace Wml
{
template class WML_ITEM IntpAkimaUniform2<float>;
template class WML_ITEM IntpAkimaUniform2<double>;
}
//----------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?