00001 /* Copyright (c) 2011 Khaled Mamou (kmamou at gmail dot com) 00002 All rights reserved. 00003 00004 00005 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 00006 00007 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 00008 00009 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 00010 00011 3. The names of the contributors may not be used to endorse or promote products derived from this software without specific prior written permission. 00012 00013 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00014 */ 00015 #pragma once 00016 #ifndef VHACD_MANIFOLD_MESH_H 00017 #define VHACD_MANIFOLD_MESH_H 00018 #include "vhacdCircularList.h" 00019 #include "vhacdSArray.h" 00020 #include "vhacdVector.h" 00021 namespace VHACD { 00022 class TMMTriangle; 00023 class TMMEdge; 00024 class TMMesh; 00025 class ICHull; 00026 00028 class TMMVertex { 00029 public: 00030 void Initialize(); 00031 TMMVertex(void); 00032 ~TMMVertex(void); 00033 00034 private: 00035 Vec3<double> m_pos; 00036 int32_t m_name; 00037 size_t m_id; 00038 CircularListElement<TMMEdge>* m_duplicate; // pointer to incident cone edge (or NULL) 00039 bool m_onHull; 00040 bool m_tag; 00041 TMMVertex(const TMMVertex& rhs); 00042 friend class ICHull; 00043 friend class TMMesh; 00044 friend class TMMTriangle; 00045 friend class TMMEdge; 00046 }; 00047 00049 class TMMEdge { 00050 public: 00051 void Initialize(); 00052 TMMEdge(void); 00053 ~TMMEdge(void); 00054 00055 private: 00056 size_t m_id; 00057 CircularListElement<TMMTriangle>* m_triangles[2]; 00058 CircularListElement<TMMVertex>* m_vertices[2]; 00059 CircularListElement<TMMTriangle>* m_newFace; 00060 TMMEdge(const TMMEdge& rhs); 00061 friend class ICHull; 00062 friend class TMMTriangle; 00063 friend class TMMVertex; 00064 friend class TMMesh; 00065 }; 00066 00068 class TMMTriangle { 00069 public: 00070 void Initialize(); 00071 TMMTriangle(void); 00072 ~TMMTriangle(void); 00073 00074 private: 00075 size_t m_id; 00076 CircularListElement<TMMEdge>* m_edges[3]; 00077 CircularListElement<TMMVertex>* m_vertices[3]; 00078 bool m_visible; 00079 00080 TMMTriangle(const TMMTriangle& rhs); 00081 friend class ICHull; 00082 friend class TMMesh; 00083 friend class TMMVertex; 00084 friend class TMMEdge; 00085 }; 00087 class TMMesh { 00088 public: 00090 inline size_t GetNVertices() const { return m_vertices.GetSize(); } 00092 inline size_t GetNEdges() const { return m_edges.GetSize(); } 00094 inline size_t GetNTriangles() const { return m_triangles.GetSize(); } 00096 inline const CircularList<TMMVertex>& GetVertices() const { return m_vertices; } 00098 inline const CircularList<TMMEdge>& GetEdges() const { return m_edges; } 00100 inline const CircularList<TMMTriangle>& GetTriangles() const { return m_triangles; } 00102 inline CircularList<TMMVertex>& GetVertices() { return m_vertices; } 00104 inline CircularList<TMMEdge>& GetEdges() { return m_edges; } 00106 inline CircularList<TMMTriangle>& GetTriangles() { return m_triangles; } 00108 CircularListElement<TMMVertex>* AddVertex() { return m_vertices.Add(); } 00110 CircularListElement<TMMEdge>* AddEdge() { return m_edges.Add(); } 00112 CircularListElement<TMMTriangle>* AddTriangle() { return m_triangles.Add(); } 00114 void Print(); 00116 void GetIFS(Vec3<double>* const points, Vec3<int32_t>* const triangles); 00118 void Clear(); 00120 void Copy(TMMesh& mesh); 00122 bool CheckConsistancy(); 00124 bool Normalize(); 00126 bool Denormalize(); 00128 TMMesh(); 00130 virtual ~TMMesh(void); 00131 00132 private: 00133 CircularList<TMMVertex> m_vertices; 00134 CircularList<TMMEdge> m_edges; 00135 CircularList<TMMTriangle> m_triangles; 00136 00137 // not defined 00138 TMMesh(const TMMesh& rhs); 00139 friend class ICHull; 00140 }; 00141 } 00142 #endif // VHACD_MANIFOLD_MESH_H