-
Notifications
You must be signed in to change notification settings - Fork 0
/
scan2ascii.cpp
167 lines (132 loc) · 4.53 KB
/
scan2ascii.cpp
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/*************************************************************
Generalized-ICP Copyright (c) 2009 Aleksandr Segal.
All rights reserved.
Redistribution and use in source and binary forms, with
or without modification, are permitted provided that the
following conditions are met:
* Redistributions of source code must retain the above
copyright notice, this list of conditions and the
following disclaimer.
* Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the
following disclaimer in the documentation and/or other
materials provided with the distribution.
* The names of the contributors may not be used to endorse
or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.
*************************************************************/
#include <iostream>
#include <fstream>
#include <string>
#include <sstream>
// program options
#include <boost/program_options.hpp>
#include <boost/filesystem/path.hpp>
#include <boost/filesystem/fstream.hpp>
#include <boost/tokenizer.hpp>
#include "scan.h"
#include "transform.h"
using namespace std;
namespace po = boost::program_options;
static string filename_in;
static string filename_out;
static string filename_tfm_out;
void print_usage(const char* program_name, po::options_description const& desc) {
cout << program_name << " scan_in [scan_out]" << endl;
cout << desc << endl;
}
bool parse_options(int argc, char** argv) {
bool error = false;
po::options_description desc("Allowed options");
desc.add_options()
("help", "print help message")
("scan_in", po::value<string>(), "input scan filename")
("scan_out", po::value<string>(), "output scan filename");
po::positional_options_description p;
p.add("scan_in", 1);
p.add("scan_out", 1);
po::variables_map vm;
try {
po::store(po::command_line_parser(argc, argv).options(desc).positional(p).run(), vm);
po::notify(vm);
}
catch(const std::exception &e) {
cout << "Error: " << e.what() << endl;
print_usage(argv[0], desc);
error = true;
return error;
}
if(vm.count("help")) {
print_usage(argv[0], desc);
error = true;
return error;
}
if(!vm.count("scan_in")) {
cout << "Error: scan_in filename not specified!" << endl;
error = true;
}
else {
filename_in = vm["scan_in"].as<string>();
}
if(!vm.count("scan_out")) {
filename_out = filename_in;
int dot_pos = filename_out.find_last_of(".");
if(dot_pos != -1) {
filename_out = filename_out.substr(0, dot_pos);
}
filename_out += ".ascii";
}
else {
filename_out = vm["scan_out"].as<string>();
}
filename_tfm_out = filename_out;
int dot_pos = filename_tfm_out.find_last_of(".");
if(dot_pos != -1) {
filename_tfm_out = filename_tfm_out.substr(0, dot_pos);
}
filename_tfm_out += ".tfm";
return error;
}
int main(int argc, char** argv) {
bool error;
error = parse_options(argc, argv);
if(error) {
return 1;
}
dgc_scan_t scan;
scan.load(filename_in.c_str());
ofstream fout(filename_out.c_str());
if(!fout) {
cout << "Error: could not open output file " << filename_out << endl;
return 1;
}
for(int i = 0; i < scan.points.size(); i++) {
fout << scan.points[i].vec[0] << "\t";
fout << scan.points[i].vec[1] << "\t";
fout << scan.points[i].vec[2] << endl;;
}
dgc_transform_t pose_tfm;
dgc_transform_identity(pose_tfm);
dgc_transform_rotate_x(pose_tfm, scan.pose.roll);
dgc_transform_rotate_y(pose_tfm, scan.pose.pitch);
dgc_transform_rotate_z(pose_tfm, scan.pose.yaw);
dgc_transform_translate(pose_tfm, scan.pose.x, scan.pose.y, scan.pose.z);
dgc_transform_write(pose_tfm, filename_tfm_out.c_str());
fout.close();
return 0;
}