Skip to content

Commit 32da278

Browse files
author
Daniel
authored
Merge pull request #3 from danielTobon43/feat/argparse
Feat/argparse
2 parents 1000d3b + dc4b536 commit 32da278

File tree

3 files changed

+38
-12
lines changed

3 files changed

+38
-12
lines changed

.clang-format

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
BasedOnStyle: Google
2-
ColumnLimit: 180
2+
ColumnLimit: 120

CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ fetch_project(
4141
URL https://github.com/danielTobon43/cloudparse/archive/v0.2.1.tar.gz
4242
)
4343

44+
fetch_project(
45+
NAME argparse
46+
URL https://github.com/p-ranav/argparse/archive/v2.6.tar.gz
47+
)
48+
4449
# #############################################################################
4550
# SOURCE CODE
4651
# #############################################################################
@@ -64,6 +69,7 @@ target_include_directories(${PROJECT_NAME} PRIVATE
6469
target_link_libraries(${PROJECT_NAME} PRIVATE
6570
${PCL_LIBRARIES}
6671
cloudparse
72+
argparse
6773
)
6874

6975
# #############################################################################

src/main.cpp

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,38 +23,55 @@
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 << "\nUse: " << 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

3032
int 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

Comments
 (0)