2323#include < iostream>
2424#include < string>
2525
26+ #include " argparse/argparse.hpp"
2627#include " cloudparse/parser.hpp"
2728
28- void printUsage (const char * progName) { std::cout << " \n Use: " << progName << " <file>" << std::endl << " support: .pcd .ply .txt .xyz" << std::endl << " [q] to exit" << std::endl; }
29+ // void printUsage(const char* progName) { std::cout << "\nUse: " << progName << " <file>" << std::endl << "support:
30+ // .pcd .ply .txt .xyz" << std::endl << "[q] to exit" << std::endl; }
2931
3032int main (int argc, char ** argv) {
31- if (argc < 2 or argc > 2 ) {
32- printUsage (argv[0 ]);
33- return -1 ;
33+ // -----------------Command line interface -----------------
34+ argparse::ArgumentParser arg_parser (argv[0 ]);
35+
36+ arg_parser.add_argument (" --cloudfile" ).required ().help (" input cloud file" );
37+ arg_parser.add_argument (" --search-radius" ).default_value (double (0.03 )).scan <' g' , double >().help (" epsilon value" );
38+ arg_parser.add_argument (" --sampling-radius" ).default_value (double (0.005 )).scan <' g' , double >().help (" epsilon value" );
39+ arg_parser.add_argument (" --step-size" ).default_value (double (0.005 )).scan <' g' , double >().help (" epsilon value" );
40+ arg_parser.add_argument (" -o" , " --output-dir" ).default_value (std::string (" -" )).help (" output dir to save clusters" );
41+ arg_parser.add_argument (" -d" , " --display" )
42+ .default_value (false )
43+ .implicit_value (true )
44+ .help (" display clusters in the pcl visualizer" );
45+
46+ try {
47+ arg_parser.parse_args (argc, argv);
48+ } catch (const std::runtime_error& err) {
49+ std::cerr << err.what () << std::endl;
50+ std::cerr << arg_parser;
51+ std::exit (0 );
3452 }
3553
3654 // -----------------Read input cloud file -----------------
3755 pcl::PointCloud<pcl::PointXYZRGB>::Ptr input_cloud (new pcl::PointCloud<pcl::PointXYZRGB>());
3856
3957 // cloud parser object
4058 CloudParserLibrary::ParserCloudFile cloud_parser;
41- cloud_parser.load_cloudfile (argv[ 1 ] , input_cloud);
59+ cloud_parser.load_cloudfile (arg_parser. get <std::string>( " --cloudfile " ) , input_cloud);
4260
4361 // set cloud metadata
4462 input_cloud->width = (int )input_cloud->points .size ();
4563 input_cloud->height = 1 ;
4664 input_cloud->is_dense = true ;
4765
48- pcl::PointCloud<pcl::PointXYZRGB>::Ptr output_cloud (new pcl::PointCloud<pcl::PointXYZRGB>());
4966 pcl::PointCloud<pcl::PointXYZRGB>::Ptr dense_points (new pcl::PointCloud<pcl::PointXYZRGB>());
5067
5168 pcl::search::KdTree<pcl::PointXYZRGB>::Ptr kd_tree (new pcl::search::KdTree<pcl::PointXYZRGB>);
52- pcl::PointCloud<pcl::PointNormal>::Ptr mls_points (new pcl::PointCloud<pcl::PointNormal>());
69+ // pcl::PointCloud<pcl::PointNormal>::Ptr mls_points(new pcl::PointCloud<pcl::PointNormal>());
5370 pcl::MovingLeastSquares<pcl::PointXYZRGB, pcl::PointXYZRGB> mls;
5471
55- double search_radius = 0.03 ; // 0.03
56- double sampling_radius = 0.005 ; // 0.005
57- double step_size = 0.005 ; // 0.005
72+ double search_radius = arg_parser. get < double >( " --search-radius " ); // 0.03
73+ double sampling_radius = arg_parser. get < double >( " --sampling-radius " ) ; // 0.005
74+ double step_size = arg_parser. get < double >( " --step-size " ); // 0.005
5875 double gauss_param = (double )std::pow (search_radius, 2 );
5976 int pol_order = 2 ;
6077 unsigned int num_threats = 1 ;
@@ -63,7 +80,8 @@ int main(int argc, char** argv) {
6380 mls.setInputCloud (input_cloud);
6481 mls.setSearchMethod (kd_tree);
6582 mls.setSearchRadius (search_radius);
66- mls.setUpsamplingMethod (pcl::MovingLeastSquares<pcl::PointXYZRGB, pcl::PointXYZRGB>::UpsamplingMethod::SAMPLE_LOCAL_PLANE);
83+ mls.setUpsamplingMethod (
84+ pcl::MovingLeastSquares<pcl::PointXYZRGB, pcl::PointXYZRGB>::UpsamplingMethod::SAMPLE_LOCAL_PLANE);
6785 mls.setUpsamplingRadius (sampling_radius);
6886 mls.setUpsamplingStepSize (step_size);
6987 mls.setPolynomialOrder (pol_order);
@@ -74,6 +92,8 @@ int main(int argc, char** argv) {
7492 // mls.setPointDensity(15); //15
7593 mls.process (*dense_points);
7694
95+ pcl::PointCloud<pcl::PointXYZRGB>::Ptr output_cloud (new pcl::PointCloud<pcl::PointXYZRGB>());
96+
7797 *output_cloud = *input_cloud;
7898 *output_cloud += *dense_points;
7999
0 commit comments