Skip to content

Commit

Permalink
fix on gridDecimation filter
Browse files Browse the repository at this point in the history
  • Loading branch information
alavenant committed Jun 3, 2024
1 parent ba3b585 commit 02ff3e2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
16 changes: 10 additions & 6 deletions filters/GridDecimationFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,17 @@ void GridDecimationFilter::processOne(BOX2D bounds, PointRef& point, PointViewPt
double y = point.getFieldAs<double>(Dimension::Id::Y);
int id = point.getFieldAs<double>(Dimension::Id::PointId);

double d_width_pt = std::floor((x - bounds.minx) / m_args->m_edgeLength) + 1;
double d_height_pt = std::floor((y - bounds.miny) / m_args->m_edgeLength) + 1;
// if x==(xmax of the cell), we assume the point are in the upper cell
// if y==(ymax of the cell), we assume the point are in the right cell
double d_width_pt = (x - bounds.minx) / m_args->m_edgeLength;
double d_height_pt = (y - bounds.miny) / m_args->m_edgeLength;

int width = static_cast<int>(d_width_pt);
int height = static_cast<int>(d_height_pt);

auto ptRefid = this->grid[ std::make_pair(width,height) ];
auto mptRefid = this->grid.find( std::make_pair(width,height) );
assert( mptRefid != this->grid.end());
auto ptRefid = mptRefid->second;

if (ptRefid==-1)
{
Expand All @@ -107,9 +111,9 @@ void GridDecimationFilter::processOne(BOX2D bounds, PointRef& point, PointViewPt

void GridDecimationFilter::createGrid(BOX2D bounds)
{
double d_width = std::floor((bounds.maxx - bounds.minx) / m_args->m_edgeLength) + 1;
double d_height = std::floor((bounds.maxy - bounds.miny) / m_args->m_edgeLength) + 1;
double d_width = std::round((bounds.maxx - bounds.minx) / m_args->m_edgeLength);
double d_height = std::round((bounds.maxy - bounds.miny) / m_args->m_edgeLength);

if (d_width < 0.0 || d_width > (std::numeric_limits<int>::max)())
throwError("Grid width out of range.");
if (d_height < 0.0 || d_height > (std::numeric_limits<int>::max)())
Expand Down
Binary file added test/data/las/4_6_crop.las
Binary file not shown.
12 changes: 5 additions & 7 deletions test/unit/filters/GridDecimationFilterTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,16 @@ TEST(GridDecimationFilterTest, create)
TEST(DecimationFilterTest, GridDecimationFilterTest_test1)
{
Options ro;
ro.add("filename", Support::datapath("las/4_6.las"));
ro.add("filename", Support::datapath("las/4_6_crop.las"));

StageFactory factory;
Stage& r = *(factory.createStage("readers.las"));
r.setOptions(ro);

Options gdOps;
gdOps.add("output_type", "max");
gdOps.add("resolution", 1.);
gdOps.add("where", "Classification==2");
gdOps.add("value", "Classification=3");
gdOps.add("resolution", 10.);
gdOps.add("value", "Classification=5");

GridDecimationFilter filter;
filter.setOptions(gdOps);
Expand All @@ -50,15 +49,14 @@ TEST(DecimationFilterTest, GridDecimationFilterTest_test1)
EXPECT_EQ(viewSet.size(), 1u);

PointViewPtr view = *viewSet.begin();
EXPECT_EQ(view->size(), 198975);

int nbThreadPts (0);
for (PointId i = 0; i < view->size(); ++i)
{
PointRef point = view->point(i);
uint8_t classification = point.getFieldAs<uint8_t>(Dimension::Id::Classification);
if (classification==3) nbThreadPts++;
if (classification==5) nbThreadPts++;
}

EXPECT_EQ(nbThreadPts, 65067);
EXPECT_EQ(nbThreadPts, 400);
}

0 comments on commit 02ff3e2

Please sign in to comment.