vhacdManifoldMesh.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /* Copyright (c) 2011 Khaled Mamou (kmamou at gmail dot com)
  2. All rights reserved.
  3. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
  4. 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  5. 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.
  6. 3. The names of the contributors may not be used to endorse or promote products derived from this software without specific prior written permission.
  7. 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.
  8. */
  9. #pragma once
  10. #ifndef VHACD_MANIFOLD_MESH_H
  11. #define VHACD_MANIFOLD_MESH_H
  12. #include "vhacdCircularList.h"
  13. #include "vhacdSArray.h"
  14. #include "vhacdVector.h"
  15. namespace VHACD {
  16. class TMMTriangle;
  17. class TMMEdge;
  18. class TMMesh;
  19. class ICHull;
  20. //! Vertex data structure used in a triangular manifold mesh (TMM).
  21. class TMMVertex {
  22. public:
  23. void Initialize();
  24. TMMVertex(void);
  25. ~TMMVertex(void);
  26. private:
  27. Vec3<double> m_pos;
  28. int m_name;
  29. size_t m_id;
  30. CircularListElement<TMMEdge>* m_duplicate; // pointer to incident cone edge (or NULL)
  31. bool m_onHull;
  32. bool m_tag;
  33. TMMVertex(const TMMVertex& rhs);
  34. friend class ICHull;
  35. friend class TMMesh;
  36. friend class TMMTriangle;
  37. friend class TMMEdge;
  38. };
  39. //! Edge data structure used in a triangular manifold mesh (TMM).
  40. class TMMEdge {
  41. public:
  42. void Initialize();
  43. TMMEdge(void);
  44. ~TMMEdge(void);
  45. private:
  46. size_t m_id;
  47. CircularListElement<TMMTriangle>* m_triangles[2];
  48. CircularListElement<TMMVertex>* m_vertices[2];
  49. CircularListElement<TMMTriangle>* m_newFace;
  50. TMMEdge(const TMMEdge& rhs);
  51. friend class ICHull;
  52. friend class TMMTriangle;
  53. friend class TMMVertex;
  54. friend class TMMesh;
  55. };
  56. //! Triangle data structure used in a triangular manifold mesh (TMM).
  57. class TMMTriangle {
  58. public:
  59. void Initialize();
  60. TMMTriangle(void);
  61. ~TMMTriangle(void);
  62. private:
  63. size_t m_id;
  64. CircularListElement<TMMEdge>* m_edges[3];
  65. CircularListElement<TMMVertex>* m_vertices[3];
  66. bool m_visible;
  67. TMMTriangle(const TMMTriangle& rhs);
  68. friend class ICHull;
  69. friend class TMMesh;
  70. friend class TMMVertex;
  71. friend class TMMEdge;
  72. };
  73. //! triangular manifold mesh data structure.
  74. class TMMesh {
  75. public:
  76. //! Returns the number of vertices>
  77. inline size_t GetNVertices() const { return m_vertices.GetSize(); }
  78. //! Returns the number of edges
  79. inline size_t GetNEdges() const { return m_edges.GetSize(); }
  80. //! Returns the number of triangles
  81. inline size_t GetNTriangles() const { return m_triangles.GetSize(); }
  82. //! Returns the vertices circular list
  83. inline const CircularList<TMMVertex>& GetVertices() const { return m_vertices; }
  84. //! Returns the edges circular list
  85. inline const CircularList<TMMEdge>& GetEdges() const { return m_edges; }
  86. //! Returns the triangles circular list
  87. inline const CircularList<TMMTriangle>& GetTriangles() const { return m_triangles; }
  88. //! Returns the vertices circular list
  89. inline CircularList<TMMVertex>& GetVertices() { return m_vertices; }
  90. //! Returns the edges circular list
  91. inline CircularList<TMMEdge>& GetEdges() { return m_edges; }
  92. //! Returns the triangles circular list
  93. inline CircularList<TMMTriangle>& GetTriangles() { return m_triangles; }
  94. //! Add vertex to the mesh
  95. CircularListElement<TMMVertex>* AddVertex() { return m_vertices.Add(); }
  96. //! Add vertex to the mesh
  97. CircularListElement<TMMEdge>* AddEdge() { return m_edges.Add(); }
  98. //! Add vertex to the mesh
  99. CircularListElement<TMMTriangle>* AddTriangle() { return m_triangles.Add(); }
  100. //! Print mesh information
  101. void Print();
  102. //!
  103. void GetIFS(Vec3<double>* const points, Vec3<int>* const triangles);
  104. //!
  105. void Clear();
  106. //!
  107. void Copy(TMMesh& mesh);
  108. //!
  109. bool CheckConsistancy();
  110. //!
  111. bool Normalize();
  112. //!
  113. bool Denormalize();
  114. //! Constructor
  115. TMMesh();
  116. //! Destructor
  117. virtual ~TMMesh(void);
  118. private:
  119. CircularList<TMMVertex> m_vertices;
  120. CircularList<TMMEdge> m_edges;
  121. CircularList<TMMTriangle> m_triangles;
  122. // not defined
  123. TMMesh(const TMMesh& rhs);
  124. friend class ICHull;
  125. };
  126. }
  127. #endif // VHACD_MANIFOLD_MESH_H