1 /* Copyright (c) 2011 Khaled Mamou (kmamou at gmail dot com)
\r
5 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
\r
7 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
\r
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.
\r
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.
\r
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.
\r
16 /* Copyright (c) 2011 Khaled Mamou (kmamou at gmail dot com)
\r
17 All rights reserved.
\r
20 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
\r
22 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
\r
24 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.
\r
26 3. The names of the contributors may not be used to endorse or promote products derived from this software without specific prior written permission.
\r
28 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.
\r
31 #ifndef HACD_MANIFOLD_MESH_H
\r
32 #define HACD_MANIFOLD_MESH_H
\r
35 #include "hacdVersion.h"
\r
36 #include "hacdCircularList.h"
\r
37 #include "hacdVector.h"
\r
50 DPoint(Real dist=0, bool computed=false, bool distOnly=false)
\r
52 m_computed(computed),
\r
53 m_distOnly(distOnly){};
\r
59 friend class TMMTriangle;
\r
60 friend class TMMesh;
\r
61 friend class GraphVertex;
\r
62 friend class GraphEdge;
\r
64 friend class ICHull;
\r
68 //! Vertex data structure used in a triangular manifold mesh (TMM).
\r
79 CircularListElement<TMMEdge> * m_duplicate; // pointer to incident cone edge (or NULL)
\r
82 TMMVertex(const TMMVertex & rhs);
\r
85 friend class ICHull;
\r
86 friend class TMMesh;
\r
87 friend class TMMTriangle;
\r
88 friend class TMMEdge;
\r
91 //! Edge data structure used in a triangular manifold mesh (TMM).
\r
99 CircularListElement<TMMTriangle> * m_triangles[2];
\r
100 CircularListElement<TMMVertex> * m_vertices[2];
\r
101 CircularListElement<TMMTriangle> * m_newFace;
\r
104 TMMEdge(const TMMEdge & rhs);
\r
107 friend class ICHull;
\r
108 friend class TMMTriangle;
\r
109 friend class TMMVertex;
\r
110 friend class TMMesh;
\r
113 //! Triangle data structure used in a triangular manifold mesh (TMM).
\r
118 ~TMMTriangle(void);
\r
121 CircularListElement<TMMEdge> * m_edges[3];
\r
122 CircularListElement<TMMVertex> * m_vertices[3];
\r
123 std::set<long> m_incidentPoints;
\r
126 TMMTriangle(const TMMTriangle & rhs);
\r
129 friend class ICHull;
\r
130 friend class TMMesh;
\r
131 friend class TMMVertex;
\r
132 friend class TMMEdge;
\r
141 Vec3<double> m_diffuseColor;
\r
142 double m_ambientIntensity;
\r
143 Vec3<double> m_specularColor;
\r
144 Vec3<double> m_emissiveColor;
\r
145 double m_shininess;
\r
146 double m_transparency;
\r
148 friend class TMMesh;
\r
152 //! triangular manifold mesh data structure.
\r
157 //! Returns the number of vertices>
\r
158 inline size_t GetNVertices() const { return m_vertices.GetSize();}
\r
159 //! Returns the number of edges
\r
160 inline size_t GetNEdges() const { return m_edges.GetSize();}
\r
161 //! Returns the number of triangles
\r
162 inline size_t GetNTriangles() const { return m_triangles.GetSize();}
\r
163 //! Returns the vertices circular list
\r
164 inline const CircularList<TMMVertex> & GetVertices() const { return m_vertices;}
\r
165 //! Returns the edges circular list
\r
166 inline const CircularList<TMMEdge> & GetEdges() const { return m_edges;}
\r
167 //! Returns the triangles circular list
\r
168 inline const CircularList<TMMTriangle> & GetTriangles() const { return m_triangles;}
\r
169 //! Returns the vertices circular list
\r
170 inline CircularList<TMMVertex> & GetVertices() { return m_vertices;}
\r
171 //! Returns the edges circular list
\r
172 inline CircularList<TMMEdge> & GetEdges() { return m_edges;}
\r
173 //! Returns the triangles circular list
\r
174 inline CircularList<TMMTriangle> & GetTriangles() { return m_triangles;}
\r
175 //! Add vertex to the mesh
\r
176 CircularListElement<TMMVertex> * AddVertex() {return m_vertices.Add();}
\r
177 //! Add vertex to the mesh
\r
178 CircularListElement<TMMEdge> * AddEdge() {return m_edges.Add();}
\r
179 //! Add vertex to the mesh
\r
180 CircularListElement<TMMTriangle> * AddTriangle() {return m_triangles.Add();}
\r
181 //! Print mesh information
\r
184 void GetIFS(Vec3<Real> * const points, Vec3<long> * const triangles);
\r
186 bool Save(const char *fileName);
\r
187 //! Save mesh to VRML 2.0 format
\r
188 bool SaveVRML2(std::ofstream &fout);
\r
189 //! Save mesh to VRML 2.0 format
\r
190 bool SaveVRML2(std::ofstream &fout, const Material & material);
\r
194 void Copy(TMMesh & mesh);
\r
196 bool CheckConsistancy();
\r
200 bool Denormalize();
\r
204 virtual ~TMMesh(void);
\r
207 CircularList<TMMVertex> m_vertices;
\r
208 CircularList<TMMEdge> m_edges;
\r
209 CircularList<TMMTriangle> m_triangles;
\r
210 Real m_diag; //>! length of the BB diagonal
\r
211 Vec3<Real> m_barycenter; //>! barycenter of the mesh
\r
214 TMMesh(const TMMesh & rhs);
\r
215 friend class ICHull;
\r
218 //! IntersectRayTriangle(): intersect a ray with a 3D triangle
\r
219 //! Input: a ray R, and a triangle T
\r
220 //! Output: *I = intersection point (when it exists)
\r
221 //! 0 = disjoint (no intersect)
\r
222 //! 1 = intersect in unique point I1
\r
223 long IntersectRayTriangle( const Vec3<double> & P0, const Vec3<double> & dir,
\r
224 const Vec3<double> & V0, const Vec3<double> & V1,
\r
225 const Vec3<double> & V2, double &t);
\r
227 // intersect_RayTriangle(): intersect a ray with a 3D triangle
\r
228 // Input: a ray R, and a triangle T
\r
229 // Output: *I = intersection point (when it exists)
\r
230 // Return: -1 = triangle is degenerate (a segment or point)
\r
231 // 0 = disjoint (no intersect)
\r
232 // 1 = intersect in unique point I1
\r
233 // 2 = are in the same plane
\r
234 long IntersectRayTriangle2(const Vec3<double> & P0, const Vec3<double> & dir,
\r
235 const Vec3<double> & V0, const Vec3<double> & V1,
\r
236 const Vec3<double> & V2, double &r);
\r
239 Calculate the line segment PaPb that is the shortest route between
\r
240 two lines P1P2 and P3P4. Calculate also the values of mua and mub where
\r
241 Pa = P1 + mua (P2 - P1)
\r
242 Pb = P3 + mub (P4 - P3)
\r
243 Return FALSE if no solution exists.
\r
245 bool IntersectLineLine(const Vec3<double> & p1, const Vec3<double> & p2,
\r
246 const Vec3<double> & p3, const Vec3<double> & p4,
\r
247 Vec3<double> & pa, Vec3<double> & pb,
\r
248 double & mua, double &mub);
\r