Wm4Delaunay.cpp

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 #include "Wm4FoundationPCH.h"
00018 #include "Wm4Delaunay.h"
00019 
00020 namespace Wm4
00021 {
00022 //----------------------------------------------------------------------------
00023 template <class Real>
00024 Delaunay<Real>::Delaunay (int iVertexQuantity, Real fEpsilon, bool bOwner,
00025     Query::Type eQueryType)
00026 {
00027     assert(iVertexQuantity > 0 && fEpsilon >= (Real)0.0);
00028 
00029     m_eQueryType = eQueryType;
00030     m_iVertexQuantity = iVertexQuantity;
00031     m_iDimension = 0;
00032     m_iSimplexQuantity = 0;
00033     m_aiIndex = 0;
00034     m_aiAdjacent = 0;
00035     m_fEpsilon = fEpsilon;
00036     m_bOwner = bOwner;
00037 }
00038 //----------------------------------------------------------------------------
00039 template <class Real>
00040 Delaunay<Real>::~Delaunay ()
00041 {
00042     WM4_DELETE[] m_aiIndex;
00043     WM4_DELETE[] m_aiAdjacent;
00044 }
00045 //----------------------------------------------------------------------------
00046 template <class Real>
00047 int Delaunay<Real>::GetQueryType () const
00048 {
00049     return m_eQueryType;
00050 }
00051 //----------------------------------------------------------------------------
00052 template <class Real>
00053 int Delaunay<Real>::GetVertexQuantity () const
00054 {
00055     return m_iVertexQuantity;
00056 }
00057 //----------------------------------------------------------------------------
00058 template <class Real>
00059 Real Delaunay<Real>::GetEpsilon () const
00060 {
00061     return m_fEpsilon;
00062 }
00063 //----------------------------------------------------------------------------
00064 template <class Real>
00065 bool Delaunay<Real>::GetOwner () const
00066 {
00067     return m_bOwner;
00068 }
00069 //----------------------------------------------------------------------------
00070 template <class Real>
00071 int Delaunay<Real>::GetDimension () const
00072 {
00073     return m_iDimension;
00074 }
00075 //----------------------------------------------------------------------------
00076 template <class Real>
00077 int Delaunay<Real>::GetSimplexQuantity () const
00078 {
00079     return m_iSimplexQuantity;
00080 }
00081 //----------------------------------------------------------------------------
00082 template <class Real>
00083 const int* Delaunay<Real>::GetIndices () const
00084 {
00085     return m_aiIndex;
00086 }
00087 //----------------------------------------------------------------------------
00088 template <class Real>
00089 const int* Delaunay<Real>::GetAdjacencies () const
00090 {
00091     return m_aiAdjacent;
00092 }
00093 //----------------------------------------------------------------------------
00094 template <class Real>
00095 bool Delaunay<Real>::Load (FILE* pkIFile)
00096 {
00097     WM4_DELETE[] m_aiIndex;
00098     WM4_DELETE[] m_aiAdjacent;
00099 
00100     // fixed-size members
00101     int iQueryType;
00102     System::Read4le(pkIFile,1,&iQueryType);
00103     m_eQueryType = (Query::Type)iQueryType;
00104     System::Read4le(pkIFile,1,&m_iVertexQuantity);
00105     System::Read4le(pkIFile,1,&m_iDimension);
00106     System::Read4le(pkIFile,1,&m_iSimplexQuantity);
00107     System::Read4le(pkIFile,1,&m_fEpsilon);
00108 
00109     // variable-size members
00110     int iIQuantity;
00111     System::Read4le(pkIFile,1,&iIQuantity);
00112     if (1 <= m_iDimension && m_iDimension <= 3)
00113     {
00114         assert(iIQuantity == (m_iDimension+1)*m_iSimplexQuantity);
00115         m_aiIndex = WM4_NEW int[iIQuantity];
00116         m_aiAdjacent = WM4_NEW int[iIQuantity];
00117         System::Read4le(pkIFile,iIQuantity,m_aiIndex);
00118         System::Read4le(pkIFile,iIQuantity,m_aiAdjacent);
00119         return true;
00120     }
00121 
00122     m_aiIndex = 0;
00123     m_aiAdjacent = 0;
00124     return m_iDimension == 0;
00125 }
00126 //----------------------------------------------------------------------------
00127 template <class Real>
00128 bool Delaunay<Real>::Save (FILE* pkOFile) const
00129 {
00130     // fixed-size members
00131     int iQueryType = (int)m_eQueryType;
00132     System::Write4le(pkOFile,1,&iQueryType);
00133     System::Write4le(pkOFile,1,&m_iVertexQuantity);
00134     System::Write4le(pkOFile,1,&m_iDimension);
00135     System::Write4le(pkOFile,1,&m_iSimplexQuantity);
00136     System::Write4le(pkOFile,1,&m_fEpsilon);
00137 
00138     // The member m_bOwner is not streamed because on a Load call, this
00139     // object will allocate the vertices and own this memory.
00140 
00141     // variable-size members
00142     int iIQuantity;
00143     if (1 <= m_iDimension && m_iDimension <= 3)
00144     {
00145         iIQuantity = (m_iDimension+1)*m_iSimplexQuantity;
00146         System::Write4le(pkOFile,1,&iIQuantity);
00147         System::Write4le(pkOFile,iIQuantity,m_aiIndex);
00148         System::Write4le(pkOFile,iIQuantity,m_aiAdjacent);
00149         return true;
00150     }
00151 
00152     iIQuantity = 0;
00153     System::Write4le(pkOFile,1,&iIQuantity);
00154     return m_iDimension == 0;
00155 }
00156 //----------------------------------------------------------------------------
00157 
00158 //----------------------------------------------------------------------------
00159 // explicit instantiation
00160 //----------------------------------------------------------------------------
00161 template WM4_FOUNDATION_ITEM
00162 class Delaunay<float>;
00163 
00164 template WM4_FOUNDATION_ITEM
00165 class Delaunay<double>;
00166 //----------------------------------------------------------------------------
00167 }

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