ScummVM API documentation
dgConvexHull4d.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_4D__
23 #define __DG_CONVEXHULL_4D__
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 dgAABBPointTree4d;
35 
36 class dgHullVector: public dgBigVector {
37 public:
38  void operator = (const dgBigVector &a) {
39  m_x = a.m_x;
40  m_y = a.m_y;
41  m_z = a.m_z;
42  m_w = a.m_w;
43  m_index = 0;
44  m_mark = 0;
45  }
46 
47  dgInt32 m_index;
48  dgInt32 m_mark;
49 };
50 
51 
53 public:
55  public:
56  dgInt32 m_index[3];
57  dgInt32 m_otherVertex;
59  };
60 
61 
63  public:
64  dgTetrahedrumPlane(const dgBigVector &p0, const dgBigVector &p1, const dgBigVector &p2, const dgBigVector &p3);
65  dgFloat64 Evalue(const dgBigVector &point) const;
66  dgFloat64 m_dist;
67  };
68 
70  dgTetrahedrumPlane GetPlaneEquation(const dgHullVector *const points) const;
71  dgFloat64 Evalue(const dgHullVector *const pointArray, const dgBigVector &point) const;
72 
73  dgBigVector CircumSphereCenter(const dgHullVector *const pointArray) const;
74 
75  dgInt32 GetMark() const {
76  return m_mark;
77  }
78  void SetMark(dgInt32 mark) {
79  m_mark = mark;
80  }
81 
82  dgTetrahedrumFace m_faces[4];
83 #ifdef _DEBUG
84  dgInt32 m_debugID;
85 #endif
86 
87 private:
88  void Init(const dgHullVector *const points, dgInt32 v0, dgInt32 v1, dgInt32 v2, dgInt32 v3);
89 
90  dgInt32 m_mark;
91  friend class dgConvexHull4d;
92  friend class dgDelaunayTetrahedralization;
93 };
94 
95 
96 class dgConvexHull4d: public dgList<dgConvexHull4dTetraherum> {
97 public:
98  dgConvexHull4d(dgMemoryAllocator *const allocator, const dgBigVector *const vertexCloud, dgInt32 count, dgFloat32 distTol);
99  virtual ~dgConvexHull4d();
100 
101  dgInt32 GetVertexCount() const;
102  dgInt32 GetVertexIndex(dgInt32 i) const;
103  const dgBigVector &GetVertex(dgInt32 i) const;
104 
105  const dgHullVector *GetHullVertexArray() const;
106 
107  dgInt32 IncMark();
108 
109 protected:
110  dgConvexHull4d(dgMemoryAllocator *const allocator);
111 
112  void BuildHull(dgMemoryAllocator *const allocator, const dgBigVector *const vertexCloud, dgInt32 count, dgFloat64 distTol);
113 
114  virtual dgInt32 AddVertex(const dgBigVector &vertex);
115  virtual dgInt32 InitVertexArray(dgHullVector *const points, const dgBigVector *const vertexCloud, dgInt32 count, void *memoryPool, dgInt32 maxMemSize);
116  virtual dgListNode *AddFace(dgInt32 i0, dgInt32 i1, dgInt32 i2, dgInt32 i3);
117  virtual void DeleteFace(dgListNode *const node) ;
118 
119  dgListNode *FindFacingNode(const dgBigVector &vertex);
120 
121  dgInt32 BuildNormalList(dgBigVector *const normalArray) const;
122  void InsertNewVertex(dgInt32 vertexIndex, dgListNode *const frontFace, dgList<dgListNode *> &deletedFaces, dgList<dgListNode *> &newFaces);
123  dgInt32 SupportVertex(dgAABBPointTree4d **const tree, const dgHullVector *const points, const dgBigVector &dir) const;
124  void TessellateTriangle(dgInt32 level, const dgVector &p0, const dgVector &p1, const dgVector &p2, dgInt32 &count, dgBigVector *const ouput, dgInt32 &start) const;
125 
126  void CalculateConvexHull(dgAABBPointTree4d *vertexTree, dgHullVector *const points, dgInt32 count, dgFloat64 distTol);
127  void LinkSibling(dgListNode *node0, dgListNode *node1) const;
128  bool Sanity() const;
129  static dgInt32 ConvexCompareVertex(const dgHullVector *const A, const dgHullVector *const B, void *const context);
130 
131  dgAABBPointTree4d *BuildTree(dgAABBPointTree4d *const parent, dgHullVector *const points, dgInt32 count, dgInt32 baseIndex, dgInt8 **const memoryPool, dgInt32 &maxMemSize) const;
132 
133  dgInt32 m_mark;
134  dgInt32 m_count;
135  dgFloat64 m_diag;
136  dgArray<dgHullVector> m_points;
137 };
138 
139 
140 inline dgInt32 dgConvexHull4d::IncMark() {
141  m_mark ++;
142  return m_mark;
143 }
144 
145 inline dgInt32 dgConvexHull4d::GetVertexCount() const {
146  return m_count;
147 }
148 
149 inline dgInt32 dgConvexHull4d::GetVertexIndex(dgInt32 index) const {
150  NEWTON_ASSERT(index >= 0);
151  NEWTON_ASSERT(index < m_count);
152  return m_points[index].m_index;
153 }
154 
155 
156 inline const dgBigVector &dgConvexHull4d::GetVertex(dgInt32 index) const {
157  NEWTON_ASSERT(index >= 0);
158  NEWTON_ASSERT(index < m_count);
159 // return dgVector (dgFloat32 (m_points[index].m_x), dgFloat32 (m_points[index].m_y), dgFloat32 (m_points[index].m_z), dgFloat32 (m_points[index].m_w));
160  return m_points[index];
161 }
162 
163 inline const dgHullVector *dgConvexHull4d::GetHullVertexArray() const {
164  return &m_points[0];
165 }
166 
167 #endif
Definition: dgConvexHull4d.h:62
Definition: dgVector.h:86
Definition: dgConvexHull4d.h:52
Definition: dgList.h:33
Definition: dgConvexHull4d.h:96
Definition: dgDelaunayTetrahedralization.h:28
Definition: dgMemory.h:80
Definition: dgConvexHull4d.h:36
Definition: dgConvexHull4d.h:54
Definition: dgVector.h:104