ConvexDecomposition.h
Go to the documentation of this file.
00001 #ifndef CONVEX_DECOMPOSITION_H
00002 
00003 #define CONVEX_DECOMPOSITION_H
00004 
00005 namespace ConvexDecomposition
00006 {
00007 
00064 class ConvexResult
00065 {
00066 public:
00067   ConvexResult(void)
00068   {
00069     mHullVcount = 0;
00070     mHullVertices = 0;
00071     mHullTcount = 0;
00072     mHullIndices = 0;
00073   }
00074 
00075   ConvexResult(unsigned int hvcount,const double *hvertices,unsigned int htcount,const unsigned int *hindices)
00076   {
00077     mHullVcount = hvcount;
00078     if ( mHullVcount )
00079     {
00080       mHullVertices = new double[mHullVcount*sizeof(double)*3];
00081       memcpy(mHullVertices, hvertices, sizeof(double)*3*mHullVcount );
00082     }
00083     else
00084     {
00085       mHullVertices = 0;
00086     }
00087 
00088     mHullTcount = htcount;
00089 
00090     if ( mHullTcount )
00091     {
00092       mHullIndices = new unsigned int[sizeof(unsigned int)*mHullTcount*3];
00093       memcpy(mHullIndices,hindices, sizeof(unsigned int)*mHullTcount*3 );
00094     }
00095     else
00096     {
00097       mHullIndices = 0;
00098     }
00099 
00100   }
00101 
00102   ConvexResult(const ConvexResult &r) // copy constructor, perform a deep copy of the data.
00103   {
00104     mHullVcount = r.mHullVcount;
00105     if ( mHullVcount )
00106     {
00107       mHullVertices = new double[mHullVcount*sizeof(double)*3];
00108       memcpy(mHullVertices, r.mHullVertices, sizeof(double)*3*mHullVcount );
00109     }
00110     else
00111     {
00112       mHullVertices = 0;
00113     }
00114     mHullTcount = r.mHullTcount;
00115     if ( mHullTcount )
00116     {
00117       mHullIndices = new unsigned int[sizeof(unsigned int)*mHullTcount*3];
00118       memcpy(mHullIndices, r.mHullIndices, sizeof(unsigned int)*mHullTcount*3 );
00119     }
00120     else
00121     {
00122       mHullIndices = 0;
00123     }
00124   }
00125 
00126   ~ConvexResult(void)
00127   {
00128     delete mHullVertices;
00129     delete mHullIndices;
00130   }
00131 
00132 // the convex hull.
00133   unsigned int              mHullVcount;
00134   double *                                                mHullVertices;
00135   unsigned  int       mHullTcount;
00136   unsigned int                   *mHullIndices;
00137 
00138   double               mHullVolume;                 // the volume of the convex hull.
00139 
00140 };
00141 
00142 // convert from doubles back down to floats.
00143 class FConvexResult
00144 {
00145 public:
00146   FConvexResult(const ConvexResult &r)
00147   {
00148     mHullVcount = r.mHullVcount;
00149     mHullVertices = 0;
00150     if ( mHullVcount )
00151     {
00152       mHullVertices = new float[mHullVcount*3];
00153 
00154       const double *src = r.mHullVertices;
00155       float *     dest  = mHullVertices;
00156       for (unsigned int i=0; i<mHullVcount; i++)
00157       {
00158         dest[0] = (float) src[0];
00159         dest[1] = (float) src[1];
00160         dest[2] = (float) src[2];
00161         src+=3;
00162         dest+=3;
00163       }
00164     }
00165     mHullTcount = r.mHullTcount;
00166     if ( mHullTcount )
00167     {
00168       mHullIndices = new unsigned int[mHullTcount*3];
00169       memcpy(mHullIndices,r.mHullIndices,sizeof(unsigned int)*mHullTcount*3);
00170     }
00171     else
00172     {
00173       mHullIndices = 0;
00174     }
00175     mHullVolume = (float)r.mHullVolume;
00176   }
00177 
00178   ~FConvexResult(void)
00179   {
00180     delete mHullVertices;
00181     delete mHullIndices;
00182   }
00183 
00184   unsigned int              mHullVcount;
00185   float  *                                                mHullVertices;
00186   unsigned  int       mHullTcount;
00187   unsigned int                   *mHullIndices;
00188   float                mHullVolume;                 // the volume of the convex hull.
00189 };
00190 
00191 class ConvexDecompInterface
00192 {
00193 public:
00194 
00195         virtual void ConvexDebugTri(const double *p1,const double *p2,const double *p3,unsigned int color) { };
00196         virtual void ConvexDebugPoint(const double *p,double dist,unsigned int color) { };
00197   virtual void ConvexDebugBound(const double *bmin,const double *bmax,unsigned int color) { };
00198   virtual void ConvexDebugOBB(const double *sides, const double *matrix,unsigned int color) { };
00199 
00200   virtual void ConvexDecompResult(ConvexResult &result) = 0;
00201 
00202 
00203 
00204 };
00205 
00206 // just to avoid passing a zillion parameters to the method the
00207 // options are packed into this descriptor.
00208 class DecompDesc
00209 {
00210 public:
00211   DecompDesc(void)
00212   {
00213         mVcount = 0;
00214         mVertices = 0;
00215         mTcount   = 0;
00216         mIndices  = 0;
00217         mDepth    = 5;
00218         mCpercent = 5;
00219         mPpercent = 5;
00220         mMaxVertices = 32;
00221         mSkinWidth   = 0;
00222         mCallback    = 0;
00223   }
00224 
00225 // describes the input triangle.
00226   unsigned      int     mVcount;   // the number of vertices in the source mesh.
00227   const double  *mVertices; // start of the vertex position array.  Assumes a stride of 3 doubles.
00228   unsigned int  mTcount;   // the number of triangles in the source mesh.
00229   unsigned int *mIndices;  // the indexed triangle list array (zero index based)
00230 
00231 // options
00232   unsigned int  mDepth;    // depth to split, a maximum of 10, generally not over 7.
00233   double         mCpercent; // the concavity threshold percentage.  0=20 is reasonable.
00234         double         mPpercent; // the percentage volume conservation threshold to collapse hulls. 0-30 is reasonable.
00235 
00236 // hull output limits.
00237   unsigned int  mMaxVertices; // maximum number of vertices in the output hull. Recommended 32 or less.
00238   double         mSkinWidth;   // a skin width to apply to the output hulls.
00239 
00240         ConvexDecompInterface *mCallback; // the interface to receive back the results.
00241 
00242 };
00243 
00244 // perform approximate convex decomposition on a mesh.
00245 unsigned int performConvexDecomposition(const DecompDesc &desc); // returns the number of hulls produced.
00246 
00247 };
00248 
00249 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines


convex_decomposition
Author(s): John Ratcliff
autogenerated on Mon Aug 19 2013 11:02:33