MCPcopy Create free account
hub / github.com/PDAL/PDAL / filter

Method filter

filters/HagNnFilter.cpp:127–203  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

125
126
127void HagNnFilter::filter(PointView& view)
128{
129 using namespace pdal::Dimension;
130
131 PointViewPtr gView = view.makeNew();
132 PointViewPtr ngView = view.makeNew();
133
134 // Separate into ground and non-ground views.
135 for (PointId i = 0; i < view.size(); ++i)
136 {
137 if (view.getFieldAs<uint8_t>(Id::Classification, i) ==
138 m_class)
139 {
140 view.setField(Id::HeightAboveGround, i, 0);
141 gView->appendPoint(view, i);
142 }
143 else
144 ngView->appendPoint(view, i);
145 }
146 BOX2D gBounds;
147 gView->calculateBounds(gBounds);
148
149 // Bail if there weren't any points classified as ground.
150 if (gView->size() == 0) {
151 log()->get(LogLevel::Error) << "Input PointView does not have "
152 "any points classified as ground.\n";
153 return;
154 }
155
156 // Build the 2D KD-tree.
157 const KD2Index& kdi = gView->build2dIndex();
158
159 double maxDistance2 = std::pow(m_maxDistance, 2.0);
160 // Find Z difference between non-ground points and the nearest
161 // neighbor (2D) in the ground view or between non-ground points and the
162 // locally-computed surface.
163 for (PointId i = 0; i < ngView->size(); ++i)
164 {
165 PointRef point = ngView->point(i);
166
167 // Non-ground view point for which we're trying to calc HAG
168 double x0 = point.getFieldAs<double>(Id::X);
169 double y0 = point.getFieldAs<double>(Id::Y);
170 double z0 = point.getFieldAs<double>(Id::Z);
171
172 PointIdList ids(m_count);
173 std::vector<double> sqr_dists(m_count);
174 kdi.knnSearch(x0, y0, m_count, &ids, &sqr_dists);
175
176 // Closest ground point.
177 double x = gView->getFieldAs<double>(Id::X, ids[0]);
178 double y = gView->getFieldAs<double>(Id::Y, ids[0]);
179 double z = gView->getFieldAs<double>(Id::Z, ids[0]);
180
181 double z1;
182 // If the close ground point is at the same X/Y as the non-ground
183 // point, we're done. Also, if there's only one ground point, we
184 // just use that.

Callers

nothing calls this directly

Calls 10

neighbor_interp_groundFunction · 0.85
appendPointMethod · 0.80
calculateBoundsMethod · 0.80
pointMethod · 0.80
logFunction · 0.50
sizeMethod · 0.45
setFieldMethod · 0.45
getMethod · 0.45
knnSearchMethod · 0.45
containsMethod · 0.45

Tested by

no test coverage detected