-
Notifications
You must be signed in to change notification settings - Fork 1
/
CopcVerify.cpp
755 lines (673 loc) · 24.2 KB
/
CopcVerify.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
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
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
#include <iostream>
#include <fstream>
#include <deque>
#include <cstring>
#include <cmath>
#include <sstream>
#include <lazperf/Extractor.hpp>
#include <lazperf/header.hpp>
#include <lazperf/readers.hpp>
#include <lazperf/vlr.hpp>
#include "ProgramArgs.hpp"
struct Las
{
int32_t x;
int32_t y;
int32_t z;
uint16_t intensity;
uint8_t rn;
uint8_t nr;
uint8_t class_flags : 4;
uint8_t channel : 2;
uint8_t scan_dir : 1;
uint8_t eof : 1;
uint8_t classification;
uint8_t user_data;
int16_t scan_angle;
uint16_t point_source_id;
double gpstime;
uint16_t red;
uint16_t green;
uint16_t blue;
uint16_t nir;
Las(char *buf, int pdrf)
{
red = 0;
green = 0;
blue = 0;
nir = 0;
if (pdrf == 6 || pdrf == 7 || pdrf == 8)
{
memcpy(&x, buf, sizeof(x)); buf += sizeof(x);
memcpy(&y, buf, sizeof(y)); buf += sizeof(y);
memcpy(&z, buf, sizeof(y)); buf += sizeof(z);
memcpy(&intensity, buf, sizeof(intensity)); buf += sizeof(intensity);
uint8_t flags;
flags = *buf++;
rn = flags >> 4;
nr = flags & 0xF;
flags = *buf++;
class_flags = flags >> 4;
channel = (flags >> 2) & 0x3;
scan_dir = (flags >> 1) & 0x1;
eof = flags & 1;
classification = *buf++;
user_data = *buf++;
memcpy(&scan_angle, buf, sizeof(scan_angle)); buf += sizeof(scan_angle);
memcpy(&point_source_id, buf, sizeof(point_source_id)); buf += sizeof(point_source_id);
memcpy(&gpstime, buf, sizeof(gpstime)); buf += sizeof(gpstime);
if (pdrf == 7 || pdrf == 8)
{
memcpy(&red, buf, sizeof(red)); buf += sizeof(red);
memcpy(&green, buf, sizeof(green)); buf += sizeof(green);
memcpy(&blue, buf, sizeof(blue)); buf += sizeof(blue);
if (pdrf == 8)
memcpy(&nir, buf, sizeof(nir)); buf += sizeof(nir);
}
}
}
};
template<typename T>
struct Range
{
T low { (std::numeric_limits<T>::max)() };
T high { (std::numeric_limits<T>::lowest)() };
};
struct RangeCalc
{
Range<double> x;
Range<double> y;
Range<double> z;
Range<double> gpstime;
};
std::ostream& operator<<(std::ostream& out, const RangeCalc& rc)
{
out << "X: [" << rc.x.low << ", " << rc.x.high << "]\n";
out << "Y: [" << rc.y.low << ", " << rc.y.high << "]\n";
out << "Z: [" << rc.z.low << ", " << rc.z.high << "]\n";
return out;
}
struct VoxelKey
{
int depth;
int x;
int y;
int z;
operator std::string () const
{
return std::to_string(depth) + "-" + std::to_string(x) + "-" + std::to_string(y) + "-" +
std::to_string(z);
}
VoxelKey parent() const
{
return VoxelKey {depth - 1, x >> 1, y >> 1, z >> 1};
}
bool operator==(const VoxelKey& other) const
{
return depth == other.depth && x == other.x && y == other.y && z == other.z;
}
};
class Entry
{
public:
VoxelKey key;
uint64_t offset;
int32_t byteSize;
int32_t pointCount;
static const int Size = 32;
bool isChildRef() const
{ return pointCount == -1; }
static Entry create(std::istream& in)
{
Entry e;
std::vector<char> buf(Entry::Size);
in.read(buf.data(), buf.size());
lazperf::LeExtractor s(buf.data(), buf.size());
s >> e.key.depth >> e.key.x >> e.key.y >> e.key.z;
s >> e.offset >> e.byteSize >> e.pointCount;
return e;
}
};
std::ostream& operator << (std::ostream& out, const VoxelKey& k)
{
out << k.depth << "-" << k.x << "-" << k.y << "-" << k.z;
return out;
}
using Entries = std::deque<Entry>;
class Verifier
{
public:
Verifier(const std::string& filename, bool dump, bool dumpChunks);
void run();
void dumpErrors() const;
private:
void checkEbVlr(const lazperf::copc_info_vlr& vlr);
uint64_t traverseTree(const lazperf::copc_info_vlr& vlr, int chunkCount);
std::vector<char> findVlr(const std::string& user_id, int record_id);
void verifyRanges(const lazperf::copc_info_vlr& vlr);
void verifyPage(const Entries& page, const Entries& all);
void readData(Entry entry, RangeCalc extent);
Entries processPage(Entries page, const lazperf::copc_info_vlr& vlr);
Entries getHierarchyPage(uint64_t offset, uint64_t size);
int getChunkCount();
void dumpCopcVlr(const lazperf::copc_info_vlr& v);
void dumpHeader(const lazperf::header14& h);
std::string m_filename;
bool m_dump;
bool m_dumpChunks;
std::ifstream m_in;
int m_ebCount = 0;
int m_pdrf = 0;
int m_pointLength = 0;
lazperf::header14 m_header;
RangeCalc m_ext;
uint64_t m_fileSize;
std::map<int, uint64_t> m_totals;
std::map<int, uint64_t> m_counts;
std::vector<std::string> m_errors;
};
int main(int argc, char *argv[])
{
using namespace pdal;
std::string filename;
bool dump;
bool dumpChunks;
ProgramArgs args;
args.add("filename", "Filename", filename).setPositional();
args.add("dump,d", "Dump notable information", dump);
args.add("chunks,c", "Dump chunk information", dumpChunks);
std::vector<std::string> input;
for (int i = 1; i < argc; ++i)
input.push_back(argv[i]);
try
{
args.parse(input);
}
catch (const arg_error& err)
{
std::cerr << err.what() << "\n";
std::cerr << "Usage: copcverify <filename>\n";
return -1;
}
Verifier v(filename, dump, dumpChunks);
v.run();
v.dumpErrors();
}
Verifier::Verifier(const std::string& filename, bool dump, bool dumpChunks) :
m_filename(filename), m_dump(dump), m_dumpChunks(dumpChunks)
{
m_in.open(m_filename.data(), std::ios::binary | std::ios::in);
m_in.seekg(0, std::ios::end);
m_fileSize = m_in.tellg();
m_in.seekg(0);
}
void Verifier::run()
{
m_header = lazperf::header14::create(m_in);
if (!m_in)
m_errors.push_back("Stream error reading LAS header. File invalid");
if (m_dump)
dumpHeader(m_header);
std::string magic(m_header.magic, 4);
if (magic != "LASF")
m_errors.push_back("Invalid LAS magic number. Should be 'LASF'. Found '" + magic + "'.");
if (m_header.version.major != 1 || m_header.version.minor != 4)
{
std::ostringstream oss;
oss << "Invalid COPC file. Found version " <<
(int)m_header.version.major << "." << (int)m_header.version.minor <<
" instead of 1.4.";
m_errors.push_back(oss.str());
}
if (m_header.header_size != lazperf::header14::Size)
{
std::ostringstream oss;
oss << "Invalid COPC file. Found header size of " << m_header.header_size <<
" instead of " << lazperf::header14::Size << ".";
m_errors.push_back(oss.str());
}
if ((m_header.point_format_id & 0x80) == 0)
{
std::ostringstream oss;
oss << "Invalid COPC file. Compression bit (high bit) of point format ID "
"not set.\n";
m_errors.push_back(oss.str());
}
int pdrf = m_header.point_format_id & 0x7F;
if (pdrf < 6 || pdrf > 8)
{
std::ostringstream oss;
oss << "Invalid COPC file. Point format is " << pdrf << ". Should be 6, 7, or 8.";
m_errors.push_back(oss.str());
}
lazperf::vlr_header vh = lazperf::vlr_header::create(m_in);
lazperf::copc_info_vlr copcVlr = lazperf::copc_info_vlr::create(m_in);
if (m_dump)
dumpCopcVlr(copcVlr);
if (vh.user_id != "copc")
{
std::ostringstream oss;
oss << "Invalid COPC VLR header. User ID is '" << vh.user_id <<
"', not 'copc'.";
m_errors.push_back(oss.str());
}
if (vh.record_id != 1)
{
std::ostringstream oss;
oss << "Invalid COPC VLR header. Record ID is " << (int)vh.record_id << ", not 1.";
m_errors.push_back(oss.str());
}
for (int i = 0; i < 11; ++i)
if (copcVlr.reserved[i])
{
std::ostringstream oss;
oss << "Invalid COPC VLR. COPC field reserved[" << i << "] is " <<
copcVlr.reserved[i] << ", not 0.";
m_errors.push_back(oss.str());
}
int baseCount = lazperf::baseCount(m_header.point_format_id);
if (baseCount == 0)
throw "Bad point record format '" + std::to_string(m_header.point_format_id) + ".";
m_ebCount = m_header.point_record_length - baseCount;
m_pdrf = m_header.pointFormat();
m_pointLength = m_header.point_record_length;
int chunkCount = getChunkCount();
/**
checkEbVlr(copcVlr);
**/
if (m_errors.empty())
traverseTree(copcVlr, chunkCount);
if (m_dump)
{
std::cout << "Points per level:\n";
uint64_t sum = 0;
for (auto& p : m_totals)
{
sum += p.second;
std::cout << " " << p.first << ": " << p.second <<
" (" << (p.second / m_counts[p.first]) << ")\n";
}
std::cout << "Total of all levels: " << sum << "\n";
std::cout << "\n";
}
verifyRanges(copcVlr);
}
void Verifier::dumpErrors() const
{
if (m_errors.size())
{
std::cerr << "ERRORS:\n";
std::cerr << "=======\n";
}
for (const std::string& s : m_errors)
std::cerr << s << "\n";
}
int Verifier::getChunkCount()
{
uint64_t chunkoffset;
uint32_t chunkcount;
m_in.seekg(m_header.point_offset);
m_in.read((char *)&chunkoffset, sizeof(chunkoffset));
m_in.seekg(chunkoffset + 4); // The first 4 bytes are the version, then the chunk count.
m_in.read((char *)&chunkcount, sizeof(chunkcount));
if (chunkcount > (std::numeric_limits<int>::max)())
std::cout << "Chunk count in chunk table exceeds maximum expected.";
return (int)chunkcount;
}
uint64_t Verifier::traverseTree(const lazperf::copc_info_vlr& vlr, int chunkCount)
{
Entries chunkEntries;
Entries nonnegEntries;
Entries page = getHierarchyPage(vlr.root_hier_offset, vlr.root_hier_size);
// Add entries from the page to chunk entries if the point count is greater than zero.
// Chunks aren't created for empty voxels.
// Also keep track of chunk entries for all non-pointer chunks so that we can make
// sure that they're properly arranged.
std::copy_if(page.begin(), page.end(), std::back_inserter(chunkEntries),
[](const Entry& e){ return e.pointCount > 0; });
std::copy_if(page.begin(), page.end(), std::back_inserter(nonnegEntries),
[](const Entry& e){ return e.pointCount >= 0; });
verifyPage(page, nonnegEntries);
Entries pageEntries = processPage(page, vlr);
while (pageEntries.size())
{
Entry e = pageEntries.front();
pageEntries.pop_front();
Entries page = getHierarchyPage(e.offset, e.byteSize);
std::copy_if(page.begin(), page.end(), std::back_inserter(chunkEntries),
[](const Entry& e){ return e.pointCount > 0; });
std::copy_if(page.begin(), page.end(), std::back_inserter(nonnegEntries),
[](const Entry& e){ return e.pointCount >= 0; });
verifyPage(page, nonnegEntries);
Entries entries = processPage(page, vlr);
pageEntries.insert(pageEntries.end(), entries.begin(), entries.end());
}
if (chunkEntries.size() != chunkCount)
{
std::ostringstream oss;
oss << "Number of hierarchy VLR chunk entries (" << chunkEntries.size() << ") " <<
"doesn't match chunk table count (" << chunkCount << ").";
m_errors.push_back(oss.str());
}
if (m_dumpChunks)
{
std::sort(nonnegEntries.begin(), nonnegEntries.end(),
[](const Entry& e1, const Entry& e2) { return e1.offset < e2.offset; });
uint64_t total = 0;
std::cout << "Chunks:\n";
std::cout << "\tKey: Offest / Count / Byte Size / Total Count\n";
for (const Entry& e : nonnegEntries)
{
total += e.pointCount;
std::cout << "\t" << std::string(e.key) << ": " <<
e.offset << " / " << e.pointCount << " / " << e.byteSize << " / " << total << "\n";
}
std::cout << "\n";
}
uint64_t totalPoints;
for (Entry e : chunkEntries)
totalPoints += e.pointCount;
return totalPoints;
}
// Make sure that all the entries in a hierarchy page have parents in this page or one already
// read.
void Verifier::verifyPage(const Entries& page, const Entries& all)
{
auto keyExists = [&all](const VoxelKey& k)
{
for (const Entry& e : all)
if (e.key == k)
return true;
return false;
};
for (const Entry& e : page)
{
VoxelKey parent = e.key.parent();
if (parent.depth < 0)
continue;
if (!keyExists(parent))
{
std::ostringstream oss;
oss << "Hierarchy entry " << std::string(e.key) << " has no parent in "
"existing hierarchy.";
m_errors.push_back(oss.str());
}
}
}
// A page is just a list of entries.
Entries Verifier::getHierarchyPage(uint64_t offset, uint64_t size)
{
Entries page;
int numEntries = size / Entry::Size;
if (numEntries * Entry::Size != size)
m_errors.push_back("Error in hierarchy page size. Not divisible by entry size.");
m_in.seekg(offset);
while (numEntries--)
{
page.push_back(Entry::create(m_in));
Entry& e = page.back();
if (e.offset + e.byteSize > m_fileSize)
{
std::ostringstream oss;
oss << "Invalid entry - offset(" << e.offset << ") + byteSize(" <<
e.byteSize << ") is greater than file size(" << m_fileSize << ").\n";
m_errors.push_back(oss.str());
}
}
return page;
}
// Process the page and return any child pages.
Entries Verifier::processPage(Entries page, const lazperf::copc_info_vlr& vlr)
{
RangeCalc fullExtent;
fullExtent.x.low = vlr.center_x - vlr.halfsize;
fullExtent.x.high = vlr.center_x + vlr.halfsize;
fullExtent.y.low = vlr.center_y - vlr.halfsize;
fullExtent.y.high = vlr.center_y + vlr.halfsize;
fullExtent.z.low = vlr.center_z - vlr.halfsize;
fullExtent.z.high = vlr.center_z + vlr.halfsize;
Entries children;
for (Entry entry : page)
{
int cells = (int)std::pow(2, entry.key.depth);
double xwidth = (fullExtent.x.high - fullExtent.x.low) / cells;
double ywidth = (fullExtent.y.high - fullExtent.y.low) / cells;
double zwidth = (fullExtent.z.high - fullExtent.z.low) / cells;
RangeCalc extent;
extent.x.low = fullExtent.x.low + (entry.key.x * xwidth);
extent.x.high = extent.x.low + xwidth;
extent.y.low = fullExtent.y.low + (entry.key.y * xwidth);
extent.y.high = extent.y.low + xwidth;
extent.z.low = fullExtent.z.low + (entry.key.z * xwidth);
extent.z.high = extent.z.low + xwidth;
if (entry.isChildRef())
children.push_back(entry);
else
{
m_totals[entry.key.depth] += entry.pointCount;
m_counts[entry.key.depth]++;
readData(entry, extent);
}
}
return children;
}
// Read the data to make sure it decompresses.
void Verifier::readData(Entry entry, RangeCalc r)
{
// We add 1/2 the scale factor to allow for imprecision in floating-point calculations.
r.x.low -= (m_header.scale.x / 2);
r.x.high += (m_header.scale.x / 2);
r.y.low -= (m_header.scale.y / 2);
r.y.high += (m_header.scale.y / 2);
r.z.low -= (m_header.scale.z / 2);
r.z.high += (m_header.scale.z / 2);
std::vector<char> buf(entry.byteSize);
m_in.seekg(entry.offset);
m_in.read(buf.data(), buf.size());
lazperf::reader::chunk_decompressor d(m_pdrf, m_ebCount, buf.data());
bool outOfRange = false;
std::vector<char> pointbuf(m_header.point_record_length);
while (entry.pointCount--)
{
d.decompress(pointbuf.data());
Las l(pointbuf.data(), m_pdrf);
double x = (l.x * m_header.scale.x) + m_header.offset.x;
m_ext.x.high = (std::max)(x, m_ext.x.high);
m_ext.x.low = (std::min)(x, m_ext.x.low);
double y = (l.y * m_header.scale.y) + m_header.offset.y;
m_ext.y.high = (std::max)(y, m_ext.y.high);
m_ext.y.low = (std::min)(y, m_ext.y.low);
double z = (l.z * m_header.scale.z) + m_header.offset.z;
m_ext.z.high = (std::max)(z, m_ext.z.high);
m_ext.z.low = (std::min)(z, m_ext.z.low);
m_ext.gpstime.high = (std::max)(l.gpstime, m_ext.gpstime.high);
m_ext.gpstime.low = (std::min)(l.gpstime, m_ext.gpstime.low);
outOfRange |= (x < r.x.low) || (x >= r.x.high) || (y < r.y.low) ||
(y >= r.y.high) || (z < r.z.low) || (z >= r.z.high);
}
if (outOfRange)
{
std::ostringstream oss;
oss << "Node " << entry.key << " contains out of range points.\n";
m_errors.push_back(oss.str());
}
}
void Verifier::verifyRanges(const lazperf::copc_info_vlr& copcVlr)
{
// Perhaps we should hardcode epsilon
auto closeEnough = [](double a, double b, float epsilon)
{
using namespace std;
return fabs(a - b) <= ( (fabs(a) < fabs(b) ? fabs(b) : fabs(a)) * epsilon);
};
std::ostringstream oss;
oss << std::setprecision(17);
if (!closeEnough(m_ext.x.low, m_header.minx, .0000001))
{
oss << "Minimum X value of " << m_ext.x.low << " doesn't match header minimum of " <<
m_header.minx << ".";
m_errors.push_back(oss.str());
oss.str("");
}
if (!closeEnough(m_ext.x.high, m_header.maxx, .0000001))
{
oss << "Maximum X value of " << m_ext.x.high << " doesn't match header maximum of " <<
m_header.maxx << ".";
m_errors.push_back(oss.str());
oss.str("");
}
if (!closeEnough(m_ext.y.low, m_header.miny, .0000001))
{
oss << "Minimum Y value of " << m_ext.y.low << " doesn't match header minimum of " <<
m_header.miny << ".";
m_errors.push_back(oss.str());
oss.str("");
}
if (!closeEnough(m_ext.y.high, m_header.maxy, .0000001))
{
oss << "Maximum Y value of " << m_ext.y.high << " doesn't match header maximum of " <<
m_header.maxy << ".";
m_errors.push_back(oss.str());
oss.str("");
}
if (!closeEnough(m_ext.z.low, m_header.minz, .0000001))
{
oss << "Minimum Z value of " << m_ext.z.low << " doesn't match header minimum of " <<
m_header.minz << ".";
m_errors.push_back(oss.str());
oss.str("");
}
if (!closeEnough(m_ext.z.high, m_header.maxz, .0000001))
{
oss << "Maximum Z value of " << m_ext.z.high << " doesn't match header maximum of " <<
m_header.maxz << ".";
m_errors.push_back(oss.str());
oss.str("");
}
if (!closeEnough(m_ext.gpstime.low, copcVlr.gpstime_minimum, .0000001))
{
oss << "Minimum GPS time value of " << m_ext.gpstime.low <<
" doesn't match COPC VLR minimum of " << copcVlr.gpstime_minimum << ".";
m_errors.push_back(oss.str());
oss.str("");
}
if (!closeEnough(m_ext.gpstime.high, copcVlr.gpstime_maximum, .0000001))
{
oss << "Maximum GPS time value of " << m_ext.gpstime.high <<
" doesn't match COPC VLR maximum of " << copcVlr.gpstime_maximum << ".";
m_errors.push_back(oss.str());
oss.str("");
}
}
std::vector<char> Verifier::findVlr(const std::string& user_id, int record_id)
{
std::vector<char> buf;
m_in.seekg(m_header.header_size);
int count = 0;
while (count < m_header.vlr_count && m_in.good() && !m_in.eof())
{
lazperf::vlr_header h = lazperf::vlr_header::create(m_in);
if (h.user_id == user_id && h.record_id == record_id)
{
buf.resize(h.data_length);
m_in.read(buf.data(), h.data_length);
return buf;
}
m_in.seekg(h.data_length, std::ios::cur);
count++;
}
if (m_header.evlr_count == 0 || m_header.evlr_offset == 0)
return buf;
m_in.seekg(m_header.evlr_offset);
count = 0;
while (count < m_header.evlr_count && m_in.good() && !m_in.eof())
{
lazperf::evlr_header h = lazperf::evlr_header::create(m_in);
if (h.user_id == user_id && h.record_id == record_id)
{
buf.resize(h.data_length);
m_in.read(buf.data(), h.data_length);
return buf;
}
m_in.seekg(h.data_length, std::ios::cur);
count++;
}
return buf;
}
void Verifier::dumpCopcVlr(const lazperf::copc_info_vlr& v)
{
std::cout << "COPC VLR:\n";
std::cout << "\tCenter X Y Z: " << v.center_x << " " << v.center_y << " " << v.center_z << "\n";
std::cout << "\tRoot node halfsize: " << v.halfsize << "\n";
std::cout << "\tRoot node point spacing: " << v.spacing << "\n";
std::cout << "\tGPS time min/max = " << v.gpstime_minimum << "/" << v.gpstime_maximum << "\n";
std::cout << "\n";
}
void Verifier::dumpHeader(const lazperf::header14& h)
{
std::cout << "LAS Header:\n";
std::cout << "\tFile source ID: " << h.file_source_id << "\n";
std::cout << "\tGlobal encoding: " << h.global_encoding << "\n";
std::cout << "\t\tTime representation: " <<
((h.global_encoding & 0x01) ? "GPS Satellite Time" : "GPS Week Time") << "\n";
std::cout << "\t\tSRS Type: " <<
((h.global_encoding & 0x10) ? "WKT" : "GeoTIFF") << "\n";
std::cout << "\tVersion: " << (int)h.version.major << "." << (int)h.version.minor << "\n";
std::cout << "\tSystem ID: " << h.system_identifier << "\n";
std::cout << "\tSoftware ID: " << h.generating_software << "\n";
std::cout << "\tCreation day/year: " << h.creation.day << " / " << h.creation.year << "\n";
std::cout << "\tHeader Size: " << h.header_size << "\n";
std::cout << "\tPoint Offset: " << h.point_offset << "\n";
std::cout << "\tVLR Count: " << h.vlr_count << "\n";
std::cout << "\tEVLR Count: " << h.evlr_count << "\n";
std::cout << "\tEVLR Offset: " << h.evlr_offset << "\n";
std::cout << "\tPoint Format: " << (h.point_format_id & 0xF) << "\n";
std::cout << "\tPoint Length: " << h.point_record_length << "\n";
std::cout << "\tNumber of Points old/1.4: " <<
h.point_count << " / " << h.point_count_14 << "\n";
std::cout << std::fixed;
std::cout << "\tScale X Y Z: " << h.scale.x << " " << h.scale.y << " " << h.scale.z << "\n";
std::cout << "\tOffset X Y Z: " << h.offset.x << " " << h.offset.y << " " << h.offset.z << "\n";
std::cout << "\tMin X Y Z: " << h.minx << " " << h.miny << " " << h.minz << "\n";
std::cout << "\tMax X Y Z: " << h.maxx << " " << h.maxy << " " << h.maxz << "\n";
std::cout << std::defaultfloat;
std::cout << "\tPoint Counts by Return: ";
for (int i = 0; i < 5; ++i)
std::cout << h.points_by_return[i] << " ";
std::cout << "\n";
std::cout << "\tExt Point Counts by Return: ";
for (int i = 0; i < 15; ++i)
std::cout << h.points_by_return_14[i] << " ";
std::cout << "\n\n";
}
/**
void Verifier::checkEbVlr(const lazperf::copc_info_vlr& copcVlr)
{
if (copcVlr.eb_vlr_offset == 0)
return;
uint64_t baseOffset = lazperf::header14::Size + lazperf::laz_vlr::Size + copcVlr.size();
if (copcVlr.eb_vlr_offset < baseOffset)
{
std::ostringstream oss;
oss << "Invalid COPC VLR. Offset to extra bytes VLR, " << copcVlr.eb_vlr_offset <<
", is too small. Should be at least " << baseOffset << ".\n";
m_errors.push_back(oss.str());
}
uint64_t offset = copcVlr.eb_vlr_offset - lazperf::vlr_header::Size;
m_in.seekg(offset);
lazperf::vlr_header vh = lazperf::vlr_header::create(m_in);
if (vh.user_id != "LASF_Spec")
{
std::ostringstream oss;
oss << "Invalid COPC VLR or extra bytes VLR. Found user ID of '" << vh.user_id <<
". Expected 'LASF_Spec'.\n";
m_errors.push_back(oss.str());
}
if (vh.record_id != 4)
std::cerr << "Invalid COPC VLR or extra bytes VLR. Found record ID of '" << vh.record_id <<
"'. Expected '4'.\n";
lazperf::eb_vlr ebVlr = lazperf::eb_vlr::create(m_in);
if (vlr.eb_vlr_size & 192)
...
}
**/