vhacdManifoldMesh.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. // -- GODOT start --
  16. #include <cstdint>
  17. // -- GODOT end --
  18. namespace VHACD {
  19. class TMMTriangle;
  20. class TMMEdge;
  21. class TMMesh;
  22. class ICHull;
  23. //! Vertex data structure used in a triangular manifold mesh (TMM).
  24. class TMMVertex {
  25. public:
  26. void Initialize();
  27. TMMVertex(void);
  28. ~TMMVertex(void);
  29. private:
  30. Vec3<double> m_pos;
  31. int32_t m_name;
  32. size_t m_id;
  33. CircularListElement<TMMEdge>* m_duplicate; // pointer to incident cone edge (or NULL)
  34. bool m_onHull;
  35. bool m_tag;
  36. TMMVertex(const TMMVertex& rhs);
  37. friend class ICHull;
  38. friend class TMMesh;
  39. friend class TMMTriangle;
  40. friend class TMMEdge;
  41. };
  42. //! Edge data structure used in a triangular manifold mesh (TMM).
  43. class TMMEdge {
  44. public:
  45. void Initialize();
  46. TMMEdge(void);
  47. ~TMMEdge(void);
  48. private:
  49. size_t m_id;
  50. CircularListElement<TMMTriangle>* m_triangles[2];
  51. CircularListElement<TMMVertex>* m_vertices[2];
  52. CircularListElement<TMMTriangle>* m_newFace;
  53. TMMEdge(const TMMEdge& rhs);
  54. friend class ICHull;
  55. friend class TMMTriangle;
  56. friend class TMMVertex;
  57. friend class TMMesh;
  58. };
  59. //! Triangle data structure used in a triangular manifold mesh (TMM).
  60. class TMMTriangle {
  61. public:
  62. void Initialize();
  63. TMMTriangle(void);
  64. ~TMMTriangle(void);
  65. private:
  66. size_t m_id;
  67. CircularListElement<TMMEdge>* m_edges[3];
  68. CircularListElement<TMMVertex>* m_vertices[3];
  69. bool m_visible;
  70. TMMTriangle(const TMMTriangle& rhs);
  71. friend class ICHull;
  72. friend class TMMesh;
  73. friend class TMMVertex;
  74. friend class TMMEdge;
  75. };
  76. //! triangular manifold mesh data structure.
  77. class TMMesh {
  78. public:
  79. //! Returns the number of vertices>
  80. inline size_t GetNVertices() const { return m_vertices.GetSize(); }
  81. //! Returns the number of edges
  82. inline size_t GetNEdges() const { return m_edges.GetSize(); }
  83. //! Returns the number of triangles
  84. inline size_t GetNTriangles() const { return m_triangles.GetSize(); }
  85. //! Returns the vertices circular list
  86. inline const CircularList<TMMVertex>& GetVertices() const { return m_vertices; }
  87. //! Returns the edges circular list
  88. inline const CircularList<TMMEdge>& GetEdges() const { return m_edges; }
  89. //! Returns the triangles circular list
  90. inline const CircularList<TMMTriangle>& GetTriangles() const { return m_triangles; }
  91. //! Returns the vertices circular list
  92. inline CircularList<TMMVertex>& GetVertices() { return m_vertices; }
  93. //! Returns the edges circular list
  94. inline CircularList<TMMEdge>& GetEdges() { return m_edges; }
  95. //! Returns the triangles circular list
  96. inline CircularList<TMMTriangle>& GetTriangles() { return m_triangles; }
  97. //! Add vertex to the mesh
  98. CircularListElement<TMMVertex>* AddVertex() { return m_vertices.Add(); }
  99. //! Add vertex to the mesh
  100. CircularListElement<TMMEdge>* AddEdge() { return m_edges.Add(); }
  101. //! Add vertex to the mesh
  102. CircularListElement<TMMTriangle>* AddTriangle() { return m_triangles.Add(); }
  103. //! Print mesh information
  104. void Print();
  105. //!
  106. void GetIFS(Vec3<double>* const points, Vec3<int32_t>* const triangles);
  107. //!
  108. void Clear();
  109. //!
  110. void Copy(TMMesh& mesh);
  111. //!
  112. bool CheckConsistancy();
  113. //!
  114. bool Normalize();
  115. //!
  116. bool Denormalize();
  117. //! Constructor
  118. TMMesh();
  119. //! Destructor
  120. virtual ~TMMesh(void);
  121. private:
  122. CircularList<TMMVertex> m_vertices;
  123. CircularList<TMMEdge> m_edges;
  124. CircularList<TMMTriangle> m_triangles;
  125. // not defined
  126. TMMesh(const TMMesh& rhs);
  127. friend class ICHull;
  128. };
  129. }
  130. #endif // VHACD_MANIFOLD_MESH_H