cd_hull.h
Go to the documentation of this file.
1 #ifndef HULL_LIB_H
2 
3 #define HULL_LIB_H
4 
5 
62 namespace ConvexDecomposition
63 {
64 
66 {
67 public:
68  HullResult(void)
69  {
70  mPolygons = true;
72  mOutputVertices = 0;
73  mNumFaces = 0;
74  mNumIndices = 0;
75  mIndices = 0;
76  }
77  bool mPolygons; // true if indices represents polygons, false indices are triangles
78  unsigned int mNumOutputVertices; // number of vertices in the output hull
79  double *mOutputVertices; // array of vertices, 3 doubles each x,y,z
80  unsigned int mNumFaces; // the number of faces produced
81  unsigned int mNumIndices; // the total number of indices
82  unsigned int *mIndices; // pointer to indices.
83 
84 // If triangles, then indices are array indexes into the vertex list.
85 // If polygons, indices are in the form (number of points in face) (p1, p2, p3, ..) etc..
86 };
87 
89 {
90 public:
92  {
93  mPolygons = r.mPolygons;
95  mNumFaces = r.mNumFaces;
97  mIndices = 0;
98  mOutputVertices = 0;
99  if ( mNumIndices )
100  {
101  mIndices = new unsigned int[mNumIndices];
102  memcpy(mIndices,r.mIndices,sizeof(unsigned int)*mNumIndices);
103  }
104  if ( mNumOutputVertices )
105  {
106  mOutputVertices = new float[mNumOutputVertices*3];
107  const double *src = r.mOutputVertices;
108  float *dst = mOutputVertices;
109  for (unsigned int i=0; i<mNumOutputVertices; i++)
110  {
111  dst[0] = (float) src[0];
112  dst[1] = (float) src[1];
113  dst[2] = (float) src[2];
114  dst+=3;
115  src+=3;
116  }
117  }
118  }
120  {
121  delete mIndices;
122  delete mOutputVertices;
123  }
124  bool mPolygons; // true if indices represents polygons, false indices are triangles
125  unsigned int mNumOutputVertices; // number of vertices in the output hull
126  float *mOutputVertices; // array of vertices, 3 doubles each x,y,z
127  unsigned int mNumFaces; // the number of faces produced
128  unsigned int mNumIndices; // the total number of indices
129  unsigned int *mIndices; // pointer to indices.
130 
131 // If triangles, then indices are array indexes into the vertex list.
132 // If polygons, indices are in the form (number of points in face) (p1, p2, p3, ..) etc..
133 };
134 
136 {
137  QF_TRIANGLES = (1<<0), // report results as triangles, not polygons.
138  QF_REVERSE_ORDER = (1<<1), // reverse order of the triangle indices.
139  QF_SKIN_WIDTH = (1<<2), // extrude hull based on this skin width
141 };
142 
143 
144 class HullDesc
145 {
146 public:
147  HullDesc(void)
148  {
149  mFlags = QF_DEFAULT;
150  mVcount = 0;
151  mVertices = 0;
152  mVertexStride = 0;
153  mNormalEpsilon = 0.001f;
154  mMaxVertices = 4096; // maximum number of points to be considered for a convex hull.
155  mSkinWidth = 0.01f; // default is one centimeter
156  };
157 
159  unsigned int vcount,
160  const double *vertices,
161  unsigned int stride)
162  {
163  mFlags = flag;
164  mVcount = vcount;
165  mVertices = vertices;
166  mVertexStride = stride;
167  mNormalEpsilon = 0.001f;
168  mMaxVertices = 4096;
169  mSkinWidth = 0.01f; // default is one centimeter
170  }
171 
172  bool HasHullFlag(HullFlag flag) const
173  {
174  if ( mFlags & flag ) return true;
175  return false;
176  }
177 
179  {
180  mFlags|=flag;
181  }
182 
184  {
185  mFlags&=~flag;
186  }
187 
188  unsigned int mFlags; // flags to use when generating the convex hull.
189  unsigned int mVcount; // number of vertices in the input point cloud
190  const double *mVertices; // the array of vertices.
191  unsigned int mVertexStride; // the stride of each vertex, in bytes.
192  double mNormalEpsilon; // the epsilon for removing duplicates. This is a normalized value, if normalized bit is on.
193  double mSkinWidth;
194  unsigned int mMaxVertices; // maximum number of vertices to be considered for the hull!
195 };
196 
198 {
199  QE_OK, // success!
200  QE_FAIL // failed.
201 };
202 
203 // This class is used when converting a convex hull into a triangle mesh.
205 {
206 public:
207  double mPos[3];
208  double mNormal[3];
209  double mTexel[2];
210 };
211 
212 // A virtual interface to receive the triangles from the convex hull.
214 {
215 public:
216  virtual void ConvexHullTriangle(const ConvexHullVertex &v1,const ConvexHullVertex &v2,const ConvexHullVertex &v3) = 0;
217 };
218 
219 
220 
222 {
223 public:
224 
225  HullError CreateConvexHull(const HullDesc &desc, // describes the input request
226  HullResult &result); // contains the resulst
227 
228  HullError ReleaseResult(HullResult &result); // release memory allocated for this result, we are done with it.
229 
230  // Utility function to convert the output convex hull as a renderable set of triangles. Unfolds the polygons into
231  // individual triangles, compute the vertex normals, and projects some texture co-ordinates.
233 private:
234  double ComputeNormal(double *n,const double *A,const double *B,const double *C);
235  void AddConvexTriangle(ConvexHullTriangleInterface *callback,const double *p1,const double *p2,const double *p3);
236 
237  void BringOutYourDead(const double *verts,unsigned int vcount, double *overts,unsigned int &ocount,unsigned int *indices,unsigned indexcount);
238 
239  bool CleanupVertices(unsigned int svcount,
240  const double *svertices,
241  unsigned int stride,
242  unsigned int &vcount, // output number of vertices
243  double *vertices, // location to store the results.
244  double normalepsilon,
245  double *scale);
246 };
247 
248 };
249 
250 #endif
ConvexDecomposition::QF_TRIANGLES
@ QF_TRIANGLES
Definition: cd_hull.h:137
ConvexDecomposition::HullResult::mPolygons
bool mPolygons
Definition: cd_hull.h:77
ConvexDecomposition::HullLibrary::AddConvexTriangle
void AddConvexTriangle(ConvexHullTriangleInterface *callback, const double *p1, const double *p2, const double *p3)
Definition: cd_hull.cpp:3528
ConvexDecomposition::HullDesc::mSkinWidth
double mSkinWidth
Definition: cd_hull.h:193
ConvexDecomposition::HullResult::mOutputVertices
double * mOutputVertices
Definition: cd_hull.h:79
ConvexDecomposition::HullDesc::mVcount
unsigned int mVcount
Definition: cd_hull.h:189
ConvexDecomposition::HullResult::HullResult
HullResult(void)
Definition: cd_hull.h:68
ConvexDecomposition::ConvexHullVertex::mPos
double mPos[3]
Definition: cd_hull.h:207
ConvexDecomposition::HullDesc
Definition: cd_hull.h:144
ConvexDecomposition::FHullResult::mIndices
unsigned int * mIndices
Definition: cd_hull.h:129
ConvexDecomposition::ConvexHullTriangleInterface::ConvexHullTriangle
virtual void ConvexHullTriangle(const ConvexHullVertex &v1, const ConvexHullVertex &v2, const ConvexHullVertex &v3)=0
ConvexDecomposition::HullResult::mNumOutputVertices
unsigned int mNumOutputVertices
Definition: cd_hull.h:78
ConvexDecomposition::HullLibrary::CreateConvexHull
HullError CreateConvexHull(const HullDesc &desc, HullResult &result)
Definition: cd_hull.cpp:2948
ConvexDecomposition::ConvexHullVertex::mNormal
double mNormal[3]
Definition: cd_hull.h:208
ConvexDecomposition::HullDesc::mFlags
unsigned int mFlags
Definition: cd_hull.h:188
ConvexDecomposition::HullLibrary::ReleaseResult
HullError ReleaseResult(HullResult &result)
Definition: cd_hull.cpp:3149
ConvexDecomposition::HullLibrary::BringOutYourDead
void BringOutYourDead(const double *verts, unsigned int vcount, double *overts, unsigned int &ocount, unsigned int *indices, unsigned indexcount)
Definition: cd_hull.cpp:3444
ConvexDecomposition::HullResult::mNumIndices
unsigned int mNumIndices
Definition: cd_hull.h:81
ConvexDecomposition::QF_DEFAULT
@ QF_DEFAULT
Definition: cd_hull.h:140
ConvexDecomposition::HullResult
Definition: cd_hull.h:65
ConvexDecomposition
Definition: bestfit.cpp:75
ConvexDecomposition::FHullResult
Definition: cd_hull.h:88
ConvexDecomposition::HullLibrary
Definition: cd_hull.h:221
ConvexDecomposition::HullDesc::mMaxVertices
unsigned int mMaxVertices
Definition: cd_hull.h:194
ConvexDecomposition::HullError
HullError
Definition: cd_hull.h:197
ConvexDecomposition::ConvexHullVertex::mTexel
double mTexel[2]
Definition: cd_hull.h:209
ConvexDecomposition::HullDesc::mVertexStride
unsigned int mVertexStride
Definition: cd_hull.h:191
ConvexDecomposition::HullLibrary::CleanupVertices
bool CleanupVertices(unsigned int svcount, const double *svertices, unsigned int stride, unsigned int &vcount, double *vertices, double normalepsilon, double *scale)
Definition: cd_hull.cpp:3187
ConvexDecomposition::HullDesc::SetHullFlag
void SetHullFlag(HullFlag flag)
Definition: cd_hull.h:178
ConvexDecomposition::FHullResult::~FHullResult
~FHullResult(void)
Definition: cd_hull.h:119
ConvexDecomposition::QE_FAIL
@ QE_FAIL
Definition: cd_hull.h:200
ConvexDecomposition::FHullResult::mPolygons
bool mPolygons
Definition: cd_hull.h:124
ConvexDecomposition::HullDesc::HullDesc
HullDesc(void)
Definition: cd_hull.h:147
ConvexDecomposition::FHullResult::mNumFaces
unsigned int mNumFaces
Definition: cd_hull.h:127
ConvexDecomposition::QF_REVERSE_ORDER
@ QF_REVERSE_ORDER
Definition: cd_hull.h:138
ConvexDecomposition::HullLibrary::ComputeNormal
double ComputeNormal(double *n, const double *A, const double *B, const double *C)
Definition: cd_hull.cpp:3614
ConvexDecomposition::HullResult::mIndices
unsigned int * mIndices
Definition: cd_hull.h:82
ConvexDecomposition::ConvexHullVertex
Definition: cd_hull.h:204
ConvexDecomposition::HullResult::mNumFaces
unsigned int mNumFaces
Definition: cd_hull.h:80
ConvexDecomposition::FHullResult::mNumOutputVertices
unsigned int mNumOutputVertices
Definition: cd_hull.h:125
ConvexDecomposition::QF_SKIN_WIDTH
@ QF_SKIN_WIDTH
Definition: cd_hull.h:139
ConvexDecomposition::FHullResult::mNumIndices
unsigned int mNumIndices
Definition: cd_hull.h:128
ConvexDecomposition::HullFlag
HullFlag
Definition: cd_hull.h:135
ConvexDecomposition::QE_OK
@ QE_OK
Definition: cd_hull.h:199
ConvexDecomposition::HullDesc::mVertices
const double * mVertices
Definition: cd_hull.h:190
ConvexDecomposition::HullDesc::HasHullFlag
bool HasHullFlag(HullFlag flag) const
Definition: cd_hull.h:172
ConvexDecomposition::HullLibrary::CreateTriangleMesh
HullError CreateTriangleMesh(HullResult &answer, ConvexHullTriangleInterface *iface)
Definition: cd_hull.cpp:3483
ConvexDecomposition::FHullResult::FHullResult
FHullResult(const HullResult &r)
Definition: cd_hull.h:91
ConvexDecomposition::FHullResult::mOutputVertices
float * mOutputVertices
Definition: cd_hull.h:126
ConvexDecomposition::HullDesc::mNormalEpsilon
double mNormalEpsilon
Definition: cd_hull.h:192
ConvexDecomposition::ConvexHullTriangleInterface
Definition: cd_hull.h:213
ConvexDecomposition::HullDesc::ClearHullFlag
void ClearHullFlag(HullFlag flag)
Definition: cd_hull.h:183
ConvexDecomposition::HullDesc::HullDesc
HullDesc(HullFlag flag, unsigned int vcount, const double *vertices, unsigned int stride)
Definition: cd_hull.h:158


convex_decomposition
Author(s): John W. Ratcliff
autogenerated on Wed Mar 2 2022 00:04:59