-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnodes.cpp
192 lines (155 loc) · 5.72 KB
/
nodes.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
#include <memory>
#include <pdal/PointTable.hpp>
#include <pdal/PointView.hpp>
#include <pdal/Options.hpp>
#include <pdal/filters/DecimationFilter.hpp>
#include <pdal/filters/RangeFilter.hpp>
#include <pdal/io/EptReader.hpp>
#include <iomanip>
#include "nodes.hpp"
#if defined(__cplusplus) && __cplusplus >= 201703L && defined(__has_include)
#if __has_include(<filesystem>)
#define GHC_USE_STD_FS
#include <filesystem>
namespace fs = std::filesystem;
#endif
#endif
#ifndef GHC_USE_STD_FS
#include <ghc/filesystem.hpp>
namespace fs = ghc::filesystem;
#endif
namespace geoflow::nodes::gfpdal {
void EptLoaderNode::process(){
PointCollection points;
vec1i classification;
vec1f intensity;
vec1f order;
vec3f colors;
pdal::EptReader reader;
{
pdal::Options options;
options.add("filename", "ept://" + dirpath);
reader.setOptions(options);
}
// Give quick overview of the EPT data in the console
const pdal::QuickInfo qi(reader.preview());
std::cout << std::endl << "EPT Bounds:\t" << qi.m_bounds << std::endl;
std::cout << "EPT Point Count:\t" << qi.m_pointCount << std::endl;
std::cout << "EPT WKT:\t" << qi.m_srs.getWKT() << std::endl;
// Keep every Nth (step) point. If filter_step == 1 then keep all points.
pdal::DecimationFilter filterDecimation;
pdal::Options decimationOps;
decimationOps.add("step", filter_step);
filterDecimation.setOptions(decimationOps);
filterDecimation.setInput(reader);
// Range filter. See https://pdal.io/stages/filters.range.html
pdal::RangeFilter filter;
bool has_range = filter_limits.length() > 0;
if (has_range) {
// Range filter
pdal::Options rangeOps;
rangeOps.add("limits", filter_limits);
filter.setOptions(rangeOps);
filter.setInput(filterDecimation);
// Reading the points now.
pdal::PointTable eptTable;
filter.prepare(eptTable);
const auto set(filter.execute(eptTable));
// The PointViews contain the actual data, there is a 1-to-1 relationship
// to the LAZ files of the octree
double x, y, z;
float r, g, b;
uint64_t o;
uint64_t np(0);
bool found_offset = manager.data_offset.has_value();
for (const pdal::PointViewPtr& view : set)
{
for (pdal::point_count_t i(0); i < view->size(); ++i)
{
++np;
r = view->getFieldAs<float>(pdal::Dimension::Id::Red, i);
g = view->getFieldAs<float>(pdal::Dimension::Id::Green, i);
b = view->getFieldAs<float>(pdal::Dimension::Id::Blue, i);
x = view->getFieldAs<double>(pdal::Dimension::Id::X, i);
y = view->getFieldAs<double>(pdal::Dimension::Id::Y, i);
z = view->getFieldAs<double>(pdal::Dimension::Id::Z, i);
// TODO: Is this the equivalent of 'order' in the LAS reader plugin?
o = view->getFieldAs<uint64_t>(pdal::Dimension::Id::OriginId, i);
order.push_back(float(o)/1000);
points.push_back({
float(x - (*manager.data_offset)[0]),
float(y - (*manager.data_offset)[1]),
float(z - (*manager.data_offset)[2])}
);
colors.push_back({
r/65535,
g/65535,
b/65535
});
classification.push_back(
view->getFieldAs<int>(pdal::Dimension::Id::Classification, i)
);
intensity.push_back(
view->getFieldAs<float>(pdal::Dimension::Id::Intensity, i)
);
}
}
std::cout << "Read " << np << " points" << std::endl;
} else {
// TODO: ugly duplicate code here, but I don't know how to construct and
// then exectue a pipleline.
std::cout << "Not using the range filter" << std::endl;
// Reading the points now.
pdal::PointTable eptTable;
filterDecimation.prepare(eptTable);
const auto set(filterDecimation.execute(eptTable));
// The PointViews contain the actual data, there is a 1-to-1 relationship
// to the LAZ files of the octree
double x, y, z;
float r, g, b;
uint64_t o;
uint64_t np(0);
bool found_offset = manager.data_offset.has_value();
for (const pdal::PointViewPtr& view : set)
{
for (pdal::point_count_t i(0); i < view->size(); ++i)
{
++np;
r = view->getFieldAs<float>(pdal::Dimension::Id::Red, i);
g = view->getFieldAs<float>(pdal::Dimension::Id::Green, i);
b = view->getFieldAs<float>(pdal::Dimension::Id::Blue, i);
x = view->getFieldAs<double>(pdal::Dimension::Id::X, i);
y = view->getFieldAs<double>(pdal::Dimension::Id::Y, i);
z = view->getFieldAs<double>(pdal::Dimension::Id::Z, i);
// TODO: Is this the equivalent of 'order' in the LAS reader plugin?
o = view->getFieldAs<uint64_t>(pdal::Dimension::Id::OriginId, i);
order.push_back(float(o)/1000);
points.push_back({
float(x - (*manager.data_offset)[0]),
float(y - (*manager.data_offset)[1]),
float(z - (*manager.data_offset)[2])}
);
colors.push_back({
r/65535,
g/65535,
b/65535
});
classification.push_back(
view->getFieldAs<int>(pdal::Dimension::Id::Classification, i)
);
intensity.push_back(
view->getFieldAs<float>(pdal::Dimension::Id::Intensity, i)
);
}
}
std::cout << "Read " << np << " points" << std::endl;
}
output("points").set(points);
output("colors").set(colors);
output("classification").set(classification);
output("intensity").set(intensity);
output("order").set(order);
}
void EptVecLoaderNode::process(){
}
}