-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpcequal.cpp
More file actions
315 lines (236 loc) · 8.65 KB
/
Copy pathpcequal.cpp
File metadata and controls
315 lines (236 loc) · 8.65 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
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
/******************************************************************************
* Copyright (c) 2012, Howard Butler (hobu.inc@gmail.com)
*
* 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.
* * Neither the name of Hobu, Inc. or Flaxen Geo Consulting nor the
* names of its contributors may 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 <boost/scoped_ptr.hpp>
#include <pdal/Stage.hpp>
#include <pdal/StageIterator.hpp>
#include <pdal/FileUtils.hpp>
#include <pdal/PointBuffer.hpp>
#include <boost/property_tree/xml_parser.hpp>
#include <boost/property_tree/json_parser.hpp>
#include "AppSupport.hpp"
#include "Application.hpp"
#include <cstdarg>
#include <map>
#include <vector>
using namespace pdal;
class Point
{
public:
double x;
double y;
double z;
boost::uint64_t id;
bool equal(Point const& other)
{
return (Utils::compare_distance(x, other.x) &&
Utils::compare_distance(y, other.y) &&
Utils::compare_distance(z, other.z));
}
bool operator==(Point const& other)
{
return equal(other);
}
bool operator!=(Point const& other)
{
return !equal(other);
}
};
class PcEqual : public Application
{
public:
PcEqual(int argc, char* argv[]);
int execute(); // overrride
private:
void addSwitches(); // overrride
void validateSwitches(); // overrride
void readPoints( StageSequentialIterator* iter,
PointBuffer& data);
std::string m_sourceFile;
std::string m_candidateFile;
std::string m_wkt;
std::ostream* m_outputStream;
std::string m_outputFileName;
bool m_3d;
};
PcEqual::PcEqual(int argc, char* argv[])
: Application(argc, argv, "pcquery")
, m_sourceFile("")
, m_candidateFile("")
, m_outputStream(0)
, m_outputFileName("")
, m_3d(true)
{
return;
}
void PcEqual::validateSwitches()
{
m_chunkSize = 1048576;
return;
}
void PcEqual::addSwitches()
{
namespace po = boost::program_options;
po::options_description* file_options = new po::options_description("file options");
file_options->add_options()
("source", po::value<std::string>(&m_sourceFile), "source file name")
("candidate", po::value<std::string>(&m_candidateFile), "candidate file name")
("output", po::value<std::string>(&m_outputFileName), "output file name")
("2d", po::value<bool>(&m_3d)->zero_tokens()->implicit_value(false), "only 2D comparisons/indexing")
;
addSwitchSet(file_options);
po::options_description* processing_options = new po::options_description("processing options");
processing_options->add_options()
;
addSwitchSet(processing_options);
addPositionalSwitch("source", 1);
addPositionalSwitch("candidate", 2);
addPositionalSwitch("output", 3);
return;
}
void PcEqual::readPoints( StageSequentialIterator* iter,
PointBuffer& data)
{
while (!iter->atEnd())
{
const boost::uint32_t numRead = iter->read(data);
}
}
std::ostream& writeHeader(std::ostream& strm, bool b3D)
{
strm << "\"ID\",\"DeltaX\",\"DeltaY\"";
if (b3D)
strm << ",\"DeltaZ\"";
strm << std::endl;
return strm;
}
int PcEqual::execute()
{
Options sourceOptions;
{
sourceOptions.add<std::string>("filename", m_sourceFile);
sourceOptions.add<bool>("debug", isDebug());
sourceOptions.add<boost::uint32_t>("verbose", getVerboseLevel());
}
Stage* source = AppSupport::makeReader(sourceOptions);
source->initialize();
PointBuffer source_data(source->getSchema(), m_chunkSize);
StageSequentialIterator* source_iter = source->createSequentialIterator(source_data);
readPoints(source_iter, source_data);
delete source_iter;
delete source;
Options candidateOptions;
{
candidateOptions.add<std::string>("filename", m_candidateFile);
candidateOptions.add<bool>("debug", isDebug());
candidateOptions.add<boost::uint32_t>("verbose", getVerboseLevel());
}
Stage* candidate = AppSupport::makeReader(candidateOptions);
// pdal::filters::Index* index_filter = new pdal::filters::Index(*candidate, candidateOptions);
candidate->initialize();
IndexedPointBuffer candidate_data(candidate->getSchema(), m_chunkSize);
StageSequentialIterator* candidate_iter = candidate->createSequentialIterator(candidate_data);
readPoints(candidate_iter, candidate_data);
delete candidate_iter;
if (source_data.getNumPoints() != candidate_data.getNumPoints())
{
std::cerr << "Source and candidate files do not have the same point count, testing each source point only!";
}
Schema const& candidate_schema = candidate_data.getSchema();
Dimension const& cDimX = candidate_schema.getDimension("X");
Dimension const& cDimY = candidate_schema.getDimension("Y");
Dimension const& cDimZ = candidate_schema.getDimension("Z");
Schema const& source_schema = source_data.getSchema();
Dimension const& sDimX = source_schema.getDimension("X");
Dimension const& sDimY = source_schema.getDimension("Y");
Dimension const& sDimZ = source_schema.getDimension("Z");
bool bWroteHeader(false);
if (m_outputFileName.size())
{
m_outputStream = FileUtils::createFile(m_outputFileName);
}
std::ostream& ostr = m_outputStream ? *m_outputStream : std::cout;
candidate_data.build(m_3d);
for (boost::uint32_t i = 0; i < source_data.getNumPoints(); ++i)
{
double sx = source_data.applyScaling(sDimX, i);
double sy = source_data.applyScaling(sDimY, i);
double sz = source_data.applyScaling(sDimZ, i);
std::vector<std::size_t> ids = candidate_data.neighbors(sx, sy, sz, 1);
if (!ids.size())
{
std::ostringstream oss;
oss << "unable to find point for id '" << i <<"'";
throw app_runtime_error(oss.str() );
}
std::size_t id = ids[0];
double cx = candidate_data.applyScaling(cDimX, id);
double cy = candidate_data.applyScaling(cDimY, id);
double cz = candidate_data.applyScaling(cDimZ, id);
double xd = sx - cx;
double yd = sy - cy;
double zd = sz - cz;
if (!bWroteHeader)
{
writeHeader(ostr, m_3d);
bWroteHeader = true;
}
ostr << i << ",";
boost::uint32_t precision = Utils::getStreamPrecision(cDimX.getNumericScale());
ostr.setf(std::ios_base::fixed, std::ios_base::floatfield);
ostr.precision(precision);
ostr << xd << ",";
precision = Utils::getStreamPrecision(cDimY.getNumericScale());
ostr.precision(precision);
ostr << yd;
if (m_3d)
{
ostr << ",";
precision = Utils::getStreamPrecision(cDimZ.getNumericScale());
ostr.precision(precision);
ostr << zd;
}
ostr << std::endl;
}
if (m_outputStream)
{
FileUtils::closeFile(m_outputStream);
}
return 0;
}
int main(int argc, char* argv[])
{
PcEqual app(argc, argv);
return app.run();
}