2014-05-07 15:54:08 +00:00
|
|
|
#ifndef CD_HULL_H
|
|
|
|
|
|
|
|
#define CD_HULL_H
|
|
|
|
|
|
|
|
/*----------------------------------------------------------------------
|
|
|
|
Copyright (c) 2004 Open Dynamics Framework Group
|
|
|
|
www.physicstools.org
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without modification, are permitted provided
|
|
|
|
that the following conditions are met:
|
|
|
|
|
|
|
|
Redistributions of source code must retain the above copyright notice, this list of conditions
|
|
|
|
and the following disclaimer.
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
Neither the name of the Open Dynamics Framework Group nor the names of its contributors may
|
|
|
|
be used to endorse or promote products derived from this software without specific prior written permission.
|
|
|
|
|
|
|
|
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 INTEL 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.
|
|
|
|
-----------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
namespace ConvexDecomposition
|
|
|
|
{
|
|
|
|
class HullResult
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
HullResult(void)
|
|
|
|
{
|
|
|
|
mPolygons = true;
|
|
|
|
mNumOutputVertices = 0;
|
|
|
|
mOutputVertices = 0;
|
|
|
|
mNumFaces = 0;
|
|
|
|
mNumIndices = 0;
|
|
|
|
mIndices = 0;
|
|
|
|
}
|
2018-09-23 21:17:31 +00:00
|
|
|
bool mPolygons; // true if indices represents polygons, false indices are triangles
|
|
|
|
unsigned int mNumOutputVertices; // number of vertices in the output hull
|
|
|
|
float *mOutputVertices; // array of vertices, 3 floats each x,y,z
|
|
|
|
unsigned int mNumFaces; // the number of faces produced
|
|
|
|
unsigned int mNumIndices; // the total number of indices
|
|
|
|
unsigned int *mIndices; // pointer to indices.
|
|
|
|
|
|
|
|
// If triangles, then indices are array indexes into the vertex list.
|
|
|
|
// If polygons, indices are in the form (number of points in face) (p1, p2, p3, ..) etc..
|
2014-05-07 15:54:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum HullFlag
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
QF_TRIANGLES = (1 << 0), // report results as triangles, not polygons.
|
|
|
|
QF_REVERSE_ORDER = (1 << 1), // reverse order of the triangle indices.
|
|
|
|
QF_SKIN_WIDTH = (1 << 2), // extrude hull based on this skin width
|
|
|
|
QF_DEFAULT = 0
|
2014-05-07 15:54:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class HullDesc
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
HullDesc(void)
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
mFlags = QF_DEFAULT;
|
|
|
|
mVcount = 0;
|
|
|
|
mVertices = 0;
|
|
|
|
mVertexStride = sizeof(float) * 3;
|
|
|
|
mNormalEpsilon = 0.001f;
|
|
|
|
mMaxVertices = 4096; // maximum number of points to be considered for a convex hull.
|
|
|
|
mMaxFaces = 4096;
|
|
|
|
mSkinWidth = 0.01f; // default is one centimeter
|
2014-05-07 15:54:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
HullDesc(HullFlag flag,
|
2018-09-23 21:17:31 +00:00
|
|
|
unsigned int vcount,
|
|
|
|
const float *vertices,
|
|
|
|
unsigned int stride)
|
2014-05-07 15:54:08 +00:00
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
mFlags = flag;
|
|
|
|
mVcount = vcount;
|
|
|
|
mVertices = vertices;
|
|
|
|
mVertexStride = stride;
|
|
|
|
mNormalEpsilon = 0.001f;
|
|
|
|
mMaxVertices = 4096;
|
|
|
|
mSkinWidth = 0.01f; // default is one centimeter
|
2014-05-07 15:54:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool HasHullFlag(HullFlag flag) const
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
if (mFlags & flag) return true;
|
2014-05-07 15:54:08 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SetHullFlag(HullFlag flag)
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
mFlags |= flag;
|
2014-05-07 15:54:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ClearHullFlag(HullFlag flag)
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
mFlags &= ~flag;
|
2014-05-07 15:54:08 +00:00
|
|
|
}
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
unsigned int mFlags; // flags to use when generating the convex hull.
|
|
|
|
unsigned int mVcount; // number of vertices in the input point cloud
|
|
|
|
const float *mVertices; // the array of vertices.
|
|
|
|
unsigned int mVertexStride; // the stride of each vertex, in bytes.
|
|
|
|
float mNormalEpsilon; // the epsilon for removing duplicates. This is a normalized value, if normalized bit is on.
|
|
|
|
float mSkinWidth;
|
|
|
|
unsigned int mMaxVertices; // maximum number of vertices to be considered for the hull!
|
|
|
|
unsigned int mMaxFaces;
|
2014-05-07 15:54:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
enum HullError
|
|
|
|
{
|
2018-09-23 21:17:31 +00:00
|
|
|
QE_OK, // success!
|
|
|
|
QE_FAIL // failed.
|
2014-05-07 15:54:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class HullLibrary
|
|
|
|
{
|
|
|
|
public:
|
2018-09-23 21:17:31 +00:00
|
|
|
HullError CreateConvexHull(const HullDesc &desc, // describes the input request
|
|
|
|
HullResult &result); // contains the resulst
|
2014-05-07 15:54:08 +00:00
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
HullError ReleaseResult(HullResult &result); // release memory allocated for this result, we are done with it.
|
2014-05-07 15:54:08 +00:00
|
|
|
|
|
|
|
private:
|
2018-09-23 21:17:31 +00:00
|
|
|
void BringOutYourDead(const float *verts, unsigned int vcount, float *overts, unsigned int &ocount, unsigned int *indices, unsigned indexcount);
|
|
|
|
|
|
|
|
bool CleanupVertices(unsigned int svcount,
|
|
|
|
const float *svertices,
|
|
|
|
unsigned int stride,
|
|
|
|
unsigned int &vcount, // output number of vertices
|
|
|
|
float *vertices, // location to store the results.
|
|
|
|
float normalepsilon,
|
|
|
|
float *scale);
|
2014-05-07 15:54:08 +00:00
|
|
|
};
|
|
|
|
|
2018-09-23 21:17:31 +00:00
|
|
|
} // namespace ConvexDecomposition
|
2014-05-07 15:54:08 +00:00
|
|
|
|
|
|
|
#endif
|