cleanup hull validation
This commit is contained in:
parent
0e0438e0a9
commit
ffed35d10a
@ -120,9 +120,11 @@ public:
|
|||||||
return m_iteration;
|
return m_iteration;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return if this hull is valid.
|
// Validate this hull.
|
||||||
bool IsConsistent() const;
|
void Validate() const;
|
||||||
|
void Validate(const qhFace* face) const;
|
||||||
|
void Validate(const qhHalfEdge* edge) const;
|
||||||
|
|
||||||
// Draw this hull.
|
// Draw this hull.
|
||||||
void Draw() const;
|
void Draw() const;
|
||||||
private:
|
private:
|
||||||
|
@ -40,21 +40,14 @@ void b3Hull::Validate() const
|
|||||||
|
|
||||||
void b3Hull::Validate(const b3Face* face) const
|
void b3Hull::Validate(const b3Face* face) const
|
||||||
{
|
{
|
||||||
bool ok = false;
|
|
||||||
const b3HalfEdge* begin = GetEdge(face->edge);
|
const b3HalfEdge* begin = GetEdge(face->edge);
|
||||||
const b3HalfEdge* edge = begin;
|
const b3HalfEdge* edge = begin;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if (GetFace(edge->face) == face)
|
B3_ASSERT(GetFace(edge->face) == face);
|
||||||
{
|
|
||||||
ok = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
edge = edges + edge->next;
|
edge = edges + edge->next;
|
||||||
} while (edge != begin);
|
} while (edge != begin);
|
||||||
|
|
||||||
B3_ASSERT(ok);
|
|
||||||
|
|
||||||
Validate(edges + face->edge);
|
Validate(edges + face->edge);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,12 +62,14 @@ void b3Hull::Validate(const b3HalfEdge* e) const
|
|||||||
B3_ASSERT(twin->twin == edgeIndex);
|
B3_ASSERT(twin->twin == edgeIndex);
|
||||||
|
|
||||||
u32 count = 0;
|
u32 count = 0;
|
||||||
|
|
||||||
const b3HalfEdge* begin = e;
|
const b3HalfEdge* begin = e;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
const b3HalfEdge* next = edges + e->next;
|
|
||||||
e = edges + next->twin;
|
|
||||||
B3_ASSERT(count < edgeCount);
|
B3_ASSERT(count < edgeCount);
|
||||||
++count;
|
++count;
|
||||||
|
|
||||||
|
const b3HalfEdge* next = edges + e->next;
|
||||||
|
e = edges + next->twin;
|
||||||
} while (e != begin);
|
} while (e != begin);
|
||||||
}
|
}
|
@ -108,6 +108,8 @@ void qhHull::Construct(void* memory, const b3Array<b3Vec3>& vs)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Validate();
|
||||||
|
|
||||||
qhVertex* eye = NextVertex();
|
qhVertex* eye = NextVertex();
|
||||||
while (eye)
|
while (eye)
|
||||||
{
|
{
|
||||||
@ -274,12 +276,7 @@ bool qhHull::BuildInitialHull(const b3Array<b3Vec3>& vertices)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Connectivity check.
|
// Connectivity check.
|
||||||
bool ok = IsConsistent();
|
Validate();
|
||||||
B3_ASSERT(ok);
|
|
||||||
if (!ok)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add remaining points to the hull.
|
// Add remaining points to the hull.
|
||||||
// Assign closest face plane to each of them.
|
// Assign closest face plane to each of them.
|
||||||
@ -714,28 +711,45 @@ void qhHull::MergeFaces(b3Array<qhFace*>& newFaces)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool qhHull::IsConsistent() const
|
void qhHull::Validate(const qhHalfEdge* edge) const
|
||||||
{
|
{
|
||||||
|
const qhHalfEdge* twin = edge->twin;
|
||||||
|
B3_ASSERT(twin->twin == edge);
|
||||||
|
|
||||||
|
b3Vec3 A = edge->tail->position;
|
||||||
|
b3Vec3 B = twin->tail->position;
|
||||||
|
B3_ASSERT(b3DistanceSquared(A, B) > B3_EPSILON * B3_EPSILON);
|
||||||
|
|
||||||
u32 count = 0;
|
u32 count = 0;
|
||||||
|
const qhHalfEdge* begin = edge;
|
||||||
qhFace* f = m_faceList.head;
|
do
|
||||||
while (f)
|
|
||||||
{
|
{
|
||||||
B3_ASSERT(f->state != qhFace::e_deleted);
|
++count;
|
||||||
qhHalfEdge* e = f->edge;
|
const qhHalfEdge* next = edge->next;
|
||||||
do
|
edge = next->twin;
|
||||||
{
|
} while (edge != begin);
|
||||||
++count;
|
}
|
||||||
//B3_ASSERT(e->face == f);
|
|
||||||
B3_ASSERT(e->twin->twin == e);
|
|
||||||
B3_ASSERT(count < 10000);
|
|
||||||
e = e->next;
|
|
||||||
} while (e != f->edge);
|
|
||||||
|
|
||||||
f = f->next;
|
void qhHull::Validate(const qhFace* face) const
|
||||||
|
{
|
||||||
|
const qhHalfEdge* begin = face->edge;
|
||||||
|
const qhHalfEdge* edge = begin;
|
||||||
|
do
|
||||||
|
{
|
||||||
|
B3_ASSERT(edge->face == face);
|
||||||
|
edge = edge->next;
|
||||||
|
} while (edge != begin);
|
||||||
|
|
||||||
|
Validate(face->edge);
|
||||||
|
}
|
||||||
|
|
||||||
|
void qhHull::Validate() const
|
||||||
|
{
|
||||||
|
for (qhFace* face = m_faceList.head; face != NULL; face = face->next)
|
||||||
|
{
|
||||||
|
B3_ASSERT(face->state != face->e_deleted);
|
||||||
|
Validate(face);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void qhHull::Draw() const
|
void qhHull::Draw() const
|
||||||
|
Loading…
x
Reference in New Issue
Block a user