Wm4Mapper2.inl
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
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
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
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
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
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 }
00166