Main Page Class List Class Members

vhacdMesh.h
Go to the documentation of this file.
1 /* Copyright (c) 2011 Khaled Mamou (kmamou at gmail dot com)
2 All 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_MESH_H
17 #define VHACD_MESH_H
18 #include "vhacdSArray.h"
19 #include "vhacdVector.h"
20
21 #define VHACD_DEBUG_MESH
22
23 namespace VHACD {
24 enum AXIS {
25 AXIS_X = 0,
26 AXIS_Y = 1,
27 AXIS_Z = 2
28 };
29 struct Plane {
30 double m_a;
31 double m_b;
32 double m_c;
33 double m_d;
34 AXIS m_axis;
35 short m_index;
36 };
37 #ifdef VHACD_DEBUG_MESH
38 struct Material {
39
40 Vec3<double> m_diffuseColor;
41 double m_ambientIntensity;
42 Vec3<double> m_specularColor;
43 Vec3<double> m_emissiveColor;
44 double m_shininess;
45 double m_transparency;
46 Material(void)
47 {
48 m_diffuseColor.X() = 0.5;
49 m_diffuseColor.Y() = 0.5;
50 m_diffuseColor.Z() = 0.5;
51 m_specularColor.X() = 0.5;
52 m_specularColor.Y() = 0.5;
53 m_specularColor.Z() = 0.5;
54 m_ambientIntensity = 0.4;
55 m_emissiveColor.X() = 0.0;
56 m_emissiveColor.Y() = 0.0;
57 m_emissiveColor.Z() = 0.0;
58 m_shininess = 0.4;
59 m_transparency = 0.0;
60 };
61 };
62 #endif // VHACD_DEBUG_MESH
63
65 class Mesh {
66 public:
67 void AddPoint(const Vec3<double>& pt) { m_points.PushBack(pt); };
68 void SetPoint(size_t index, const Vec3<double>& pt) { m_points[index] = pt; };
69 const Vec3<double>& GetPoint(size_t index) const { return m_points[index]; };
70 Vec3<double>& GetPoint(size_t index) { return m_points[index]; };
71 size_t GetNPoints() const { return m_points.Size(); };
72 double* GetPoints() { return (double*)m_points.Data(); } // ugly
73 const double* const GetPoints() const { return (double*)m_points.Data(); } // ugly
74 const Vec3<double>* const GetPointsBuffer() const { return m_points.Data(); } //
75 Vec3<double>* const GetPointsBuffer() { return m_points.Data(); } //
76 void AddTriangle(const Vec3<int32_t>& tri) { m_triangles.PushBack(tri); };
77 void SetTriangle(size_t index, const Vec3<int32_t>& tri) { m_triangles[index] = tri; };
78 const Vec3<int32_t>& GetTriangle(size_t index) const { return m_triangles[index]; };
79 Vec3<int32_t>& GetTriangle(size_t index) { return m_triangles[index]; };
80 size_t GetNTriangles() const { return m_triangles.Size(); };
81 int32_t* GetTriangles() { return (int32_t*)m_triangles.Data(); } // ugly
82 const int32_t* const GetTriangles() const { return (int32_t*)m_triangles.Data(); } // ugly
83 const Vec3<int32_t>* const GetTrianglesBuffer() const { return m_triangles.Data(); }
84 Vec3<int32_t>* const GetTrianglesBuffer() { return m_triangles.Data(); }
85 const Vec3<double>& GetCenter() const { return m_center; }
86 const Vec3<double>& GetMinBB() const { return m_minBB; }
87 const Vec3<double>& GetMaxBB() const { return m_maxBB; }
88 void ClearPoints() { m_points.Clear(); }
89 void ClearTriangles() { m_triangles.Clear(); }
90 void Clear()
91 {
92 ClearPoints();
93 ClearTriangles();
94 }
95 void ResizePoints(size_t nPts) { m_points.Resize(nPts); }
96 void ResizeTriangles(size_t nTri) { m_triangles.Resize(nTri); }
97 void CopyPoints(SArray<Vec3<double> >& points) const { points = m_points; }
98 double GetDiagBB() const { return m_diag; }
99 double ComputeVolume() const;
100 void ComputeConvexHull(const double* const pts,
101 const size_t nPts);
102 void Clip(const Plane& plane,
103 SArray<Vec3<double> >& positivePart,
104 SArray<Vec3<double> >& negativePart) const;
105 bool IsInside(const Vec3<double>& pt) const;
106 double ComputeDiagBB();
107 Vec3<double> &ComputeCenter(void);
108
109 #ifdef VHACD_DEBUG_MESH
110 bool LoadOFF(const std::string& fileName, bool invert);
111 bool SaveVRML2(const std::string& fileName) const;
112 bool SaveVRML2(std::ofstream& fout, const Material& material) const;
113 bool SaveOFF(const std::string& fileName) const;
114 #endif // VHACD_DEBUG_MESH
115
117 Mesh();
119 ~Mesh(void);
120
121 private:
122 SArray<Vec3<double> > m_points;
123 SArray<Vec3<int32_t> > m_triangles;
124 Vec3<double> m_minBB;
125 Vec3<double> m_maxBB;
126 Vec3<double> m_center;
127 double m_diag;
128 };
129 }
130 #endif
VHACD::Mesh::SetTriangle
void SetTriangle(size_t index, const Vec3< int32_t > &tri)
Definition: vhacdMesh.h:77
VHACD::Mesh::AddPoint
void AddPoint(const Vec3< double > &pt)
Definition: vhacdMesh.h:67
VHACD::AXIS_Y
Definition: vhacdMesh.h:26
vhacdSArray.h
VHACD::Mesh::CopyPoints
void CopyPoints(SArray< Vec3< double > > &points) const
Definition: vhacdMesh.h:97
VHACD::Vec3::X
T & X()
VHACD::Mesh::GetTriangles
const int32_t *const GetTriangles() const
Definition: vhacdMesh.h:82
VHACD::Mesh::SetPoint
void SetPoint(size_t index, const Vec3< double > &pt)
Definition: vhacdMesh.h:68
VHACD::Material::m_specularColor
Vec3< double > m_specularColor
Definition: vhacdMesh.h:42
VHACD::Mesh::GetTriangle
const Vec3< int32_t > & GetTriangle(size_t index) const
Definition: vhacdMesh.h:78
VHACD::Plane
Definition: vhacdMesh.h:29
VHACD::Mesh::GetPoint
Vec3< double > & GetPoint(size_t index)
Definition: vhacdMesh.h:70
VHACD::Mesh::GetNTriangles
size_t GetNTriangles() const
Definition: vhacdMesh.h:80
VHACD::Mesh::GetCenter
const Vec3< double > & GetCenter() const
Definition: vhacdMesh.h:85
VHACD::Material
Definition: vhacdMesh.h:38
VHACD::Mesh::GetPointsBuffer
Vec3< double > *const GetPointsBuffer()
Definition: vhacdMesh.h:75
VHACD::SArray
SArray.
Definition: vhacdSArray.h:27
VHACD::Mesh::GetTrianglesBuffer
Vec3< int32_t > *const GetTrianglesBuffer()
Definition: vhacdMesh.h:84
VHACD::Vec3::Z
T & Z()
VHACD::Plane::m_b
double m_b
Definition: vhacdMesh.h:31
VHACD::AXIS_Z
Definition: vhacdMesh.h:27
VHACD::Mesh
Triangular mesh data structure.
Definition: vhacdMesh.h:65
VHACD::Vec3::Y
T & Y()
VHACD::Material::m_diffuseColor
Vec3< double > m_diffuseColor
Definition: vhacdMesh.h:40
VHACD::Plane::m_axis
AXIS m_axis
Definition: vhacdMesh.h:34
VHACD::Mesh::ResizeTriangles
void ResizeTriangles(size_t nTri)
Definition: vhacdMesh.h:96
VHACD::Mesh::ClearPoints
void ClearPoints()
Definition: vhacdMesh.h:88
VHACD::Mesh::GetPointsBuffer
const Vec3< double > *const GetPointsBuffer() const
Definition: vhacdMesh.h:74
VHACD::Mesh::GetTriangles
int32_t * GetTriangles()
Definition: vhacdMesh.h:81
VHACD::Mesh::GetMaxBB
const Vec3< double > & GetMaxBB() const
Definition: vhacdMesh.h:87
VHACD::Mesh::GetPoints
double * GetPoints()
Definition: vhacdMesh.h:72
VHACD::Material::m_shininess
double m_shininess
Definition: vhacdMesh.h:44
VHACD::Plane::m_d
double m_d
Definition: vhacdMesh.h:33
VHACD::Mesh::GetPoints
const double *const GetPoints() const
Definition: vhacdMesh.h:73
VHACD::Mesh::ResizePoints
void ResizePoints(size_t nPts)
Definition: vhacdMesh.h:95
VHACD
Definition: vhacdCircularList.h:19
VHACD::Mesh::GetTrianglesBuffer
const Vec3< int32_t > *const GetTrianglesBuffer() const
Definition: vhacdMesh.h:83
VHACD::Mesh::GetDiagBB
double GetDiagBB() const
Definition: vhacdMesh.h:98
VHACD::Material::m_ambientIntensity
double m_ambientIntensity
Definition: vhacdMesh.h:41
VHACD::Material::m_transparency
double m_transparency
Definition: vhacdMesh.h:45
VHACD::AXIS
AXIS
Definition: vhacdMesh.h:24
VHACD::Material::m_emissiveColor
Vec3< double > m_emissiveColor
Definition: vhacdMesh.h:43
VHACD::Mesh::GetNPoints
size_t GetNPoints() const
Definition: vhacdMesh.h:71
VHACD::Mesh::ClearTriangles
void ClearTriangles()
Definition: vhacdMesh.h:89
VHACD::AXIS_X
Definition: vhacdMesh.h:25
VHACD::Mesh::GetTriangle
Vec3< int32_t > & GetTriangle(size_t index)
Definition: vhacdMesh.h:79
VHACD::Plane::m_index
short m_index
Definition: vhacdMesh.h:35
VHACD::Plane::m_a
double m_a
Definition: vhacdMesh.h:30
VHACD::Material::Material
Material(void)
Definition: vhacdMesh.h:46
VHACD::Mesh::GetMinBB
const Vec3< double > & GetMinBB() const
Definition: vhacdMesh.h:86
VHACD::Plane::m_c
double m_c
Definition: vhacdMesh.h:32
VHACD::Vec3< double >
VHACD::Mesh::Clear
void Clear()
Definition: vhacdMesh.h:90
vhacdVector.h
VHACD::Mesh::AddTriangle
void AddTriangle(const Vec3< int32_t > &tri)
Definition: vhacdMesh.h:76
VHACD::Mesh::GetPoint
const Vec3< double > & GetPoint(size_t index) const
Definition: vhacdMesh.h:69