Wm4Query3Filtered.inl

Go to the documentation of this file.
00001 // Wild Magic Source Code
00002 // David Eberly
00003 // http://www.geometrictools.com
00004 // Copyright (c) 1998-2007
00005 //
00006 // This library is free software; you can redistribute it and/or modify it
00007 // under the terms of the GNU Lesser General Public License as published by
00008 // the Free Software Foundation; either version 2.1 of the License, or (at
00009 // your option) any later version.  The license is available for reading at
00010 // either of the locations:
00011 //     http://www.gnu.org/copyleft/lgpl.html
00012 //     http://www.geometrictools.com/License/WildMagicLicense.pdf
00013 // The license applies to versions 0 through 4 of Wild Magic.
00014 //
00015 // Version: 4.0.0 (2006/06/28)
00016 
00017 namespace Wm4
00018 {
00019 //----------------------------------------------------------------------------
00020 template <class Real>
00021 Query3Filtered<Real>::Query3Filtered (int iVQuantity,
00022     const Vector3<Real>* akVertex, Real fUncertainty)
00023     :
00024     Query3<Real>(iVQuantity,akVertex),
00025     m_kRQuery(iVQuantity,akVertex)
00026 {
00027     assert((Real)0.0 <= fUncertainty && fUncertainty <= (Real)1.0);
00028     m_fUncertainty = fUncertainty;
00029 }
00030 //----------------------------------------------------------------------------
00031 template <class Real>
00032 Query3Filtered<Real>::~Query3Filtered ()
00033 {
00034 }
00035 //----------------------------------------------------------------------------
00036 template <class Real>
00037 Query::Type Query3Filtered<Real>::GetType () const
00038 {
00039     return Query::QT_FILTERED;
00040 }
00041 //----------------------------------------------------------------------------
00042 template <class Real>
00043 int Query3Filtered<Real>::ToPlane (const Vector3<Real>& rkP, int iV0, int iV1,
00044     int iV2) const
00045 {
00046     const Vector3<Real>& rkV0 = m_akVertex[iV0];
00047     const Vector3<Real>& rkV1 = m_akVertex[iV1];
00048     const Vector3<Real>& rkV2 = m_akVertex[iV2];
00049 
00050     Real fX0 = rkP[0] - rkV0[0];
00051     Real fY0 = rkP[1] - rkV0[1];
00052     Real fZ0 = rkP[2] - rkV0[2];
00053     Real fX1 = rkV1[0] - rkV0[0];
00054     Real fY1 = rkV1[1] - rkV0[1];
00055     Real fZ1 = rkV1[2] - rkV0[2];
00056     Real fX2 = rkV2[0] - rkV0[0];
00057     Real fY2 = rkV2[1] - rkV0[1];
00058     Real fZ2 = rkV2[2] - rkV0[2];
00059 
00060     Real fLen0 = Math<Real>::Sqrt(fX0*fX0 + fY0*fY0 + fZ0*fZ0);
00061     Real fLen1 = Math<Real>::Sqrt(fX1*fX1 + fY1*fY1 + fZ1*fZ1);
00062     Real fLen2 = Math<Real>::Sqrt(fX2*fX2 + fY2*fY2 + fZ2*fZ2);
00063     Real fScaledUncertainty = m_fUncertainty*fLen0*fLen1*fLen2;
00064 
00065     Real fDet3 = Det3(fX0,fY0,fZ0,fX1,fY1,fZ1,fX2,fY2,fZ2);
00066     if (Math<Real>::FAbs(fDet3) >= fScaledUncertainty)
00067     {
00068         return (fDet3 > (Real)0.0 ? +1 : (fDet3 < (Real)0.0 ? -1 : 0));
00069     }
00070 
00071     return m_kRQuery.ToPlane(rkP,iV0,iV1,iV2);
00072 }
00073 //----------------------------------------------------------------------------
00074 template <class Real>
00075 int Query3Filtered<Real>::ToCircumsphere (const Vector3<Real>& rkP, int iV0,
00076     int iV1, int iV2, int iV3) const
00077 {
00078     const Vector3<Real>& rkV0 = m_akVertex[iV0];
00079     const Vector3<Real>& rkV1 = m_akVertex[iV1];
00080     const Vector3<Real>& rkV2 = m_akVertex[iV2];
00081     const Vector3<Real>& rkV3 = m_akVertex[iV3];
00082 
00083     Real fS0x = rkV0[0] + rkP[0];
00084     Real fD0x = rkV0[0] - rkP[0];
00085     Real fS0y = rkV0[1] + rkP[1];
00086     Real fD0y = rkV0[1] - rkP[1];
00087     Real fS0z = rkV0[2] + rkP[2];
00088     Real fD0z = rkV0[2] - rkP[2];
00089     Real fS1x = rkV1[0] + rkP[0];
00090     Real fD1x = rkV1[0] - rkP[0];
00091     Real fS1y = rkV1[1] + rkP[1];
00092     Real fD1y = rkV1[1] - rkP[1];
00093     Real fS1z = rkV1[2] + rkP[2];
00094     Real fD1z = rkV1[2] - rkP[2];
00095     Real fS2x = rkV2[0] + rkP[0];
00096     Real fD2x = rkV2[0] - rkP[0];
00097     Real fS2y = rkV2[1] + rkP[1];
00098     Real fD2y = rkV2[1] - rkP[1];
00099     Real fS2z = rkV2[2] + rkP[2];
00100     Real fD2z = rkV2[2] - rkP[2];
00101     Real fS3x = rkV3[0] + rkP[0];
00102     Real fD3x = rkV3[0] - rkP[0];
00103     Real fS3y = rkV3[1] + rkP[1];
00104     Real fD3y = rkV3[1] - rkP[1];
00105     Real fS3z = rkV3[2] + rkP[2];
00106     Real fD3z = rkV3[2] - rkP[2];
00107     Real fW0 = fS0x*fD0x + fS0y*fD0y + fS0z*fD0z;
00108     Real fW1 = fS1x*fD1x + fS1y*fD1y + fS1z*fD1z;
00109     Real fW2 = fS2x*fD2x + fS2y*fD2y + fS2z*fD2z;
00110     Real fW3 = fS3x*fD3x + fS3y*fD3y + fS3z*fD3z;
00111 
00112     Real fLen0 = Math<Real>::Sqrt(fD0x*fD0x+fD0y*fD0y+fD0z*fD0z+fW0*fW0);
00113     Real fLen1 = Math<Real>::Sqrt(fD1x*fD1x+fD1y*fD1y+fD1z*fD1z+fW1*fW1);
00114     Real fLen2 = Math<Real>::Sqrt(fD2x*fD2x+fD2y*fD2y+fD2z*fD2z+fW2*fW2);
00115     Real fLen3 = Math<Real>::Sqrt(fD3x*fD3x+fD3y*fD3y+fD3z*fD3z+fW3*fW3);
00116     Real fScaledUncertainty = m_fUncertainty*fLen0*fLen1*fLen2*fLen3;
00117 
00118     Real fDet4 = Det4(fD0x,fD0y,fD0z,fW0,fD1x,fD1y,fD1z,fW1,fD2x,
00119         fD2y,fD2z,fW2,fD3x,fD3y,fD3z,fW3);
00120 
00121     if (Math<Real>::FAbs(fDet4) >= fScaledUncertainty)
00122     {
00123         return (fDet4 > (Real)0.0 ? 1 : (fDet4 < (Real)0.0 ? -1 : 0));
00124     }
00125 
00126     return m_kRQuery.ToCircumsphere(rkP,iV0,iV1,iV2,iV3);
00127 }
00128 //----------------------------------------------------------------------------
00129 } //namespace Wm4

Generated on Wed Nov 23 19:01:07 2011 for FreeCAD by  doxygen 1.6.1