Skip to content

Commit

Permalink
Don't change point classifications of voting points.
Browse files Browse the repository at this point in the history
  • Loading branch information
abellgithub committed Aug 14, 2020
1 parent aaf90ba commit 69cd524
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 10 deletions.
14 changes: 11 additions & 3 deletions filters/NeighborClassifierFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,13 @@ void NeighborClassifierFilter::prepared(PointTableRef table)
std::sort(m_domain.begin(), m_domain.end());
}


void NeighborClassifierFilter::ready(PointTableRef)
{
m_newClass.clear();
}


void NeighborClassifierFilter::doOneNoDomain(PointRef &point, PointRef &temp,
KD3Index &kdi)
{
Expand All @@ -130,9 +137,7 @@ void NeighborClassifierFilter::doOneNoDomain(PointRef &point, PointRef &temp,
auto oldclass = point.getFieldAs<double>(m_dim);
auto newclass = pr.first;
if (pr.second > thresh && oldclass != newclass)
{
point.setField(m_dim, newclass);
}
m_newClass[point.pointId()] = newclass;
}

// update point. kdi and temp both reference the NN point cloud
Expand Down Expand Up @@ -191,6 +196,9 @@ void NeighborClassifierFilter::filter(PointView& view)
doOne(point_src, point_nn, kdiCand);
}
}

for (auto& p : m_newClass)
view.setField(m_dim, p.first, p.second);
}

} // namespace pdal
Expand Down
3 changes: 3 additions & 0 deletions filters/NeighborClassifierFilter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@

#include <pdal/Filter.hpp>
#include <pdal/KDIndex.hpp>
#include <unordered_map>

extern "C" int32_t NeighborClassifierFilter_ExitFunc();
extern "C" PF_ExitFunc NeighborClassifierFilter_InitPlugin();
Expand All @@ -61,6 +62,7 @@ class PDAL_DLL NeighborClassifierFilter : public Filter
bool doOne(PointRef& point, PointRef& temp, KD3Index &kdi);
virtual void filter(PointView& view);
virtual void initialize();
virtual void ready(PointTableRef);
void doOneNoDomain(PointRef &point, PointRef& temp, KD3Index &kdi);
PointViewPtr loadSet(const std::string &candFileName, PointTableRef table);
NeighborClassifierFilter& operator=(
Expand All @@ -72,6 +74,7 @@ class PDAL_DLL NeighborClassifierFilter : public Filter
Dimension::Id m_dim;
std::string m_dimName;
std::string m_candidateFile;
std::unordered_map<PointId, int> m_newClass;
};

} // namespace pdal
15 changes: 8 additions & 7 deletions test/unit/filters/NeighborClassifierFilterTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,16 +185,22 @@ TEST(NeighborClassifierFilterTest, candidate)
Stage& r = *(factory.createStage("readers.las"));
r.setOptions(ro);

// NeighborClassifier used to be broken because it would change voting point
// classifications while it was running. This mean it would create different
// classifications if the point order was different.
// Randomizing the data should quickly expose this case if it were to reappear.
Stage& rfilter = *(factory.createStage("filters.randomize"));
rfilter.setInput(r);

std::vector<unsigned int> kvals = {1};
for (auto &k : kvals) {

Options fo;
//fo.add("dimension", "Classification");
fo.add("candidate", Support::datapath("las/sample_c_thin.las"));
fo.add("k", k);

Stage& f = *(factory.createStage("filters.neighborclassifier"));
f.setInput(r);
f.setInput(rfilter);
f.setOptions(fo);

PointTable table;
Expand All @@ -207,15 +213,10 @@ TEST(NeighborClassifierFilterTest, candidate)

stats::Summary::EnumMap NewClassifications = GetClassifications(f);

//std::cout << "**** K = " << k << " ****** " << std::endl;
for (auto& p : OrigClassifications)
{
if (p.first == 6)
{
EXPECT_TRUE(NewClassifications[p.first] == 12441 && OrigClassifications[p.first] == 12525);
}
//std::cout << " OrigClassifications["<< p.first << "] = " << OrigClassifications[p.first] <<
//" --> " << "NewClassifications[" << p.first << "] = " << NewClassifications[p.first] << std::endl;
}
}
}
Expand Down

0 comments on commit 69cd524

Please sign in to comment.