📄 wmldelaunay3.cpp
字号:
m_akTetrahedron[m_iTetrahedronQuantity];
rkTetra.m_aiVertex[0] = aaiA3S[i0][0];
rkTetra.m_aiVertex[1] = aaiA3S[i0][1];
rkTetra.m_aiVertex[2] = aaiA3S[i0][2+iDelta];
rkTetra.m_aiVertex[3] = aaiA3S[i0][3-iDelta];
m_iTetrahedronQuantity++;
}
}
}
ExitDelaunay:
delete[] aaiTmp[0];
delete[] aaiTmp;
delete[] aaID;
delete[] aaiA3S[0];
delete[] aaiA3S;
delete[] aafCCR[0];
delete[] aafCCR;
delete[] akPoint;
}
//----------------------------------------------------------------------------
template <class Real>
Delaunay3<Real>::Delaunay3 (Delaunay3& rkNet)
{
m_bOwner = false;
m_iVertexQuantity = rkNet.m_iVertexQuantity;
m_akVertex = rkNet.m_akVertex;
m_fXMin = rkNet.m_fXMin;
m_fXMax = rkNet.m_fXMax;
m_fXRange = rkNet.m_fXRange;
m_fYMin = rkNet.m_fYMin;
m_fYMax = rkNet.m_fYMax;
m_fYRange = rkNet.m_fYRange;
m_fZMin = rkNet.m_fZMin;
m_fZMax = rkNet.m_fZMax;
m_fZRange = rkNet.m_fZRange;
m_iTetrahedronQuantity = rkNet.m_iTetrahedronQuantity;
m_akTetrahedron = rkNet.m_akTetrahedron;
}
//----------------------------------------------------------------------------
template <class Real>
Delaunay3<Real>::~Delaunay3 ()
{
if ( m_bOwner )
{
delete[] m_akVertex;
delete[] m_akTetrahedron;
}
}
//----------------------------------------------------------------------------
template <class Real>
bool Delaunay3<Real>::IsOwner () const
{
return m_bOwner;
}
//----------------------------------------------------------------------------
template <class Real>
int Delaunay3<Real>::GetVertexQuantity () const
{
return m_iVertexQuantity;
}
//----------------------------------------------------------------------------
template <class Real>
const Vector3<Real>& Delaunay3<Real>::GetVertex (int i) const
{
assert( 0 <= i && i < m_iVertexQuantity );
return m_akVertex[i];
}
//----------------------------------------------------------------------------
template <class Real>
const Vector3<Real>* Delaunay3<Real>::GetVertices () const
{
return m_akVertex;
}
//----------------------------------------------------------------------------
template <class Real>
Real Delaunay3<Real>::GetXMin () const
{
return m_fXMin;
}
//----------------------------------------------------------------------------
template <class Real>
Real Delaunay3<Real>::GetXMax () const
{
return m_fXMax;
}
//----------------------------------------------------------------------------
template <class Real>
Real Delaunay3<Real>::GetXRange () const
{
return m_fXRange;
}
//----------------------------------------------------------------------------
template <class Real>
Real Delaunay3<Real>::GetYMin () const
{
return m_fYMin;
}
//----------------------------------------------------------------------------
template <class Real>
Real Delaunay3<Real>::GetYMax () const
{
return m_fYMax;
}
//----------------------------------------------------------------------------
template <class Real>
Real Delaunay3<Real>::GetYRange () const
{
return m_fYRange;
}
//----------------------------------------------------------------------------
template <class Real>
Real Delaunay3<Real>::GetZMin () const
{
return m_fZMin;
}
//----------------------------------------------------------------------------
template <class Real>
Real Delaunay3<Real>::GetZMax () const
{
return m_fZMax;
}
//----------------------------------------------------------------------------
template <class Real>
Real Delaunay3<Real>::GetZRange () const
{
return m_fZRange;
}
//----------------------------------------------------------------------------
template <class Real>
int Delaunay3<Real>::GetTetrahedronQuantity () const
{
return m_iTetrahedronQuantity;
}
//----------------------------------------------------------------------------
template <class Real>
typename Delaunay3<Real>::Tetrahedron& Delaunay3<Real>::GetTetrahedron (int i)
{
assert( 0 <= i && i < m_iTetrahedronQuantity );
return m_akTetrahedron[i];
}
//----------------------------------------------------------------------------
template <class Real>
const typename Delaunay3<Real>::Tetrahedron&
Delaunay3<Real>::GetTetrahedron (int i) const
{
assert( 0 <= i && i < m_iTetrahedronQuantity );
return m_akTetrahedron[i];
}
//----------------------------------------------------------------------------
template <class Real>
typename Delaunay3<Real>::Tetrahedron* Delaunay3<Real>::GetTetrahedrons ()
{
return m_akTetrahedron;
}
//----------------------------------------------------------------------------
template <class Real>
const typename Delaunay3<Real>::Tetrahedron*
Delaunay3<Real>::GetTetrahedrons () const
{
return m_akTetrahedron;
}
//----------------------------------------------------------------------------
template <class Real>
Real& Delaunay3<Real>::Epsilon ()
{
return ms_fEpsilon;
}
//----------------------------------------------------------------------------
template <class Real>
Real& Delaunay3<Real>::Range ()
{
return ms_fRange;
}
//----------------------------------------------------------------------------
template <class Real>
int& Delaunay3<Real>::TSize ()
{
return ms_iTSize;
}
//----------------------------------------------------------------------------
template <class Real>
int& Delaunay3<Real>::QuantityFactor ()
{
return ms_iQuantityFactor;
}
//----------------------------------------------------------------------------
template <class Real>
void Delaunay3<Real>::ComputeBarycenter (const Vector3<Real>& rkV0,
const Vector3<Real>& rkV1, const Vector3<Real>& rkV2,
const Vector3<Real>& rkV3, const Vector3<Real>& rkP, Real afNumer[4],
Real& rfDenom)
{
// compute the vectors relative to V0 of the tetrahedron
Vector3<Real> akDiff[4] =
{
rkV0 - rkV3,
rkV1 - rkV3,
rkV2 - rkV3,
rkP - rkV3
};
// If the vertices are of order 10^3 or larger, the linear system of
// equations for computing barycentric coordinates can be ill-conditioned.
// To avoid this, uniformly scale the tetrahedra edges to be of order 1.
// The scaling of all differences does not change the barycentric
// coordinates.
Real fMax = (Real)0.0;
int i;
for (i = 0; i < 3; i++)
{
for (int j = 0; j < 3; j++)
{
Real fValue = Math<Real>::FAbs(akDiff[i][j]);
if ( fValue > fMax )
fMax = fValue;
}
}
// scale down only large data
if ( fMax > (Real)1.0 )
{
Real fInvMax = ((Real)1.0)/fMax;
for (i = 0; i < 4; i++)
akDiff[i] *= fInvMax;
}
Real fM00 = akDiff[0].Dot(akDiff[0]);
Real fM01 = akDiff[0].Dot(akDiff[1]);
Real fM02 = akDiff[0].Dot(akDiff[2]);
Real fM11 = akDiff[1].Dot(akDiff[1]);
Real fM12 = akDiff[1].Dot(akDiff[2]);
Real fM22 = akDiff[2].Dot(akDiff[2]);
Real fR0 = akDiff[0].Dot(akDiff[3]);
Real fR1 = akDiff[1].Dot(akDiff[3]);
Real fR2 = akDiff[2].Dot(akDiff[3]);
Real fC00 = fM11*fM22-fM12*fM12;
Real fC01 = fM02*fM12-fM01*fM22;
Real fC02 = fM01*fM12-fM02*fM11;
Real fC11 = fM00*fM22-fM02*fM02;
Real fC12 = fM02*fM01-fM00*fM12;
Real fC22 = fM00*fM11-fM01*fM01;
rfDenom = fM00*fC00 + fM01*fC01 + fM02*fC02;
assert( rfDenom != (Real)0.0 );
afNumer[0] = fC00*fR0+fC01*fR1+fC02*fR2;
afNumer[1] = fC01*fR0+fC11*fR1+fC12*fR2;
afNumer[2] = fC02*fR0+fC12*fR1+fC22*fR2;
afNumer[3] = rfDenom-afNumer[0]-afNumer[1]-afNumer[2];
}
//----------------------------------------------------------------------------
template <class Real>
bool Delaunay3<Real>::InTetrahedron (const Vector3<Real>& rkV0,
const Vector3<Real>& rkV1, const Vector3<Real>& rkV2,
const Vector3<Real>& rkV3, const Vector3<Real>& rkP)
{
Real afNumer[4], fDenom;
ComputeBarycenter(rkV0,rkV1,rkV2,rkV3,rkP,afNumer,fDenom);
return InTetrahedron(afNumer,fDenom);
}
//----------------------------------------------------------------------------
template <class Real>
bool Delaunay3<Real>::InTetrahedron (const Real afNumer[4], Real fDenom)
{
Real fPerturb = Math<Real>::EPSILON*fDenom;
int i;
if ( fDenom > (Real)0.0 )
{
for (i = 0; i < 4; i++)
{
if ( afNumer[i] < -fPerturb || afNumer[i] > fDenom+fPerturb )
return false;
}
}
else
{
for (i = 0; i < 4; i++)
{
if ( afNumer[i] < fDenom+fPerturb || afNumer[i] > -fPerturb )
return false;
}
}
return true;
}
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
// explicit instantiation
//----------------------------------------------------------------------------
namespace Wml
{
template class WML_ITEM Delaunay3<float>;
float Delaunay3f::ms_fEpsilon = 0.00001f;
float Delaunay3f::ms_fRange = 10.0f;
int Delaunay3f::ms_iTSize = 75;
int Delaunay3f::ms_iQuantityFactor = 16;
template class WML_ITEM Delaunay3<double>;
double Delaunay3d::ms_fEpsilon = 0.00001;
double Delaunay3d::ms_fRange = 10.0;
int Delaunay3d::ms_iTSize = 75;
int Delaunay3d::ms_iQuantityFactor = 16;
}
//----------------------------------------------------------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -