ConvexDecomposition.h
Go to the documentation of this file.
1 #ifndef CONVEX_DECOMPOSITION_H
2 
3 #define CONVEX_DECOMPOSITION_H
4 
5 namespace ConvexDecomposition
6 {
7 
65 {
66 public:
68  {
69  mHullVcount = 0;
70  mHullVertices = 0;
71  mHullTcount = 0;
72  mHullIndices = 0;
73  }
74 
75  ConvexResult(unsigned int hvcount,const double *hvertices,unsigned int htcount,const unsigned int *hindices)
76  {
77  mHullVcount = hvcount;
78  if ( mHullVcount )
79  {
80  mHullVertices = new double[mHullVcount*sizeof(double)*3];
81  memcpy(mHullVertices, hvertices, sizeof(double)*3*mHullVcount );
82  }
83  else
84  {
85  mHullVertices = 0;
86  }
87 
88  mHullTcount = htcount;
89 
90  if ( mHullTcount )
91  {
92  mHullIndices = new unsigned int[sizeof(unsigned int)*mHullTcount*3];
93  memcpy(mHullIndices,hindices, sizeof(unsigned int)*mHullTcount*3 );
94  }
95  else
96  {
97  mHullIndices = 0;
98  }
99 
100  }
101 
102  ConvexResult(const ConvexResult &r) // copy constructor, perform a deep copy of the data.
103  {
105  if ( mHullVcount )
106  {
107  mHullVertices = new double[mHullVcount*sizeof(double)*3];
108  memcpy(mHullVertices, r.mHullVertices, sizeof(double)*3*mHullVcount );
109  }
110  else
111  {
112  mHullVertices = 0;
113  }
115  if ( mHullTcount )
116  {
117  mHullIndices = new unsigned int[sizeof(unsigned int)*mHullTcount*3];
118  memcpy(mHullIndices, r.mHullIndices, sizeof(unsigned int)*mHullTcount*3 );
119  }
120  else
121  {
122  mHullIndices = 0;
123  }
124  }
125 
127  {
128  delete mHullVertices;
129  delete mHullIndices;
130  }
131 
132 // the convex hull.
133  unsigned int mHullVcount;
134  double * mHullVertices;
135  unsigned int mHullTcount;
136  unsigned int *mHullIndices;
137 
138  double mHullVolume; // the volume of the convex hull.
139 
140 };
141 
142 // convert from doubles back down to floats.
144 {
145 public:
147  {
149  mHullVertices = 0;
150  if ( mHullVcount )
151  {
152  mHullVertices = new float[mHullVcount*3];
153 
154  const double *src = r.mHullVertices;
155  float * dest = mHullVertices;
156  for (unsigned int i=0; i<mHullVcount; i++)
157  {
158  dest[0] = (float) src[0];
159  dest[1] = (float) src[1];
160  dest[2] = (float) src[2];
161  src+=3;
162  dest+=3;
163  }
164  }
166  if ( mHullTcount )
167  {
168  mHullIndices = new unsigned int[mHullTcount*3];
169  memcpy(mHullIndices,r.mHullIndices,sizeof(unsigned int)*mHullTcount*3);
170  }
171  else
172  {
173  mHullIndices = 0;
174  }
175  mHullVolume = (float)r.mHullVolume;
176  }
177 
179  {
180  delete mHullVertices;
181  delete mHullIndices;
182  }
183 
184  unsigned int mHullVcount;
185  float * mHullVertices;
186  unsigned int mHullTcount;
187  unsigned int *mHullIndices;
188  float mHullVolume; // the volume of the convex hull.
189 };
190 
192 {
193 public:
194 
195  virtual void ConvexDebugTri(const double *p1,const double *p2,const double *p3,unsigned int color) { };
196  virtual void ConvexDebugPoint(const double *p,double dist,unsigned int color) { };
197  virtual void ConvexDebugBound(const double *bmin,const double *bmax,unsigned int color) { };
198  virtual void ConvexDebugOBB(const double *sides, const double *matrix,unsigned int color) { };
199 
200  virtual void ConvexDecompResult(ConvexResult &result) = 0;
201 
202 
203 
204 };
205 
206 // just to avoid passing a zillion parameters to the method the
207 // options are packed into this descriptor.
209 {
210 public:
212  {
213  mVcount = 0;
214  mVertices = 0;
215  mTcount = 0;
216  mIndices = 0;
217  mDepth = 5;
218  mCpercent = 5;
219  mPpercent = 5;
220  mMaxVertices = 32;
221  mSkinWidth = 0;
222  mCallback = 0;
223  }
224 
225 // describes the input triangle.
226  unsigned int mVcount; // the number of vertices in the source mesh.
227  const double *mVertices; // start of the vertex position array. Assumes a stride of 3 doubles.
228  unsigned int mTcount; // the number of triangles in the source mesh.
229  unsigned int *mIndices; // the indexed triangle list array (zero index based)
230 
231 // options
232  unsigned int mDepth; // depth to split, a maximum of 10, generally not over 7.
233  double mCpercent; // the concavity threshold percentage. 0=20 is reasonable.
234  double mPpercent; // the percentage volume conservation threshold to collapse hulls. 0-30 is reasonable.
235 
236 // hull output limits.
237  unsigned int mMaxVertices; // maximum number of vertices in the output hull. Recommended 32 or less.
238  double mSkinWidth; // a skin width to apply to the output hulls.
239 
240  ConvexDecompInterface *mCallback; // the interface to receive back the results.
241 
242 };
243 
244 // perform approximate convex decomposition on a mesh.
245 unsigned int performConvexDecomposition(const DecompDesc &desc); // returns the number of hulls produced.
246 
247 };
248 
249 #endif
ConvexDecomposition::DecompDesc::mDepth
unsigned int mDepth
Definition: ConvexDecomposition.h:232
ConvexDecomposition::ConvexDecompInterface::ConvexDebugOBB
virtual void ConvexDebugOBB(const double *sides, const double *matrix, unsigned int color)
Definition: ConvexDecomposition.h:198
ConvexDecomposition::ConvexResult::ConvexResult
ConvexResult(unsigned int hvcount, const double *hvertices, unsigned int htcount, const unsigned int *hindices)
Definition: ConvexDecomposition.h:75
ConvexDecomposition::DecompDesc::mSkinWidth
double mSkinWidth
Definition: ConvexDecomposition.h:238
ConvexDecomposition::FConvexResult::~FConvexResult
~FConvexResult(void)
Definition: ConvexDecomposition.h:178
ConvexDecomposition::DecompDesc::DecompDesc
DecompDesc(void)
Definition: ConvexDecomposition.h:211
ConvexDecomposition::FConvexResult::mHullVcount
unsigned int mHullVcount
Definition: ConvexDecomposition.h:184
ConvexDecomposition::ConvexDecompInterface::ConvexDecompResult
virtual void ConvexDecompResult(ConvexResult &result)=0
ConvexDecomposition::performConvexDecomposition
unsigned int performConvexDecomposition(const DecompDesc &desc)
Definition: ConvexDecomposition.cpp:1049
ConvexDecomposition::ConvexResult
Definition: ConvexDecomposition.h:64
ConvexDecomposition::FConvexResult::mHullVertices
float * mHullVertices
Definition: ConvexDecomposition.h:185
ConvexDecomposition::ConvexResult::mHullTcount
unsigned int mHullTcount
Definition: ConvexDecomposition.h:135
ConvexDecomposition::FConvexResult::mHullTcount
unsigned int mHullTcount
Definition: ConvexDecomposition.h:186
ConvexDecomposition::ConvexResult::ConvexResult
ConvexResult(void)
Definition: ConvexDecomposition.h:67
ConvexDecomposition
Definition: bestfit.cpp:75
ConvexDecomposition::ConvexDecompInterface::ConvexDebugPoint
virtual void ConvexDebugPoint(const double *p, double dist, unsigned int color)
Definition: ConvexDecomposition.h:196
ConvexDecomposition::FConvexResult::mHullIndices
unsigned int * mHullIndices
Definition: ConvexDecomposition.h:187
ConvexDecomposition::ConvexResult::mHullIndices
unsigned int * mHullIndices
Definition: ConvexDecomposition.h:136
ConvexDecomposition::DecompDesc::mIndices
unsigned int * mIndices
Definition: ConvexDecomposition.h:229
ConvexDecomposition::ConvexResult::mHullVolume
double mHullVolume
Definition: ConvexDecomposition.h:138
ConvexDecomposition::DecompDesc::mTcount
unsigned int mTcount
Definition: ConvexDecomposition.h:228
ConvexDecomposition::ConvexResult::~ConvexResult
~ConvexResult(void)
Definition: ConvexDecomposition.h:126
ConvexDecomposition::DecompDesc::mPpercent
double mPpercent
Definition: ConvexDecomposition.h:234
ConvexDecomposition::DecompDesc::mCallback
ConvexDecompInterface * mCallback
Definition: ConvexDecomposition.h:240
ConvexDecomposition::DecompDesc::mVcount
unsigned int mVcount
Definition: ConvexDecomposition.h:226
ConvexDecomposition::ConvexDecompInterface
Definition: ConvexDecomposition.h:191
ConvexDecomposition::ConvexDecompInterface::ConvexDebugTri
virtual void ConvexDebugTri(const double *p1, const double *p2, const double *p3, unsigned int color)
Definition: ConvexDecomposition.h:195
ConvexDecomposition::FConvexResult
Definition: ConvexDecomposition.h:143
ConvexDecomposition::FConvexResult::mHullVolume
float mHullVolume
Definition: ConvexDecomposition.h:188
ConvexDecomposition::FConvexResult::FConvexResult
FConvexResult(const ConvexResult &r)
Definition: ConvexDecomposition.h:146
ConvexDecomposition::ConvexResult::mHullVcount
unsigned int mHullVcount
Definition: ConvexDecomposition.h:133
ConvexDecomposition::DecompDesc::mVertices
const double * mVertices
Definition: ConvexDecomposition.h:227
ConvexDecomposition::ConvexResult::mHullVertices
double * mHullVertices
Definition: ConvexDecomposition.h:134
ConvexDecomposition::DecompDesc
Definition: ConvexDecomposition.h:208
ConvexDecomposition::DecompDesc::mMaxVertices
unsigned int mMaxVertices
Definition: ConvexDecomposition.h:237
ConvexDecomposition::ConvexResult::ConvexResult
ConvexResult(const ConvexResult &r)
Definition: ConvexDecomposition.h:102
ConvexDecomposition::DecompDesc::mCpercent
double mCpercent
Definition: ConvexDecomposition.h:233
ConvexDecomposition::ConvexDecompInterface::ConvexDebugBound
virtual void ConvexDebugBound(const double *bmin, const double *bmax, unsigned int color)
Definition: ConvexDecomposition.h:197


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