cleanup quickhull

This commit is contained in:
Irlan 2018-04-17 01:53:36 -03:00
parent fd04c35886
commit 5e0a010881
2 changed files with 29 additions and 26 deletions

View File

@ -32,7 +32,6 @@ struct qhList
u32 count;
};
// Half-edge data structure definition used by qhHull.
struct qhHalfEdge;
struct qhVertex;
@ -90,16 +89,6 @@ struct qhVertex
qhFace* conflictFace;
};
// todo
// Snapshots of the algorithm for debug drawing.
struct qhDraw
{
//DrawIteration* iter; // current iteration
//b3Array<DrawIteration> iterations;
};
class b3Draw;
// Given a number of points return the required memory size in bytes for constructing the
// convex hull of those points. Use this function before allocating the memory buffer passed
// as argument to Construct.
@ -119,15 +108,23 @@ public:
// Use qhGetMemorySize to see how many free bytes should be available in the buffer.
void Construct(void* memory, const b3Array<b3Vec3>& vertices);
// Output of qhHull.
// todo
// Output a cleaner data structure. Maybe similar to b3Hull but storing larger hulls?
qhList<qhFace> m_faceList; // convex hull
u32 m_iteration; // number of quickhull iterations
// Get the list of faces in this hull.
const qhList<qhFace>& GetFaceList() const
{
return m_faceList;
}
// Get the number of iterations this algorithm ran.
u32 GetIterations() const
{
return m_iteration;
}
// Return if this hull is valid.
bool IsConsistent() const;
void Draw(b3Draw* draw) const;
// Draw this hull.
void Draw() const;
private:
bool BuildInitialHull(const b3Array<b3Vec3>& vertices);
@ -154,6 +151,12 @@ private:
// Coplanarity tolerance
float32 m_tolerance;
// List of faces
qhList<qhFace> m_faceList; // list of faces
// Number of Quickhull iterations
u32 m_iteration;
// Memory
qhVertex* AllocateVertex();
void FreeVertex(qhVertex* p);
@ -167,6 +170,7 @@ private:
qhVertex* m_freeVertices;
qhHalfEdge* m_freeEdges;
qhFace* m_freeFaces;
};
#include <bounce/quickhull/qh_hull.inl>

View File

@ -20,7 +20,7 @@
#include <bounce/common/template/stack.h>
#include <bounce/common/draw.h>
float32 qhFindAABB(u32 iMin[3], u32 iMax[3], const b3Array<b3Vec3>& vertices)
static float32 qhFindAABB(u32 iMin[3], u32 iMax[3], const b3Array<b3Vec3>& vertices)
{
b3Vec3 min(B3_MAX_FLOAT, B3_MAX_FLOAT, B3_MAX_FLOAT);
iMin[0] = 0;
@ -65,6 +65,8 @@ qhHull::~qhHull()
void qhHull::Construct(void* memory, const b3Array<b3Vec3>& vs)
{
// Euler's formula
// V - E + F = 2
u32 V = vs.Count();
u32 E = 3 * V - 6;
u32 HE = 2 * E;
@ -73,9 +75,6 @@ void qhHull::Construct(void* memory, const b3Array<b3Vec3>& vs)
HE *= 2;
F *= 2;
// Euler's formula
// V - E + F = 2
m_freeVertices = NULL;
qhVertex* vertices = (qhVertex*)memory;
for (u32 i = 0; i < V; ++i)
@ -739,7 +738,7 @@ bool qhHull::IsConsistent() const
return true;
}
void qhHull::Draw(b3Draw* draw) const
void qhHull::Draw() const
{
qhFace* face = m_faceList.head;
while (face)
@ -757,17 +756,17 @@ void qhHull::Draw(b3Draw* draw) const
edge = edge->next;
} while (edge != begin);
draw->DrawSolidPolygon(n, vs.Begin(), vs.Count(), b3Color(1.0f, 1.0f, 1.0f, 0.5f));
b3Draw_draw->DrawSolidPolygon(n, vs.Begin(), vs.Count(), b3Color(1.0f, 1.0f, 1.0f, 0.5f));
qhVertex* v = face->conflictList.head;
while (v)
{
draw->DrawPoint(v->position, 4.0f, b3Color(1.0f, 1.0f, 0.0f));
draw->DrawSegment(c, v->position, b3Color(1.0f, 1.0f, 0.0f));
b3Draw_draw->DrawPoint(v->position, 4.0f, b3Color(1.0f, 1.0f, 0.0f));
b3Draw_draw->DrawSegment(c, v->position, b3Color(1.0f, 1.0f, 0.0f));
v = v->next;
}
draw->DrawSegment(c, c + n, b3Color(1.0f, 1.0f, 1.0f));
b3Draw_draw->DrawSegment(c, c + n, b3Color(1.0f, 1.0f, 1.0f));
face = face->next;
}