VHACD.h
Go to the documentation of this file.
1 /* Copyright (c) 2011 Khaled Mamou (kmamou at gmail dot com)
2  All rights reserved.
3 
4 
5  Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
6 
7  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
8 
9  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.
10 
11  3. The names of the contributors may not be used to endorse or promote products derived from this software without specific prior written permission.
12 
13  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.
14  */
15 #pragma once
16 #ifndef VHACD_H
17 #define VHACD_H
18 
19 #define VHACD_VERSION_MAJOR 2
20 #define VHACD_VERSION_MINOR 3
21 
22 // Changes for version 2.3
23 //
24 // m_gamma : Has been removed. This used to control the error metric to merge convex hulls. Now it uses the 'm_maxConvexHulls' value instead.
25 // m_maxConvexHulls : This is the maximum number of convex hulls to produce from the merge operation; replaces 'm_gamma'.
26 //
27 // Note that decomposition depth is no longer a user provided value. It is now derived from the
28 // maximum number of hulls requested.
29 //
30 // As a convenience to the user, each convex hull produced now includes the volume of the hull as well as it's center.
31 //
32 // This version supports a convenience method to automatically make V-HACD run asynchronously in a background thread.
33 // To get a fully asynchronous version, call 'CreateVHACD_ASYNC' instead of 'CreateVHACD'. You get the same interface however,
34 // now when computing convex hulls, it is no longer a blocking operation. All callback messages are still returned
35 // in the application's thread so you don't need to worry about mutex locks or anything in that case.
36 // To tell if the operation is complete, the application should call 'IsReady'. This will return true if
37 // the last approximation operation is complete and will dispatch any pending messages.
38 // If you call 'Compute' while a previous operation was still running, it will automatically cancel the last request
39 // and begin a new one. To cancel a currently running approximation just call 'Cancel'.
40 #include <stdint.h>
41 
42 namespace VHACD {
43 class IVHACD {
44 public:
45  class IUserCallback {
46  public:
47  virtual ~IUserCallback(){};
48  virtual void Update(const double overallProgress,
49  const double stageProgress,
50  const double operationProgress,
51  const char* const stage,
52  const char* const operation)
53  = 0;
54  };
55 
56  class IUserLogger {
57  public:
58  virtual ~IUserLogger(){};
59  virtual void Log(const char* const msg) = 0;
60  };
61 
62  class ConvexHull {
63  public:
64  double* m_points;
65  uint32_t* m_triangles;
66  uint32_t m_nPoints;
67  uint32_t m_nTriangles;
68  double m_volume;
69  double m_center[3];
70  };
71 
72  class Parameters {
73  public:
74  Parameters(void) { Init(); }
75  void Init(void)
76  {
77  m_resolution = 100000;
78  m_concavity = 0.001;
79  m_planeDownsampling = 4;
80  m_convexhullDownsampling = 4;
81  m_alpha = 0.05;
82  m_beta = 0.05;
83  m_pca = 0;
84  m_mode = 0; // 0: voxel-based (recommended), 1: tetrahedron-based
85  m_maxNumVerticesPerCH = 64;
86  m_minVolumePerCH = 0.0001;
87  m_callback = 0;
88  m_logger = 0;
89  m_convexhullApproximation = true;
90  m_oclAcceleration = true;
91  m_maxConvexHulls = 1024;
92  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
93  }
94  double m_concavity;
95  double m_alpha;
96  double m_beta;
100  uint32_t m_resolution;
104  uint32_t m_pca;
105  uint32_t m_mode;
110  };
111 
113  {
114  public:
115  uint32_t mHullA; // Convex Hull A index
116  uint32_t mHullB; // Convex Hull B index
117  double mConstraintPoint[3]; // The point of intersection between the two convex hulls
118  };
119 
120  virtual void Cancel() = 0;
121  virtual bool Compute(const float* const points,
122  const uint32_t countPoints,
123  const uint32_t* const triangles,
124  const uint32_t countTriangles,
125  const Parameters& params)
126  = 0;
127  virtual bool Compute(const double* const points,
128  const uint32_t countPoints,
129  const uint32_t* const triangles,
130  const uint32_t countTriangles,
131  const Parameters& params)
132  = 0;
133  virtual uint32_t GetNConvexHulls() const = 0;
134  virtual void GetConvexHull(const uint32_t index, ConvexHull& ch) const = 0;
135  virtual void Clean(void) = 0; // release internally allocated memory
136  virtual void Release(void) = 0; // release IVHACD
137  virtual bool OCLInit(void* const oclDevice,
138  IUserLogger* const logger = 0)
139  = 0;
140  virtual bool OCLRelease(IUserLogger* const logger = 0) = 0;
141 
142  // Will compute the center of mass of the convex hull decomposition results and return it
143  // in 'centerOfMass'. Returns false if the center of mass could not be computed.
144  virtual bool ComputeCenterOfMass(double centerOfMass[3]) const = 0;
145 
146  // Will analyze the HACD results and compute the constraints solutions.
147  // It will analyze the point at which any two convex hulls touch each other and
148  // return the total number of constraint pairs found
149  virtual uint32_t ComputeConstraints(void) = 0;
150 
151  // Returns a pointer to the constraint index; null if the index is not valid or
152  // the user did not previously call 'ComputeConstraints'
153  virtual const Constraint *GetConstraint(uint32_t index) const = 0;
154 
155  // In synchronous mode (non-multi-threaded) the state is always 'ready'
156  // In asynchronous mode, this returns true if the background thread is not still actively computing
157  // a new solution. In an asynchronous config the 'IsReady' call will report any update or log
158  // messages in the caller's current thread.
159  virtual bool IsReady(void) const
160  {
161  return true;
162  }
163 
164 protected:
165  virtual ~IVHACD(void) {}
166 };
167 IVHACD* CreateVHACD(void);
169 }
170 #endif // VHACD_H
Definition: VHACD.h:56
uint32_t m_planeDownsampling
Definition: VHACD.h:102
Definition: VHACD.h:43
uint32_t * m_triangles
Definition: VHACD.h:65
uint32_t m_maxConvexHulls
Definition: VHACD.h:108
IVHACD * CreateVHACD(void)
virtual bool Compute(const float *const points, const uint32_t countPoints, const uint32_t *const triangles, const uint32_t countTriangles, const Parameters &params)=0
IUserCallback * m_callback
Definition: VHACD.h:98
virtual bool OCLInit(void *const oclDevice, IUserLogger *const logger=0)=0
IVHACD * CreateVHACD_ASYNC(void)
virtual uint32_t GetNConvexHulls() const =0
uint32_t m_resolution
Definition: VHACD.h:100
virtual bool OCLRelease(IUserLogger *const logger=0)=0
virtual uint32_t ComputeConstraints(void)=0
void Init(void)
Definition: VHACD.h:75
Definition: VHACD.h:112
uint32_t mHullA
Definition: VHACD.h:115
double m_minVolumePerCH
Definition: VHACD.h:97
virtual ~IVHACD(void)
Definition: VHACD.h:165
virtual bool ComputeCenterOfMass(double centerOfMass[3]) const =0
virtual bool IsReady(void) const
Definition: VHACD.h:159
virtual ~IUserCallback()
Definition: VHACD.h:47
uint32_t m_mode
Definition: VHACD.h:105
Definition: vhacdCircularList.h:19
virtual void Cancel()=0
double m_volume
Definition: VHACD.h:68
uint32_t mHullB
Definition: VHACD.h:116
virtual void Release(void)=0
virtual void GetConvexHull(const uint32_t index, ConvexHull &ch) const =0
Definition: VHACD.h:72
uint32_t m_pca
Definition: VHACD.h:104
uint32_t m_maxNumVerticesPerCH
Definition: VHACD.h:101
uint32_t m_oclAcceleration
Definition: VHACD.h:107
Parameters(void)
Definition: VHACD.h:74
virtual ~IUserLogger()
Definition: VHACD.h:58
double m_concavity
Definition: VHACD.h:94
virtual const Constraint * GetConstraint(uint32_t index) const =0
uint32_t m_convexhullDownsampling
Definition: VHACD.h:103
bool m_projectHullVertices
Definition: VHACD.h:109
uint32_t m_nTriangles
Definition: VHACD.h:67
uint32_t m_convexhullApproximation
Definition: VHACD.h:106
virtual void Clean(void)=0
uint32_t m_nPoints
Definition: VHACD.h:66
virtual void Update(const double overallProgress, const double stageProgress, const double operationProgress, const char *const stage, const char *const operation)=0
Definition: VHACD.h:62
double * m_points
Definition: VHACD.h:64
double m_beta
Definition: VHACD.h:96
IUserLogger * m_logger
Definition: VHACD.h:99
double m_alpha
Definition: VHACD.h:95
Definition: VHACD.h:45