Tesseract
Motion Planning Environment
Loading...
Searching...
No Matches
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
6 following conditions are met:
7
8 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following
9 disclaimer.
10
11 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following
12 disclaimer in the documentation and/or other materials provided with the distribution.
13
14 3. The names of the contributors may not be used to endorse or promote products derived from this software without
15 specific prior written permission.
16
17 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
18 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
22 WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25#pragma once
26
27#define VHACD_VERSION_MAJOR 2
28#define VHACD_VERSION_MINOR 3
29
30// Changes for version 2.3
31//
32// m_gamma : Has been removed. This used to control the error metric to merge convex hulls. Now it uses the
33// 'm_maxConvexHulls' value instead.
34// m_maxConvexHulls : This is the maximum number of convex hulls to produce from the merge operation; replaces
35// 'm_gamma'.
36//
37// Note that decomposition depth is no longer a user provided value. It is now derived from the
38// maximum number of hulls requested.
39//
40// As a convenience to the user, each convex hull produced now includes the volume of the hull as well as it's center.
41//
42// This version supports a convenience method to automatically make V-HACD run asynchronously in a background thread.
43// To get a fully asynchronous version, call 'CreateVHACD_ASYNC' instead of 'CreateVHACD'. You get the same interface
44// however,
45// now when computing convex hulls, it is no longer a blocking operation. All callback messages are still returned
46// in the application's thread so you don't need to worry about mutex locks or anything in that case.
47// To tell if the operation is complete, the application should call 'IsReady'. This will return true if
48// the last approximation operation is complete and will dispatch any pending messages.
49// If you call 'Compute' while a previous operation was still running, it will automatically cancel the last request
50// and begin a new one. To cancel a currently running approximation just call 'Cancel'.
53#include <cstdint>
54#include <array>
55#include <string>
57
59{
60class IVHACD
61{
62public:
63 IVHACD() = default;
64 virtual ~IVHACD() = default;
65 IVHACD(const IVHACD&) = default;
66 IVHACD& operator=(const IVHACD&) = default;
67 IVHACD(IVHACD&&) = default;
68 IVHACD& operator=(IVHACD&&) = default;
69
71 {
72 public:
73 IUserCallback() = default;
74 virtual ~IUserCallback() = default;
75 IUserCallback(const IUserCallback&) = default;
79
80 virtual void Update(double overallProgress,
81 double stageProgress,
82 double operationProgress,
83 const std::string& stage,
84 const std::string& operation) = 0;
85 };
86
88 {
89 public:
90 IUserLogger() = default;
91 virtual ~IUserLogger() = default;
92 IUserLogger(const IUserLogger&) = default;
93 IUserLogger& operator=(const IUserLogger&) = default;
96
97 virtual void Log(const std::string& msg) const = 0;
98 };
99
101 {
102 public:
103 double* m_points;
104 uint32_t* m_triangles;
105 uint32_t m_nPoints;
106 uint32_t m_nTriangles;
107 double m_volume;
108 std::array<double, 3> m_center;
109 };
110
112 {
113 public:
115 void Init()
116 {
117 m_resolution = 100000;
118 m_concavity = 0.001;
121 m_alpha = 0.05;
122 m_beta = 0.05;
123 m_pca = 0;
124 m_mode = 0; // 0: voxel-based (recommended), 1: tetrahedron-based
126 m_minVolumePerCH = 0.0001;
127 m_callback = nullptr;
128 m_logger = nullptr;
131 m_maxConvexHulls = 1024;
132 m_projectHullVertices = true; // This will project the output convex hull vertices onto the original source mesh
133 // to increase the floating point accuracy of the results
134 }
135 double m_concavity{ 0.001 };
136 double m_alpha{ 0.05 };
137 double m_beta{ 0.05 };
138 double m_minVolumePerCH{ 0.0001 };
141 uint32_t m_resolution{ 100000 };
142 uint32_t m_maxNumVerticesPerCH{ 64 };
143 uint32_t m_planeDownsampling{ 4 };
145 uint32_t m_pca{ 0 };
146 uint32_t m_mode{ 0 };
148 uint32_t m_oclAcceleration{ 1U };
149 uint32_t m_maxConvexHulls{ 1024 };
151 };
152
153 virtual void Cancel() = 0;
154 virtual bool Compute(float const* points,
155 uint32_t countPoints,
156 uint32_t const* triangles,
157 uint32_t countTriangles,
158 const Parameters& params) = 0;
159 virtual bool Compute(double const* points,
160 uint32_t countPoints,
161 uint32_t const* triangles,
162 uint32_t countTriangles,
163 const Parameters& params) = 0;
164 virtual uint32_t GetNConvexHulls() const = 0;
165 virtual void GetConvexHull(uint32_t index, ConvexHull& ch) const = 0;
166 virtual void Clean() = 0; // release internally allocated memory
167 virtual void Release() = 0; // release IVHACD
168 virtual bool OCLInit(void const* oclDevice, IUserLogger const* logger = nullptr) = 0;
169 virtual bool OCLRelease(IUserLogger const* logger = nullptr) = 0;
170
171 // Will compute the center of mass of the convex hull decomposition results and return it
172 // in 'centerOfMass'. Returns false if the center of mass could not be computed.
173 virtual bool ComputeCenterOfMass(std::array<double, 3>& centerOfMass) const = 0;
174
175 // In synchronous mode (non-multi-threaded) the state is always 'ready'
176 // In asynchronous mode, this returns true if the background thread is not still actively computing
177 // a new solution. In an asynchronous config the 'IsReady' call will report any update or log
178 // messages in the caller's current thread.
179 virtual bool IsReady() const { return true; }
180};
181IVHACD* CreateVHACD();
182IVHACD* CreateVHACD_ASYNC();
183} // namespace tesseract_collision::VHACD
uint32_t m_nTriangles
Definition: VHACD.h:106
double m_volume
Definition: VHACD.h:107
double * m_points
Definition: VHACD.h:103
uint32_t m_nPoints
Definition: VHACD.h:105
std::array< double, 3 > m_center
Definition: VHACD.h:108
uint32_t * m_triangles
Definition: VHACD.h:104
IUserCallback & operator=(IUserCallback &&)=default
virtual void Update(double overallProgress, double stageProgress, double operationProgress, const std::string &stage, const std::string &operation)=0
IUserCallback & operator=(const IUserCallback &)=default
IUserCallback(const IUserCallback &)=default
IUserLogger(const IUserLogger &)=default
virtual void Log(const std::string &msg) const =0
IUserLogger & operator=(const IUserLogger &)=default
IUserLogger & operator=(IUserLogger &&)=default
IUserLogger * m_logger
Definition: VHACD.h:140
double m_minVolumePerCH
Definition: VHACD.h:138
uint32_t m_mode
Definition: VHACD.h:146
double m_beta
Definition: VHACD.h:137
bool m_projectHullVertices
Definition: VHACD.h:150
uint32_t m_pca
Definition: VHACD.h:145
uint32_t m_maxConvexHulls
Definition: VHACD.h:149
double m_concavity
Definition: VHACD.h:135
uint32_t m_maxNumVerticesPerCH
Definition: VHACD.h:142
uint32_t m_convexhullDownsampling
Definition: VHACD.h:144
uint32_t m_resolution
Definition: VHACD.h:141
IUserCallback * m_callback
Definition: VHACD.h:139
double m_alpha
Definition: VHACD.h:136
uint32_t m_oclAcceleration
Definition: VHACD.h:148
uint32_t m_planeDownsampling
Definition: VHACD.h:143
uint32_t m_convexhullApproximation
Definition: VHACD.h:147
IVHACD(const IVHACD &)=default
virtual bool Compute(float const *points, uint32_t countPoints, uint32_t const *triangles, uint32_t countTriangles, const Parameters &params)=0
virtual bool ComputeCenterOfMass(std::array< double, 3 > &centerOfMass) const =0
virtual bool OCLInit(void const *oclDevice, IUserLogger const *logger=nullptr)=0
virtual uint32_t GetNConvexHulls() const =0
virtual bool Compute(double const *points, uint32_t countPoints, uint32_t const *triangles, uint32_t countTriangles, const Parameters &params)=0
virtual bool OCLRelease(IUserLogger const *logger=nullptr)=0
IVHACD & operator=(const IVHACD &)=default
virtual void GetConvexHull(uint32_t index, ConvexHull &ch) const =0
virtual bool IsReady() const
Definition: VHACD.h:179
IVHACD & operator=(IVHACD &&)=default
Common Tesseract Macros.
#define TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
Definition: macros.h:71
Definition: create_convex_hull.cpp:36
Definition: vhacdCircularList.h:32
IVHACD * CreateVHACD_ASYNC()
Definition: VHACD-ASYNC.cpp:310
IVHACD * CreateVHACD()
Definition: VHACD.cpp:233