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