Wm4Mapper2.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 Mapper2<Real>::Mapper2 (int iVQuantity, const Vector2<Real>* akVertex,
00022     Real fEpsilon)
00023 {
00024     assert(iVQuantity > 0 && akVertex && fEpsilon >= (Real)0.0);
00025     m_bExtremeCCW = false;
00026 
00027     // Compute the axis-aligned bounding box for the input points.
00028     m_kMin = akVertex[0];
00029     m_kMax = m_kMin;
00030 
00031     int aiIMin[2], aiIMax[2], i, j;
00032     for (j = 0; j < 2; j++)
00033     {
00034         aiIMin[j] = 0;
00035         aiIMax[j] = 0;
00036     }
00037 
00038     for (i = 1; i < iVQuantity; i++)
00039     {
00040         for (j = 0; j < 2; j++)
00041         {
00042             if (akVertex[i][j] < m_kMin[j])
00043             {
00044                 m_kMin[j] = akVertex[i][j];
00045                 aiIMin[j] = i;
00046             }
00047             else if (akVertex[i][j] > m_kMax[j])
00048             {
00049                 m_kMax[j] = akVertex[i][j];
00050                 aiIMax[j] = i;
00051             }
00052         }
00053     }
00054 
00055     // Determine the maximum range for the bounding box.
00056     Vector2<Real> kRange = m_kMax - m_kMin;
00057     m_fMaxRange = kRange[0];
00058     m_aiExtreme[0] = aiIMin[0];
00059     m_aiExtreme[1] = aiIMax[0];
00060     if (kRange[1] > m_fMaxRange)
00061     {
00062         m_fMaxRange = kRange[1];
00063         m_aiExtreme[0] = aiIMin[1];
00064         m_aiExtreme[1] = aiIMax[1];
00065     }
00066     m_kOrigin = akVertex[m_aiExtreme[0]];
00067 
00068     // Test if the point set is (nearly) a point.
00069     if (m_fMaxRange < fEpsilon)
00070     {
00071         m_iDimension = 0;
00072         m_aiExtreme[1] = m_aiExtreme[0];
00073         m_aiExtreme[2] = m_aiExtreme[0];
00074         m_akDirection[0] = Vector2<Real>::ZERO;
00075         m_akDirection[1] = Vector2<Real>::ZERO;
00076         return;
00077     }
00078 
00079     // Test if the point set is (nearly) a line segment.
00080     m_akDirection[0] = akVertex[m_aiExtreme[1]] - m_kOrigin;
00081     m_akDirection[0].Normalize();
00082     m_akDirection[1] = -m_akDirection[0].Perp();
00083     Real fLMax = (Real)0.0, fMaxSign = (Real)0.0;
00084     m_aiExtreme[2] = m_aiExtreme[0];
00085     for (i = 0; i < iVQuantity; i++)
00086     {
00087         Vector2<Real> kDiff = akVertex[i] - m_kOrigin;
00088         Real fL = m_akDirection[1].Dot(kDiff);
00089         Real fSign = Math<Real>::Sign(fL);
00090         fL = Math<Real>::FAbs(fL);
00091         if (fL > fLMax)
00092         {
00093             fLMax = fL;
00094             fMaxSign = fSign;
00095             m_aiExtreme[2] = i;
00096         }
00097     }
00098 
00099     if (fLMax < fEpsilon*m_fMaxRange)
00100     {
00101         m_iDimension = 1;
00102         m_aiExtreme[2] = m_aiExtreme[1];
00103         return;
00104     }
00105 
00106     m_iDimension = 2;
00107     m_bExtremeCCW = (fMaxSign > (Real)0.0 ? true : false);
00108 }
00109 //----------------------------------------------------------------------------
00110 template <class Real>
00111 Mapper2<Real>::~Mapper2 ()
00112 {
00113 }
00114 //----------------------------------------------------------------------------
00115 template <class Real>
00116 const Vector2<Real>& Mapper2<Real>::GetMin () const
00117 {
00118     return m_kMin;
00119 }
00120 //----------------------------------------------------------------------------
00121 template <class Real>
00122 const Vector2<Real>& Mapper2<Real>::GetMax () const
00123 {
00124     return m_kMax;
00125 }
00126 //----------------------------------------------------------------------------
00127 template <class Real>
00128 Real Mapper2<Real>::GetMaxRange () const
00129 {
00130     return m_fMaxRange;
00131 }
00132 //----------------------------------------------------------------------------
00133 template <class Real>
00134 int Mapper2<Real>::GetDimension () const
00135 {
00136     return m_iDimension;
00137 }
00138 //----------------------------------------------------------------------------
00139 template <class Real>
00140 const Vector2<Real>& Mapper2<Real>::GetOrigin () const
00141 {
00142     return m_kOrigin;
00143 }
00144 //----------------------------------------------------------------------------
00145 template <class Real>
00146 const Vector2<Real>& Mapper2<Real>::GetDirection (int i) const
00147 {
00148     assert(0 <= i && i < 2);
00149     return m_akDirection[i];
00150 }
00151 //----------------------------------------------------------------------------
00152 template <class Real>
00153 int Mapper2<Real>::GetExtremeIndex (int i) const
00154 {
00155     assert(0 <= i && i < 3);
00156     return m_aiExtreme[i];
00157 }
00158 //----------------------------------------------------------------------------
00159 template <class Real>
00160 bool Mapper2<Real>::GetExtremeCCW () const
00161 {
00162     return m_bExtremeCCW;
00163 }
00164 //----------------------------------------------------------------------------
00165 } // namespace Wm4
00166 

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