28 #include <console_bridge/console.h>
29 #include <boost/program_options.hpp>
49 if (value < min || value > max)
52 ss <<
"Value " << value <<
" is not in valid range [" << min <<
", " << max <<
"]";
53 throw std::runtime_error(ss.str());
57 int main(
int argc,
char** argv)
64 namespace po = boost::program_options;
65 po::options_description desc(
"Options");
73 po::value<std::string>(&input)->required(),
74 "File path to mesh used to create a convex hull."
78 po::value<std::string>(&output)->required(),
79 "File path to save the generated convex hull as a ply."
84 "Maximum number of convex hulls"
88 po::value<unsigned>(&(params.
resolution))->notifier([](
const unsigned& val){
check_range(val, 1u, std::numeric_limits<unsigned>::max());}),
89 "Number of voxels to use to represent the shape"
92 "min_volume_percent_error,e",
94 "If the voxels are within this threshold percentage of the volume of the hull, we consider this a close enough approximation"
97 "max_recursion_depth,d",
99 "Maximum recursion depth for convex decomposition improvement"
104 "Shrinkwrap the voxel positions to the source mesh on output"
107 "max_num_vertices,v",
109 "Maximum number of vertices per convex hull"
113 po::value<unsigned>(&(params.
min_edge_length))->notifier([](
const unsigned& val){
check_range(val, 1u, std::numeric_limits<unsigned>::max());}),
114 "Once a voxel patch has an edge length of less than this value in all 3 dimensions, stop recursing"
119 "Flag for attempting to split planes along best location (experimental)"
123 po::variables_map vm;
126 po::store(po::parse_command_line(argc, argv, desc), vm);
129 if (vm.count(
"help") != 0U)
131 std::cout <<
"Basic Command Line Parameter App\n" << desc <<
"\n";
140 std::cerr <<
"ERROR: " << e.what() <<
"\n\n";
141 std::cerr << desc <<
"\n";
145 std::ifstream file(input, std::ios::binary | std::ios::ate);
146 std::streamsize size = file.tellg();
149 CONSOLE_BRIDGE_logError(
"Failed to locate input file!");
154 Eigen::VectorXi mesh_faces;
158 CONSOLE_BRIDGE_logError(
"Failed to read mesh from file!");
163 std::vector<std::shared_ptr<tesseract_geometry::ConvexMesh>> convex_hulls =
164 convex_decomp.
compute(mesh_vertices, mesh_faces);
166 if (convex_hulls.empty())
168 CONSOLE_BRIDGE_logError(
"Failed to create convex decomposition!");
172 for (std::size_t i = 0; i < convex_hulls.size(); ++i)
174 auto ch = convex_hulls[i];
176 std::to_string(i) +
"_" + output, *(ch->getVertices()), *(ch->getFaces()), ch->getFaceCount()))
178 CONSOLE_BRIDGE_logError(
"Failed to write convex hull to file!");