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 #ifndef WM4DELAUNAY1_H 00018 #define WM4DELAUNAY1_H 00019 00020 // A fancy class to sort a collection of real-valued numbers, but this 00021 // provides some convenience for Delaunay2 and Delaunay3 when the input point 00022 // set has intrinsic dimension smaller than the containing space. The 00023 // interface of Delaunay1 is also the model for those of Delaunay2 and 00024 // Delaunay3. 00025 00026 #include "Wm4FoundationLIB.h" 00027 #include "Wm4Delaunay.h" 00028 00029 namespace Wm4 00030 { 00031 00032 template <class Real> 00033 class WM4_FOUNDATION_ITEM Delaunay1 : public Delaunay<Real> 00034 { 00035 public: 00036 // The input to the constructor is the array of vertices you want to sort. 00037 // If you want Delaunay1 to delete the array during destruction, set 00038 // bOwner to 'true'. Otherwise, you own the array and must delete it 00039 // yourself. TO DO: The query type is currently ignored by this class. 00040 // Add support for the various types later. 00041 Delaunay1 (int iVertexQuantity, Real* afVertex, Real fEpsilon, 00042 bool bOwner, Query::Type eQueryType); 00043 virtual ~Delaunay1 (); 00044 00045 // The input vertex array. 00046 const Real* GetVertices () const; 00047 00048 // The functions listed here are valid only for dimension 1. 00049 00050 // The convex hull of the vertices is an interval. This function returns 00051 // the indices of the vertices that form the interval. The return value 00052 // is 'true' iff the dimension is 1. 00053 bool GetHull (int aiIndex[2]); 00054 00055 // Support for searching the sorted vertices for a interval that contains 00056 // P. If there is a containing interval, the returned value is a index i 00057 // into the GetIndices() array with 0 <= i < GetSimplexQuantity(). If 00058 // there is not a containing segment, -1 is returned. 00059 int GetContainingSegment (const Real fP) const; 00060 00061 // Get the vertices for segment i. The function returns 'true' if i is a 00062 // valid segment index, in which case the vertices are valid. Otherwise, 00063 // the function returns 'false' and the vertices are invalid. 00064 bool GetVertexSet (int i, Real afV[2]) const; 00065 00066 // Get the vertex indices for segment i. The function returns 'true' if 00067 // i is a valid segment index, in which case the vertices are valid. 00068 // Otherwise, the function returns 'false' and the vertices are invalid. 00069 bool GetIndexSet (int i, int aiIndex[2]) const; 00070 00071 // Get the indices for segments adjacent to segment i. The function 00072 // returns 'true' if i is a valid segment index, in which case the 00073 // adjacencies are valid. Otherwise, the function returns 'false' and 00074 // the adjacencies are invalid. 00075 bool GetAdjacentSet (int i, int aiAdjacent[2]) const; 00076 00077 // Compute the barycentric coordinates of P with respect to segment i. 00078 // The function returns 'true' if i is a valid segment index, in which 00079 // case the coordinates are valid. Otherwise, the function returns 00080 // 'false' and the coordinate array is invalid. 00081 bool GetBarycentricSet (int i, const Real fP, Real afBary[2]) const; 00082 00083 // Support for streaming to/from disk. 00084 Delaunay1 (const char* acFilename); 00085 bool Load (const char* acFilename); 00086 bool Save (const char* acFilename) const; 00087 00088 private: 00089 using Delaunay<Real>::m_iVertexQuantity; 00090 using Delaunay<Real>::m_iDimension; 00091 using Delaunay<Real>::m_iSimplexQuantity; 00092 using Delaunay<Real>::m_aiIndex; 00093 using Delaunay<Real>::m_aiAdjacent; 00094 using Delaunay<Real>::m_fEpsilon; 00095 using Delaunay<Real>::m_bOwner; 00096 00097 Real* m_afVertex; 00098 00099 class WM4_FOUNDATION_ITEM SortedVertex 00100 { 00101 public: 00102 Real Value; 00103 int Index; 00104 00105 bool operator< (const SortedVertex& rkProj) const 00106 { 00107 return Value < rkProj.Value; 00108 } 00109 }; 00110 }; 00111 00112 typedef Delaunay1<float> Delaunay1f; 00113 typedef Delaunay1<double> Delaunay1d; 00114 00115 } 00116 00117 #endif