ScummVM API documentation
dgConvexHull3d.h
1 /* Copyright (c) <2003-2011> <Julio Jerez, Newton Game Dynamics>
2 *
3 * This software is provided 'as-is', without any express or implied
4 * warranty. In no event will the authors be held liable for any damages
5 * arising from the use of this software.
6 *
7 * Permission is granted to anyone to use this software for any purpose,
8 * including commercial applications, and to alter it and redistribute it
9 * freely, subject to the following restrictions:
10 *
11 * 1. The origin of this software must not be misrepresented; you must not
12 * claim that you wrote the original software. If you use this software
13 * in a product, an acknowledgment in the product documentation would be
14 * appreciated but is not required.
15 *
16 * 2. Altered source versions must be plainly marked as such, and must not be
17 * misrepresented as being the original software.
18 *
19 * 3. This notice may not be removed or altered from any source distribution.
20 */
21 
22 #ifndef __DG_CONVEXHULL_3D__
23 #define __DG_CONVEXHULL_3D__
24 
25 #include "dgStdafx.h"
26 #include "dgList.h"
27 #include "dgArray.h"
28 #include "dgPlane.h"
29 #include "dgVector.h"
30 #include "dgMatrix.h"
31 #include "dgQuaternion.h"
32 
33 class dgMemoryAllocator;
34 class dgAABBPointTree3d;
35 
37 public:
39  dgInt32 m_index[3];
40 
41 private:
42  dgFloat64 Evalue(const dgBigVector *const pointArray, const dgBigVector &point) const;
43  dgBigPlane GetPlaneEquation(const dgBigVector *const pointArray) const;
44 
45  mutable dgInt32 m_mark;
47  friend class dgConvexHull3d;
48 };
49 
50 class dgHullVertex;
51 
52 class dgConvexHull3d: public dgList<dgConvexHull3DFace> {
53 public:
54  dgConvexHull3d(dgMemoryAllocator *const allocator, const dgFloat64 *const vertexCloud, dgInt32 strideInBytes, dgInt32 count, dgFloat64 distTol, dgInt32 maxVertexCount = 0x7fffffff);
55  virtual ~dgConvexHull3d();
56 
57  dgInt32 GetVertexCount() const;
58  const dgBigVector *GetVertexPool() const;
59  const dgBigVector &GetVertex(dgInt32 i) const;
60 
61  dgFloat64 GetDiagonal() const;
62  dgFloat64 RayCastBruteForce(const dgBigVector &localP0, const dgBigVector &localP1) const;
63  dgFloat64 RayCast(const dgBigVector &localP0, const dgBigVector &localP1, const dgConvexHull3DFace **firstFaceGuess = NULL) const;
64 
65  void CalculateVolumeAndSurfaceArea(dgFloat64 &volume, dgFloat64 &surcafeArea) const;
66 
67 protected:
68 
69  dgConvexHull3d(dgMemoryAllocator *const allocator);
70  void BuildHull(const dgFloat64 *const vertexCloud, dgInt32 strideInBytes, dgInt32 count, dgFloat64 distTol, dgInt32 maxVertexCount);
71 
72  dgFloat64 FaceRayCast(const dgConvexHull3DFace *const face, const dgBigVector &origin, const dgBigVector &dist, dgFloat64 &normalProjection) const;
73 
74 
75  virtual dgListNode *AddFace(dgInt32 i0, dgInt32 i1, dgInt32 i2);
76  virtual void DeleteFace(dgListNode *const node) ;
77  virtual dgInt32 InitVertexArray(dgHullVertex *const points, const dgFloat64 *const vertexCloud, dgInt32 strideInBytes, dgInt32 count, void *memoryPool, dgInt32 maxMemSize);
78 
79  void CalculateConvexHull(dgAABBPointTree3d *vertexTree, dgHullVertex *const points, dgInt32 count, dgFloat64 distTol, dgInt32 maxVertexCount);
80  dgInt32 BuildNormalList(dgBigVector *const normalArray) const;
81  dgInt32 SupportVertex(dgAABBPointTree3d **const tree, const dgHullVertex *const points, const dgBigVector &dir) const;
82  dgFloat64 TetrahedrumVolume(const dgBigVector &p0, const dgBigVector &p1, const dgBigVector &p2, const dgBigVector &p3) const;
83  void TessellateTriangle(dgInt32 level, const dgVector &p0, const dgVector &p1, const dgVector &p2, dgInt32 &count, dgBigVector *const ouput, dgInt32 &start) const;
84 
85  dgAABBPointTree3d *BuildTree(dgAABBPointTree3d *const parent, dgHullVertex *const points, dgInt32 count, dgInt32 baseIndex, dgInt8 **const memoryPool, dgInt32 &maxMemSize) const;
86  static dgInt32 ConvexCompareVertex(const dgHullVertex *const A, const dgHullVertex *const B, void *const context);
87  bool Sanity() const;
88 
89  mutable dgInt32 m_mark;
90  dgInt32 m_count;
91  dgFloat64 m_diag;
92  dgArray<dgBigVector> m_points;
93 };
94 
95 
96 inline dgInt32 dgConvexHull3d::GetVertexCount() const {
97  return m_count;
98 }
99 
100 inline const dgBigVector *dgConvexHull3d::GetVertexPool() const {
101  return &m_points[0];
102 }
103 
104 inline const dgBigVector &dgConvexHull3d::GetVertex(dgInt32 index) const {
105  return m_points[index];
106 }
107 
108 inline dgFloat64 dgConvexHull3d::GetDiagonal() const {
109  return m_diag;
110 }
111 
112 #endif
Definition: dgConvexHull3d.h:36
Definition: dgVector.h:86
Definition: dgConvexHull3d.h:52
Definition: dgList.h:33
Definition: dgPlane.h:41
Definition: dgMemory.h:80
Definition: dgVector.h:104