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 WM4DELAUNAY3_H 00018 #define WM4DELAUNAY3_H 00019 00020 #include "Wm4FoundationLIB.h" 00021 #include "Wm4Delaunay1.h" 00022 #include "Wm4Delaunay2.h" 00023 #include "Wm4DelTetrahedron.h" 00024 #include "Wm4Query3.h" 00025 00026 namespace Wm4 00027 { 00028 00029 template <class Real> 00030 class WM4_FOUNDATION_ITEM Delaunay3 : public Delaunay<Real> 00031 { 00032 public: 00033 // The input to the constructor is the array of vertices whose Delaunay 00034 // tetrahedralization is required. If you want Delaunay3 to delete the 00035 // vertices during destruction, set bOwner to 'true'. Otherwise, you 00036 // own the vertices and must delete them yourself. Before using this 00037 // class, you should "clean" your input points by removing duplicates. 00038 // 00039 // You have a choice of speed versus accuracy. The fastest choice is 00040 // Query::QT_INT64, but it gives up a lot of precision, scaling the points 00041 // to [0,2^{10}]^3. The choice Query::QT_INTEGER gives up less precision, 00042 // scaling the points to [0,2^{20}]^3. The choice Query::QT_RATIONAL uses 00043 // exact arithmetic, but is the slowest choice. The choice Query::QT_REAL 00044 // uses floating-point arithmetic, but is not robust in all cases. 00045 00046 Delaunay3 (int iVertexQuantity, Vector3<Real>* akVertex, Real fEpsilon, 00047 bool bOwner, Query::Type eQueryType); 00048 virtual ~Delaunay3 (); 00049 00050 // The input vertex array. 00051 const Vector3<Real>* GetVertices () const; 00052 00053 // The number of unique vertices processed. 00054 int GetUniqueVertexQuantity () const; 00055 00056 // If GetDimension() returns 1, then the points lie on a line. You must 00057 // create a Delaunay1 object using the function provided. 00058 const Vector3<Real>& GetLineOrigin () const; 00059 const Vector3<Real>& GetLineDirection () const; 00060 Delaunay1<Real>* GetDelaunay1 () const; 00061 00062 // If GetDimension() returns 2, then the points lie on a plane. The plane 00063 // has two direction vectors (inputs 0 or 1). You must create a Delaunay2 00064 // object using the function provided. 00065 const Vector3<Real>& GetPlaneOrigin () const; 00066 const Vector3<Real>& GetPlaneDirection (int i) const; 00067 Delaunay2<Real>* GetDelaunay2 () const; 00068 00069 // Locate those tetrahedra faces that do not share other tetrahedra. 00070 // The returned quantity is the number of triangles in the hull. The 00071 // returned array has 3*quantity indices, each triple representing a 00072 // triangle. The triangles are counterclockwise ordered when viewed 00073 // from outside the hull. The return value is 'true' iff the dimension 00074 // is 3. 00075 bool GetHull (int& riTQuantity, int*& raiIndex) const; 00076 00077 // Support for searching the tetrahedralization for a tetrahedron that 00078 // contains a point. If there is a containing tetrahedron, the returned 00079 // value is a tetrahedron index i with 0 <= i < riTQuantity. If there is 00080 // not a containing tetrahedron, -1 is returned. 00081 int GetContainingTetrahedron (const Vector3<Real>& rkP) const; 00082 00083 // If GetContainingTetrahedron returns a nonnegative value, the path of 00084 // tetrahedra searched for the containing tetrahedra is stored in an 00085 // array. The last index of the array is returned by GetPathLast; it is 00086 // one less than the number of array elements. The array itself is 00087 // returned by GetPath. 00088 int GetPathLast () const; 00089 const int* GetPath () const; 00090 00091 // If GetContainingTetrahedron returns -1, the path of tetrahedra 00092 // searched may be obtained by GetPathLast and GetPath. The input point 00093 // is outside a face of the last tetrahedron in the path. This function 00094 // returns the vertex indices <v0,v1,v2> of the face, listed in 00095 // counterclockwise order relative to the convex hull of the data points 00096 // as viewed by an outside observer. The final output is the index of the 00097 // vertex v3 opposite the face. The return value of the function is the 00098 // index of the quadruple of vertex indices; the value is 0, 1, 2, or 3. 00099 int GetLastFace (int& riV0, int& riV1, int& riV2, int& riV3) const; 00100 00101 // Get the vertices for tetrahedron i. The function returns 'true' if i 00102 // is a valid tetrahedron index, in which case the vertices are valid. 00103 // Otherwise, the function returns 'false' and the vertices are invalid. 00104 bool GetVertexSet (int i, Vector3<Real> akV[4]) const; 00105 00106 // Get the vertex indices for tetrahedron i. The function returns 'true' 00107 // if i is a valid tetrahedron index, in which case the vertices are 00108 // valid. Otherwise, the function returns 'false' and the vertices are 00109 // invalid. 00110 bool GetIndexSet (int i, int aiIndex[4]) const; 00111 00112 // Get the indices for tetrahedra adjacent to tetrahedron i. The function 00113 // returns 'true' if i is a valid tetrahedron index, in which case the 00114 // adjacencies are valid. Otherwise, the function returns 'false' and 00115 // the adjacencies are invalid. 00116 bool GetAdjacentSet (int i, int aiAdjacent[4]) const; 00117 00118 // Compute the barycentric coordinates of P with respect to tetrahedron i. 00119 // The function returns 'true' if i is a valid tetrahedron index, in which 00120 // case the coordinates are valid. Otherwise, the function returns 00121 // 'false' and the coordinate array is invalid. 00122 bool GetBarycentricSet (int i, const Vector3<Real>& rkP, Real afBary[4]) 00123 const; 00124 00125 // Support for streaming to/from disk. 00126 Delaunay3 (const char* acFilename); 00127 bool Load (const char* acFilename); 00128 bool Save (const char* acFilename) const; 00129 00130 private: 00131 using Delaunay<Real>::m_eQueryType; 00132 using Delaunay<Real>::m_iVertexQuantity; 00133 using Delaunay<Real>::m_iDimension; 00134 using Delaunay<Real>::m_iSimplexQuantity; 00135 using Delaunay<Real>::m_aiIndex; 00136 using Delaunay<Real>::m_aiAdjacent; 00137 using Delaunay<Real>::m_fEpsilon; 00138 using Delaunay<Real>::m_bOwner; 00139 00140 void Update (int i); 00141 DelTetrahedron<Real>* GetContainingTetrahedron (int i) const; 00142 void RemoveTetrahedra (); 00143 bool IsSupervertex (int i) const; 00144 bool SharesFace (int i, DelTetrahedron<Real>* pkFace, 00145 DelTetrahedron<Real>* pkAdj); 00146 00147 // The input vertices. 00148 Vector3<Real>* m_akVertex; 00149 00150 // The number of unique vertices processed. 00151 int m_iUniqueVertexQuantity; 00152 00153 // The scaled input vertices with additional storage for the four 00154 // supertetrahedron vertices. This array and supporting data structures 00155 // are for robust calculations. 00156 Vector3<Real>* m_akSVertex; 00157 Query3<Real>* m_pkQuery; 00158 Vector3<Real> m_kMin; 00159 Real m_fScale; 00160 00161 // The indices for the three supertetrahedron vertices. 00162 int m_aiSV[4]; 00163 00164 // The current tetrahedralization. 00165 std::set<DelTetrahedron<Real>*> m_kTetrahedron; 00166 00167 // The line of containment if the dimension is 1. 00168 Vector3<Real> m_kLineOrigin, m_kLineDirection; 00169 00170 // The plane of containment if the dimension is 2. 00171 Vector3<Real> m_kPlaneOrigin, m_akPlaneDirection[2]; 00172 00173 // Store the path of tetrahedra visited in a GetContainingTetrahedron 00174 // function call. 00175 mutable int m_iPathLast; 00176 mutable int* m_aiPath; 00177 00178 // If a query point is not in the convex hull of the input points, the 00179 // point is outside a face of the last tetrahedron in the search path. 00180 // These are the vertex indices for that face. 00181 mutable int m_iLastFaceV0, m_iLastFaceV1, m_iLastFaceV2; 00182 mutable int m_iLastFaceOpposite, m_iLastFaceOppositeIndex; 00183 }; 00184 00185 typedef Delaunay3<float> Delaunay3f; 00186 typedef Delaunay3<double> Delaunay3d; 00187 00188 } 00189 00190 #endif