00001 /* Copyright (c) 2011 Khaled Mamou (kmamou at gmail dot com) 00002 All rights reserved. 00003 00004 00005 Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 00006 00007 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 00008 00009 2. 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. 00010 00011 3. The names of the contributors may not be used to endorse or promote products derived from this software without specific prior written permission. 00012 00013 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 COPYRIGHT HOLDER 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. 00014 */ 00015 #pragma once 00016 #ifndef VHACD_H 00017 #define VHACD_H 00018 00019 #define VHACD_VERSION_MAJOR 2 00020 #define VHACD_VERSION_MINOR 3 00021 00022 // Changes for version 2.3 00023 // 00024 // m_gamma : Has been removed. This used to control the error metric to merge convex hulls. Now it uses the 'm_maxConvexHulls' value instead. 00025 // m_maxConvexHulls : This is the maximum number of convex hulls to produce from the merge operation; replaces 'm_gamma'. 00026 // 00027 // Note that decomposition depth is no longer a user provided value. It is now derived from the 00028 // maximum number of hulls requested. 00029 // 00030 // As a convenience to the user, each convex hull produced now includes the volume of the hull as well as it's center. 00031 // 00032 // This version supports a convenience method to automatically make V-HACD run asynchronously in a background thread. 00033 // To get a fully asynchronous version, call 'CreateVHACD_ASYNC' instead of 'CreateVHACD'. You get the same interface however, 00034 // now when computing convex hulls, it is no longer a blocking operation. All callback messages are still returned 00035 // in the application's thread so you don't need to worry about mutex locks or anything in that case. 00036 // To tell if the operation is complete, the application should call 'IsReady'. This will return true if 00037 // the last approximation operation is complete and will dispatch any pending messages. 00038 // If you call 'Compute' while a previous operation was still running, it will automatically cancel the last request 00039 // and begin a new one. To cancel a currently running approximation just call 'Cancel'. 00040 #include <stdint.h> 00041 00042 namespace VHACD { 00043 class IVHACD { 00044 public: 00045 class IUserCallback { 00046 public: 00047 virtual ~IUserCallback(){}; 00048 virtual void Update(const double overallProgress, 00049 const double stageProgress, 00050 const double operationProgress, 00051 const char* const stage, 00052 const char* const operation) 00053 = 0; 00054 }; 00055 00056 class IUserLogger { 00057 public: 00058 virtual ~IUserLogger(){}; 00059 virtual void Log(const char* const msg) = 0; 00060 }; 00061 00062 class ConvexHull { 00063 public: 00064 double* m_points; 00065 uint32_t* m_triangles; 00066 uint32_t m_nPoints; 00067 uint32_t m_nTriangles; 00068 double m_volume; 00069 double m_center[3]; 00070 }; 00071 00072 class Parameters { 00073 public: 00074 Parameters(void) { Init(); } 00075 void Init(void) 00076 { 00077 m_resolution = 100000; 00078 m_concavity = 0.001; 00079 m_planeDownsampling = 4; 00080 m_convexhullDownsampling = 4; 00081 m_alpha = 0.05; 00082 m_beta = 0.05; 00083 m_pca = 0; 00084 m_mode = 0; // 0: voxel-based (recommended), 1: tetrahedron-based 00085 m_maxNumVerticesPerCH = 64; 00086 m_minVolumePerCH = 0.0001; 00087 m_callback = 0; 00088 m_logger = 0; 00089 m_convexhullApproximation = true; 00090 m_oclAcceleration = true; 00091 m_maxConvexHulls = 1024; 00092 m_projectHullVertices = true; // This will project the output convex hull vertices onto the original source mesh to increase the floating point accuracy of the results 00093 } 00094 double m_concavity; 00095 double m_alpha; 00096 double m_beta; 00097 double m_minVolumePerCH; 00098 IUserCallback* m_callback; 00099 IUserLogger* m_logger; 00100 uint32_t m_resolution; 00101 uint32_t m_maxNumVerticesPerCH; 00102 uint32_t m_planeDownsampling; 00103 uint32_t m_convexhullDownsampling; 00104 uint32_t m_pca; 00105 uint32_t m_mode; 00106 uint32_t m_convexhullApproximation; 00107 uint32_t m_oclAcceleration; 00108 uint32_t m_maxConvexHulls; 00109 bool m_projectHullVertices; 00110 }; 00111 00112 class Constraint 00113 { 00114 public: 00115 uint32_t mHullA; // Convex Hull A index 00116 uint32_t mHullB; // Convex Hull B index 00117 double mConstraintPoint[3]; // The point of intersection between the two convex hulls 00118 }; 00119 00120 virtual void Cancel() = 0; 00121 virtual bool Compute(const float* const points, 00122 const uint32_t countPoints, 00123 const uint32_t* const triangles, 00124 const uint32_t countTriangles, 00125 const Parameters& params) 00126 = 0; 00127 virtual bool Compute(const double* const points, 00128 const uint32_t countPoints, 00129 const uint32_t* const triangles, 00130 const uint32_t countTriangles, 00131 const Parameters& params) 00132 = 0; 00133 virtual uint32_t GetNConvexHulls() const = 0; 00134 virtual void GetConvexHull(const uint32_t index, ConvexHull& ch) const = 0; 00135 virtual void Clean(void) = 0; // release internally allocated memory 00136 virtual void Release(void) = 0; // release IVHACD 00137 virtual bool OCLInit(void* const oclDevice, 00138 IUserLogger* const logger = 0) 00139 = 0; 00140 virtual bool OCLRelease(IUserLogger* const logger = 0) = 0; 00141 00142 // Will compute the center of mass of the convex hull decomposition results and return it 00143 // in 'centerOfMass'. Returns false if the center of mass could not be computed. 00144 virtual bool ComputeCenterOfMass(double centerOfMass[3]) const = 0; 00145 00146 // Will analyze the HACD results and compute the constraints solutions. 00147 // It will analyze the point at which any two convex hulls touch each other and 00148 // return the total number of constraint pairs found 00149 virtual uint32_t ComputeConstraints(void) = 0; 00150 00151 // Returns a pointer to the constraint index; null if the index is not valid or 00152 // the user did not previously call 'ComputeConstraints' 00153 virtual const Constraint *GetConstraint(uint32_t index) const = 0; 00154 00155 // In synchronous mode (non-multi-threaded) the state is always 'ready' 00156 // In asynchronous mode, this returns true if the background thread is not still actively computing 00157 // a new solution. In an asynchronous config the 'IsReady' call will report any update or log 00158 // messages in the caller's current thread. 00159 virtual bool IsReady(void) const 00160 { 00161 return true; 00162 } 00163 00164 protected: 00165 virtual ~IVHACD(void) {} 00166 }; 00167 IVHACD* CreateVHACD(void); 00168 IVHACD* CreateVHACD_ASYNC(void); 00169 } 00170 #endif // VHACD_H