convex_decomposition_vhacd.cpp
Go to the documentation of this file.
3 #include <console_bridge/console.h>
4 #include <iomanip>
6 
10 
11 namespace tesseract_collision
12 {
14 {
15 public:
16  ProgressCallback() = default;
17  ~ProgressCallback() override = default;
18  ProgressCallback(const ProgressCallback&) = default;
19  ProgressCallback& operator=(const ProgressCallback&) = default;
22 
23  void Update(const double overallProgress,
24  const double stageProgress,
25  const char* const stage,
26  const char* operation) override
27  {
28  std::cout << std::setfill(' ') << std::setw(3) << ceil(overallProgress) << "% "
29  << "[ " << stage << " " << std::setfill(' ') << std::setw(3) << ceil(stageProgress) << "% ] " << operation
30  << "\n";
31  }
32 };
33 
35 
36 std::vector<std::shared_ptr<tesseract_geometry::ConvexMesh> >
37 ConvexDecompositionVHACD::compute(const tesseract_common::VectorVector3d& vertices, const Eigen::VectorXi& faces) const
38 {
39  params_.print();
40 
41  std::vector<double> points_local;
42  points_local.reserve(vertices.size() * 3);
43  for (const auto& v : vertices)
44  {
45  points_local.push_back(v.x());
46  points_local.push_back(v.y());
47  points_local.push_back(v.z());
48  }
49 
50  std::vector<unsigned int> triangles_local;
51  triangles_local.reserve(static_cast<std::size_t>(faces.size()) / 4);
52  for (Eigen::Index i = 0; i < faces.rows();)
53  {
54  int face_vertice_cnt = faces(i++);
55  if (face_vertice_cnt != 3)
56  throw std::runtime_error("Currently only supports triangle meshes");
57 
58  triangles_local.push_back(static_cast<unsigned int>(faces(i++)));
59  triangles_local.push_back(static_cast<unsigned int>(faces(i++)));
60  triangles_local.push_back(static_cast<unsigned int>(faces(i++)));
61  }
62 
63  // run V-HACD
64  VHACD::IVHACD* interfaceVHACD = VHACD::CreateVHACD();
65 
66  ProgressCallback progress_callback;
78  par.m_callback = &progress_callback;
79 
80  bool res = interfaceVHACD->Compute(points_local.data(),
81  static_cast<unsigned int>(points_local.size() / 3),
82  triangles_local.data(),
83  static_cast<unsigned int>(triangles_local.size() / 3),
84  par);
85 
86  std::vector<tesseract_geometry::ConvexMesh::Ptr> output;
87  if (res)
88  {
89  unsigned int num_convex_hulls = interfaceVHACD->GetNConvexHulls();
91  for (unsigned int p = 0; p < num_convex_hulls; ++p)
92  {
93  interfaceVHACD->GetConvexHull(p, ch);
94 
95  auto vhacd_vertices = std::make_shared<tesseract_common::VectorVector3d>();
96  vhacd_vertices->reserve(ch.m_points.size());
97  for (const auto& m_point : ch.m_points)
98  {
99  Eigen::Vector3d v(m_point.mX, m_point.mY, m_point.mZ);
100  vhacd_vertices->push_back(v);
101  }
102 
103  auto ch_vertices = std::make_shared<tesseract_common::VectorVector3d>();
104  auto ch_faces = std::make_shared<Eigen::VectorXi>();
105  int ch_num_faces = tesseract_collision::createConvexHull(*ch_vertices, *ch_faces, *vhacd_vertices);
106  output.push_back(std::make_shared<tesseract_geometry::ConvexMesh>(ch_vertices, ch_faces, ch_num_faces));
107  }
108  }
109  else
110  {
111  CONSOLE_BRIDGE_logError("Decomposition cancelled by user!");
112  }
113 
114  interfaceVHACD->Clean();
115  interfaceVHACD->Release();
116 
117  return output;
118 }
119 
121 {
122  std::stringstream msg;
123  msg << "+ Parameters\n";
124  msg << "\t Max number of convex hulls " << max_convex_hulls << "\n";
125  msg << "\t Voxel resolution " << resolution << "\n";
126  msg << "\t Volume error allowed as a percentage " << minimum_volume_percent_error_allowed << "\n";
127  msg << "\t Maximum recursion depth " << max_recursion_depth << "\n";
128  msg << "\t Shrinkwrap output to source mesh " << shrinkwrap << "\n";
129  msg << "\t Fill mode ";
130  switch (fill_mode)
131  {
133  msg << "FLOOD_FILL";
134  break;
136  msg << "SURFACE_ONLY";
137  break;
139  msg << "RAYCAST_FILL";
140  break;
141  }
142  msg << "\n";
143  msg << "\t Maximum number of vertices " << max_num_vertices_per_ch << "\n";
144  msg << "\t Run asynchronously " << async_ACD << "\n";
145  msg << "\t Minimum size of a voxel edge " << min_edge_length << "\n";
146  msg << "\t Attempt to split planes along the best location " << find_best_plane << "\n";
147 
148  std::cout << msg.str();
149 }
150 
151 } // namespace tesseract_collision
VHACD::IVHACD::Release
virtual void Release()=0
VHACD::IVHACD::Parameters::m_resolution
uint32_t m_resolution
Definition: VHACD.h:398
VHACD::IVHACD::Parameters::m_maxConvexHulls
uint32_t m_maxConvexHulls
Definition: VHACD.h:397
tesseract_collision::ConvexDecompositionVHACD::params_
VHACDParameters params_
Definition: convex_decomposition_vhacd.h:79
VHACD::IVHACD::Parameters::m_maxRecursionDepth
uint32_t m_maxRecursionDepth
Definition: VHACD.h:401
tesseract_collision::VHACDParameters::min_edge_length
uint32_t min_edge_length
Once a voxel patch has an edge length of less than 4 on all 3 sides, we don't keep recursing.
Definition: convex_decomposition_vhacd.h:59
VHACD::IVHACD::Parameters::m_findBestPlane
bool m_findBestPlane
Definition: VHACD.h:408
tesseract_collision::VHACDParameters::minimum_volume_percent_error_allowed
double minimum_volume_percent_error_allowed
if the voxels are within 1% of the volume of the hull, we consider this a close enough approximation
Definition: convex_decomposition_vhacd.h:47
VHACD::IVHACD::Parameters::m_minEdgeLength
uint32_t m_minEdgeLength
Definition: VHACD.h:406
tesseract_collision::createConvexHull
int createConvexHull(tesseract_common::VectorVector3d &vertices, Eigen::VectorXi &faces, const tesseract_common::VectorVector3d &input, double shrink=-1, double shrinkClamp=-1)
Create a convex hull from vertices using Bullet Convex Hull Computer.
Definition: convex_hull_utils.cpp:37
VHACD::IVHACD::Parameters::m_fillMode
FillMode m_fillMode
Definition: VHACD.h:403
VHACD::IVHACD::Parameters::m_minimumVolumePercentErrorAllowed
double m_minimumVolumePercentErrorAllowed
Definition: VHACD.h:399
VHACD::IVHACD::ConvexHull
Definition: VHACD.h:375
tesseract_collision::ProgressCallback::Update
void Update(const double overallProgress, const double stageProgress, const char *const stage, const char *operation) override
Definition: convex_decomposition_vhacd.cpp:23
TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
#define TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
convex_decomposition_vhacd.h
Convex decomposition VHACD implementation.
VHACD::IVHACD::GetConvexHull
virtual bool GetConvexHull(const uint32_t index, ConvexHull &ch) const =0
VHACD::IVHACD::Clean
virtual void Clean()=0
convex_hull_utils.h
This is a collection of common methods.
VHACD::FillMode::FLOOD_FILL
@ FLOOD_FILL
tesseract_collision::ConvexDecompositionVHACD::ConvexDecompositionVHACD
ConvexDecompositionVHACD()=default
tesseract_collision::VHACDParameters::max_convex_hulls
uint32_t max_convex_hulls
The maximum number of convex hulls to produce.
Definition: convex_decomposition_vhacd.h:43
tesseract_collision::VHACDParameters::find_best_plane
bool find_best_plane
Whether or not to attempt to split planes along the best location. Experimental feature....
Definition: convex_decomposition_vhacd.h:61
tesseract_collision::ProgressCallback::~ProgressCallback
~ProgressCallback() override=default
tesseract_collision::VHACDParameters::print
void print() const
Definition: convex_decomposition_vhacd.cpp:120
VHACD::IVHACD::Compute
virtual bool Compute(const float *const points, const uint32_t countPoints, const uint32_t *const triangles, const uint32_t countTriangles, const Parameters &params)=0
tesseract_common::VectorVector3d
std::vector< Eigen::Vector3d > VectorVector3d
VHACD::IVHACD::GetNConvexHulls
virtual uint32_t GetNConvexHulls() const =0
tesseract_collision::VHACDParameters::fill_mode
VHACD::FillMode fill_mode
How to fill the interior of the voxelized mesh.
Definition: convex_decomposition_vhacd.h:53
TESSERACT_COMMON_IGNORE_WARNINGS_POP
Definition: create_convex_hull.cpp:37
tesseract_collision::VHACDParameters::resolution
uint32_t resolution
The voxel resolution to use.
Definition: convex_decomposition_vhacd.h:45
VHACD::FillMode::RAYCAST_FILL
@ RAYCAST_FILL
VHACD::IVHACD::Parameters::m_callback
IUserCallback * m_callback
Definition: VHACD.h:394
VHACD::IVHACD::Parameters
Definition: VHACD.h:391
VHACD::IVHACD::Parameters::m_maxNumVerticesPerCH
uint32_t m_maxNumVerticesPerCH
Definition: VHACD.h:404
tesseract_collision::VHACDParameters::max_recursion_depth
uint32_t max_recursion_depth
The maximum recursion depth.
Definition: convex_decomposition_vhacd.h:49
VHACD::CreateVHACD
IVHACD * CreateVHACD()
tesseract_collision::ProgressCallback
Definition: convex_decomposition_vhacd.cpp:13
VHACD::FillMode::SURFACE_ONLY
@ SURFACE_ONLY
convex_mesh.h
tesseract_collision::ProgressCallback::ProgressCallback
ProgressCallback()=default
tesseract_collision::VHACDParameters
Definition: convex_decomposition_vhacd.h:40
VHACD::IVHACD::Parameters::m_shrinkWrap
bool m_shrinkWrap
Definition: VHACD.h:402
tesseract_collision::VHACDParameters::async_ACD
bool async_ACD
Whether or not to run asynchronously, taking advantage of additional cores.
Definition: convex_decomposition_vhacd.h:57
tesseract_collision::ProgressCallback::operator=
ProgressCallback & operator=(const ProgressCallback &)=default
tesseract_collision
Definition: bullet_cast_bvh_manager.h:48
macros.h
VHACD::IVHACD::IUserCallback
Definition: VHACD.h:323
tesseract_collision::ConvexDecompositionVHACD::compute
std::vector< std::shared_ptr< tesseract_geometry::ConvexMesh > > compute(const tesseract_common::VectorVector3d &vertices, const Eigen::VectorXi &faces) const override
Run convex decomposition algorithm.
Definition: convex_decomposition_vhacd.cpp:37
tesseract_collision::VHACDParameters::max_num_vertices_per_ch
uint32_t max_num_vertices_per_ch
The maximum number of vertices allowed in any output convex hull.
Definition: convex_decomposition_vhacd.h:55
VHACD::IVHACD::Parameters::m_asyncACD
bool m_asyncACD
Definition: VHACD.h:405
VHACD::IVHACD
Definition: VHACD.h:315
tesseract_collision::VHACDParameters::shrinkwrap
bool shrinkwrap
Whether or not to shrinkwrap the voxel positions to the source mesh on output.
Definition: convex_decomposition_vhacd.h:51


tesseract_collision
Author(s): Levi Armstrong
autogenerated on Sun May 18 2025 03:01:52