Tesseract
Motion Planning Environment
Loading...
Searching...
No Matches
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
6 following conditions are met:
7
8 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following
9 disclaimer.
10
11 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
12 disclaimer in the documentation and/or other materials provided with the distribution.
13
14 3. The names of the contributors may not be used to endorse or promote products derived from this software without
15 specific prior written permission.
16
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
18 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25#pragma once
26
29
30#define VHACD_DEBUG_MESH
31
32namespace tesseract_collision
33{
34namespace VHACD
35{
36enum AXIS
37{
38 AXIS_X = 0,
39 AXIS_Y = 1,
40 AXIS_Z = 2
41};
42struct Plane
43{
44 double m_a;
45 double m_b;
46 double m_c;
47 double m_d;
49 short m_index;
50};
51#ifdef VHACD_DEBUG_MESH
53{
61 {
62 m_diffuseColor.X() = 0.5;
63 m_diffuseColor.Y() = 0.5;
64 m_diffuseColor.Z() = 0.5;
65 m_specularColor.X() = 0.5;
66 m_specularColor.Y() = 0.5;
67 m_specularColor.Z() = 0.5;
69 m_emissiveColor.X() = 0.0;
70 m_emissiveColor.Y() = 0.0;
71 m_emissiveColor.Z() = 0.0;
72 m_shininess = 0.4;
73 m_transparency = 0.0;
74 }
75};
76#endif // VHACD_DEBUG_MESH
77
79class Mesh
80{
81public:
82 void AddPoint(const Vec3<double>& pt) { m_points.PushBack(pt); };
83 void SetPoint(size_t index, const Vec3<double>& pt) { m_points[index] = pt; };
84 const Vec3<double>& GetPoint(size_t index) const { return m_points[index]; };
85 Vec3<double>& GetPoint(size_t index) { return m_points[index]; }
86 size_t GetNPoints() const { return m_points.Size(); }
87 double* GetPoints() { return (double*)m_points.Data(); } // ugly
88 const double* GetPoints() const { return (double*)m_points.Data(); } // ugly
89 const Vec3<double>* GetPointsBuffer() const { return m_points.Data(); } //
90 Vec3<double>* GetPointsBuffer() { return m_points.Data(); } //
91 void AddTriangle(const Vec3<int32_t>& tri) { m_triangles.PushBack(tri); };
92 void SetTriangle(size_t index, const Vec3<int32_t>& tri) { m_triangles[index] = tri; }
93 const Vec3<int32_t>& GetTriangle(size_t index) const { return m_triangles[index]; }
94 Vec3<int32_t>& GetTriangle(size_t index) { return m_triangles[index]; }
95 size_t GetNTriangles() const { return m_triangles.Size(); }
96 int32_t* GetTriangles() { return (int32_t*)m_triangles.Data(); } // ugly
97 const int32_t* GetTriangles() const { return (int32_t*)m_triangles.Data(); } // ugly
98 const Vec3<int32_t>* GetTrianglesBuffer() const { return m_triangles.Data(); }
100 const Vec3<double>& GetCenter() const { return m_center; }
101 const Vec3<double>& GetMinBB() const { return m_minBB; }
102 const Vec3<double>& GetMaxBB() const { return m_maxBB; }
103 void ClearPoints() { m_points.Clear(); }
104 void ClearTriangles() { m_triangles.Clear(); }
105 void Clear()
106 {
107 ClearPoints();
109 }
110 void ResizePoints(size_t nPts) { m_points.Resize(nPts); }
111 void ResizeTriangles(size_t nTri) { m_triangles.Resize(nTri); }
112 void CopyPoints(SArray<Vec3<double> >& points) const { points = m_points; }
113 double GetDiagBB() const { return m_diag; }
114 double ComputeVolume() const;
115 void ComputeConvexHull(const double* const pts, const size_t nPts);
116 void Clip(const Plane& plane, SArray<Vec3<double> >& positivePart, SArray<Vec3<double> >& negativePart) const;
117 bool IsInside(const Vec3<double>& pt) const;
118 double ComputeDiagBB();
120
121#ifdef VHACD_DEBUG_MESH
122 bool LoadOFF(const std::string& fileName, bool invert);
123 bool SaveVRML2(const std::string& fileName) const;
124 bool SaveVRML2(std::ofstream& fout, const Material& material) const;
125 bool SaveOFF(const std::string& fileName) const;
126#endif // VHACD_DEBUG_MESH
127
129 Mesh();
131 ~Mesh(void);
132
133private:
139 double m_diag;
140};
141} // namespace VHACD
142} // namespace tesseract_collision
Triangular mesh data structure.
Definition: vhacdMesh.h:80
const Vec3< double > & GetCenter() const
Definition: vhacdMesh.h:100
Vec3< double > & ComputeCenter(void)
Definition: vhacdMesh.cpp:50
void ClearTriangles()
Definition: vhacdMesh.h:104
const Vec3< int32_t > & GetTriangle(size_t index) const
Definition: vhacdMesh.h:93
double ComputeVolume() const
Definition: vhacdMesh.cpp:98
bool SaveVRML2(std::ofstream &fout, const Material &material) const
bool IsInside(const Vec3< double > &pt) const
Definition: vhacdMesh.cpp:183
int32_t * GetTriangles()
Definition: vhacdMesh.h:96
const Vec3< double > & GetMaxBB() const
Definition: vhacdMesh.h:102
Vec3< double > m_center
Definition: vhacdMesh.h:138
double m_diag
Definition: vhacdMesh.h:139
Vec3< double > m_maxBB
Definition: vhacdMesh.h:137
void AddPoint(const Vec3< double > &pt)
Definition: vhacdMesh.h:82
size_t GetNPoints() const
Definition: vhacdMesh.h:86
double * GetPoints()
Definition: vhacdMesh.h:87
void Clip(const Plane &plane, SArray< Vec3< double > > &positivePart, SArray< Vec3< double > > &negativePart) const
Definition: vhacdMesh.cpp:156
bool SaveOFF(const std::string &fileName) const
void AddTriangle(const Vec3< int32_t > &tri)
Definition: vhacdMesh.h:91
Vec3< int32_t > * GetTrianglesBuffer()
Definition: vhacdMesh.h:99
void Clear()
Definition: vhacdMesh.h:105
void ResizePoints(size_t nPts)
Definition: vhacdMesh.h:110
void ComputeConvexHull(const double *const pts, const size_t nPts)
Definition: vhacdMesh.cpp:127
Mesh()
Constructor.
Definition: vhacdMesh.cpp:48
const Vec3< double > & GetPoint(size_t index) const
Definition: vhacdMesh.h:84
void SetTriangle(size_t index, const Vec3< int32_t > &tri)
Definition: vhacdMesh.h:92
void ResizeTriangles(size_t nTri)
Definition: vhacdMesh.h:111
void ClearPoints()
Definition: vhacdMesh.h:103
Vec3< double > & GetPoint(size_t index)
Definition: vhacdMesh.h:85
void SetPoint(size_t index, const Vec3< double > &pt)
Definition: vhacdMesh.h:83
const int32_t * GetTriangles() const
Definition: vhacdMesh.h:97
SArray< Vec3< int32_t > > m_triangles
Definition: vhacdMesh.h:135
const Vec3< double > * GetPointsBuffer() const
Definition: vhacdMesh.h:89
Vec3< int32_t > & GetTriangle(size_t index)
Definition: vhacdMesh.h:94
const double * GetPoints() const
Definition: vhacdMesh.h:88
Vec3< double > m_minBB
Definition: vhacdMesh.h:136
void CopyPoints(SArray< Vec3< double > > &points) const
Definition: vhacdMesh.h:112
bool SaveVRML2(const std::string &fileName) const
const Vec3< double > & GetMinBB() const
Definition: vhacdMesh.h:101
const Vec3< int32_t > * GetTrianglesBuffer() const
Definition: vhacdMesh.h:98
SArray< Vec3< double > > m_points
Definition: vhacdMesh.h:134
double GetDiagBB() const
Definition: vhacdMesh.h:113
~Mesh(void)
Destructor.
Definition: vhacdMesh.cpp:49
Vec3< double > * GetPointsBuffer()
Definition: vhacdMesh.h:90
bool LoadOFF(const std::string &fileName, bool invert)
size_t GetNTriangles() const
Definition: vhacdMesh.h:95
double ComputeDiagBB()
Definition: vhacdMesh.cpp:207
SArray.
Definition: vhacdSArray.h:42
Vector dim 3.
Definition: vhacdVector.h:37
T & Y()
Definition: vhacdVector.inl:18
T & X()
Definition: vhacdVector.inl:13
T & Z()
Definition: vhacdVector.inl:23
AXIS
Definition: vhacdMesh.h:37
@ AXIS_Z
Definition: vhacdMesh.h:40
@ AXIS_Y
Definition: vhacdMesh.h:39
@ AXIS_X
Definition: vhacdMesh.h:38
Definition: bullet_cast_bvh_manager.h:49
Definition: vhacdMesh.h:53
double m_transparency
Definition: vhacdMesh.h:59
Vec3< double > m_emissiveColor
Definition: vhacdMesh.h:57
double m_ambientIntensity
Definition: vhacdMesh.h:55
Material(void)
Definition: vhacdMesh.h:60
Vec3< double > m_specularColor
Definition: vhacdMesh.h:56
double m_shininess
Definition: vhacdMesh.h:58
Vec3< double > m_diffuseColor
Definition: vhacdMesh.h:54
Definition: vhacdMesh.h:43
double m_d
Definition: vhacdMesh.h:47
short m_index
Definition: vhacdMesh.h:49
double m_c
Definition: vhacdMesh.h:46
double m_b
Definition: vhacdMesh.h:45
double m_a
Definition: vhacdMesh.h:44
AXIS m_axis
Definition: vhacdMesh.h:48
auto plane
Definition: tesseract_geometry_unit.cpp:22