-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathdatabase_builder.cpp
More file actions
115 lines (107 loc) · 3.34 KB
/
database_builder.cpp
File metadata and controls
115 lines (107 loc) · 3.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include <pel/database/database_creator.h>
#include <pel/database/database_io.h>
#include <pel/database/database.h>
#include <pcl/console/parse.h>
#include <string>
#include <vector>
#include <boost/algorithm/string/split.hpp>
#include <boost/algorithm/string/trim.hpp>
#include <boost/filesystem/path.hpp>
using namespace pcl::console;
bool load(false), overwrite(false);
boost::filesystem::path in_path, out_path;
boost::filesystem::path p_path;
void
show_help(char* prog_name)
{
//trim and split program name string
std::string pn = prog_name;
boost::trim(pn);
std::vector<std::string> vst;
boost::split (vst, pn, boost::is_any_of("/\\.."), boost::token_compress_on);
pn = vst.at( vst.size() -1);
print_highlight ("%s takes a path containing pcd files of objects viewes to assemble a PEL Database from them, using default or specified parameters.\n", pn.c_str());
print_highlight ("Usage:\t%s [SourceDir] [OutputDir] [Options]\n", pn.c_str());
print_highlight ("Options are:\n");
print_value ("\t-h, --help");
print_info (":\t\tShow this help screen and quit.\n");
print_value ("\t--load <path>");
print_info (":\t\tLoad a set of configuration parameters from a yaml file in <path>\n");
print_value ("\t-w");
print_info (":\t\t\tOverwrite <OutputDir> even if it already exists.\n");
}
void
parse_command_line(int argc, char* argv[])
{
if (find_switch (argc, argv, "-h") || find_switch (argc, argv, "--help"))
{
show_help(argv[0]);
exit(0);
}
if (find_switch (argc, argv, "-w"))
overwrite = true;
std::string param_path;
parse_argument (argc, argv, "--load", param_path);
p_path = param_path;
if (!boost::filesystem::exists(p_path) || !boost::filesystem::is_regular_file(p_path))
{
print_warn("Invalid path for parameters loading! Ignoring...\n");
load = false;
}
else
load=true;
in_path = argv[1];
out_path = argv[2];
if (!boost::filesystem::exists(in_path) || !boost::filesystem::is_directory(in_path))
{
print_error("Invalid path for source clouds. Cannot continue...\n");
exit(0);
}
}
////////////////////////////////////////////////////
////////////////// Main //////////////////////////
////////////////////////////////////////////////////
int
main (int argc, char *argv[])
{
//take care of command line...
if (argc <3)
{
print_error("Need at least 2 parameters: [SourceDir] and [OutputDir], in this order.\n");
show_help(argv[0]);
return(0);
}
parse_command_line(argc, argv);
//to business!
//Create an empty database and
pel::Database db;
//a creator
pel::DatabaseCreator creator;
if (load)
{
//load provided parameters instead of default ones
creator.loadParamsFromFile(p_path);
}
//be verbose
creator.setParam("verbosity", 2);
//inform user what parameters we are going to use
creator.printAllParams();
//ok, start Database creation
db = creator.create(in_path);
//go get coffee...
if (!db.isEmpty())
{
//Everything went fine, lets save the database where the user told us
//Writer object
pel::DatabaseWriter writer;
//write it!
writer.save(out_path, db, overwrite);
}
else
{
print_error("Something went wrong with Database creation, not saving it...\n");
return (0);
}
//bye
return (1);
}