Skip to content

Commit

Permalink
update test with an text data example
Browse files Browse the repository at this point in the history
  • Loading branch information
alavenant committed Jun 12, 2024
1 parent 6b6fc3a commit 7f2afdb
Show file tree
Hide file tree
Showing 3 changed files with 157 additions and 65 deletions.
7 changes: 4 additions & 3 deletions filters/GridDecimationFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ void GridDecimationFilter::processOne(BOX2D bounds, PointRef& point, PointViewPt
int width = static_cast<int>((x - bounds.minx) / m_args->m_edgeLength);
int height = static_cast<int>((y - bounds.miny) / m_args->m_edgeLength);

// to avoid numreic pb with the division (append if the point is on the grid)
// to avoid numeric pb due to the division (append if the point is on the grid)
if (x < bounds.minx+width*m_args->m_edgeLength) width--;
if (y < bounds.miny+height*m_args->m_edgeLength) height--;
if (x >= bounds.minx+(width+1)*m_args->m_edgeLength) width++;
Expand Down Expand Up @@ -114,8 +114,9 @@ void GridDecimationFilter::processOne(BOX2D bounds, PointRef& point, PointViewPt

void GridDecimationFilter::createGrid(BOX2D bounds)
{
size_t d_width = std::floor((bounds.maxx - bounds.minx) / m_args->m_edgeLength) + 1;
size_t d_height = std::floor((bounds.maxy - bounds.miny) / m_args->m_edgeLength) + 1;
// +2 to be sur to deal with all points (avoid some numeric precision issue due to the division)
size_t d_width = std::floor((bounds.maxx - bounds.minx) / m_args->m_edgeLength) + 2;
size_t d_height = std::floor((bounds.maxy - bounds.miny) / m_args->m_edgeLength) + 2;

if (d_width < 0.0 || d_width > (std::numeric_limits<int>::max)())
throwError("Grid width out of range.");
Expand Down
82 changes: 82 additions & 0 deletions test/data/text/file_grid.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
X Y Z Classification
1639623.5 1454421.5 2 1
1639623.5 1454422.0 2 1
1639623.5 1454422.5 2 1
1639623.5 1454423.0 2 1
1639623.5 1454423.5 2 1
1639623.5 1454424.0 2 1
1639623.5 1454424.5 2 1
1639623.5 1454425.0 2 1
1639623.5 1454425.5 2 1
1639624.0 1454421.5 1 1
1639624.0 1454422.0 1 1
1639624.0 1454422.5 1 1
1639624.0 1454423.0 1 1
1639624.0 1454423.5 1 1
1639624.0 1454424.0 1 1
1639624.0 1454424.5 1 1
1639624.0 1454425.0 1 1
1639624.0 1454425.5 1 1
1639624.5 1454421.5 2 1
1639624.5 1454422.0 2 1
1639624.5 1454422.5 2 1
1639624.5 1454423.0 2 1
1639624.5 1454423.5 2 1
1639624.5 1454424.0 2 1
1639624.5 1454424.5 2 1
1639624.5 1454425.0 2 1
1639624.5 1454425.5 2 1
1639625.0 1454421.5 1 1
1639625.0 1454422.0 1 1
1639625.0 1454422.5 1 1
1639625.0 1454423.0 1 1
1639625.0 1454423.5 1 1
1639625.0 1454424.0 1 1
1639625.0 1454424.5 1 1
1639625.0 1454425.0 1 1
1639625.0 1454425.5 1 1
1639625.5 1454421.5 2 1
1639625.5 1454422.0 2 1
1639625.5 1454422.5 2 1
1639625.5 1454423.0 2 1
1639625.5 1454423.5 2 1
1639625.5 1454424.0 2 1
1639625.5 1454424.5 2 1
1639625.5 1454425.0 2 1
1639625.5 1454425.5 2 1
1639626.0 1454421.5 1 1
1639626.0 1454422.0 1 1
1639626.0 1454422.5 1 1
1639626.0 1454423.0 1 1
1639626.0 1454423.5 1 1
1639626.0 1454424.0 1 1
1639626.0 1454424.5 1 1
1639626.0 1454425.0 1 1
1639626.0 1454425.5 1 1
1639626.5 1454421.5 2 1
1639626.5 1454422.0 2 1
1639626.5 1454422.5 2 1
1639626.5 1454423.0 2 1
1639626.5 1454423.5 2 1
1639626.5 1454424.0 2 1
1639626.5 1454424.5 2 1
1639626.5 1454425.0 2 1
1639626.5 1454425.5 2 1
1639627.0 1454421.5 1 1
1639627.0 1454422.0 1 1
1639627.0 1454422.5 1 1
1639627.0 1454423.0 1 1
1639627.0 1454423.5 1 1
1639627.0 1454424.0 1 1
1639627.0 1454424.5 1 1
1639627.0 1454425.0 1 1
1639627.0 1454425.5 1 1
1639627.5 1454421.5 2 1
1639627.5 1454422.0 2 1
1639627.5 1454422.5 2 1
1639627.5 1454423.0 2 1
1639627.5 1454423.5 2 1
1639627.5 1454424.0 2 1
1639627.5 1454424.5 2 1
1639627.5 1454425.0 2 1
1639627.5 1454425.5 2 1
133 changes: 71 additions & 62 deletions test/unit/filters/GridDecimationFilterTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@ bool contains(BOX2D box, double x, double y)
TEST(DecimationFilterTest, GridDecimationFilterTest_test_empty)
{
Options ro;
ro.add("filename", Support::datapath("las/4_6_crop.las"));
ro.add("filename", Support::datapath("text/file_grid.txt"));

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

Options gdOps;
gdOps.add("output_type", "max");
gdOps.add("resolution", "10.");
gdOps.add("where", "Classification==10"); // no points at 10
gdOps.add("value", "Classification=5");
gdOps.add("where", "Classification==2"); // no points at 2 (all points are at 1)
gdOps.add("value", "Classification=2");

GridDecimationFilter filter;
filter.setOptions(gdOps);
Expand All @@ -69,74 +69,83 @@ TEST(DecimationFilterTest, GridDecimationFilterTest_test_empty)
TEST(DecimationFilterTest, GridDecimationFilterTest_test1)
{
Options ro;
ro.add("filename", Support::datapath("las/4_6_crop.las"));
ro.add("filename", Support::datapath("text/file_grid.txt"));

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

std::vector<double> resolution = {10., 10.3, 9.8, 9.6};
std::vector<double> resolution = {1., 1.3, 0.500000000001, 1.5, 0.8, 0.6, 0.1, 0.49999999999999999999};

for (auto res : resolution)
for (size_t it(0); it<1; it++) // max then min
{
Options gdOps;
gdOps.add("output_type", "max");
gdOps.add("resolution", res);
gdOps.add("value", "Classification=5");

GridDecimationFilter filter;
filter.setOptions(gdOps);
filter.setInput(r);

PointTable table;

filter.prepare(table);
PointViewSet viewSet = filter.execute(table);

EXPECT_EQ(viewSet.size(), 1u);

PointViewPtr view = *viewSet.begin();

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

BOX2D bounds;
view->calculateBounds(bounds);
size_t d_width = std::floor((bounds.maxx - bounds.minx) / res) + 1;
size_t d_height = std::floor((bounds.maxy - bounds.miny) / res) + 1;
EXPECT_EQ(nbThreadPts, d_width*d_height);

double xmin = bounds.minx;
double ymin = bounds.miny;

for (size_t l(0); l<d_height; l++){
for (size_t c(0); c<d_width; c++){

BOX2D dstBounds(xmin + c*res, ymin + l*res, xmin + (c+1)*res, ymin + (l+1)*res);

int nbThreadPtsCrop (0);
double Zmax(0), ZmaxGrid(0);
for (PointId i = 0; i < view->size(); ++i)
{
PointRef point = view->point(i);
double x_pt = point.getFieldAs<double>(Dimension::Id::X);
double y_pt = point.getFieldAs<double>(Dimension::Id::Y);
if (!contains(dstBounds, x_pt, y_pt)) continue;
Options gdOps;
gdOps.add("output_type", (it==0 ? "max" : "min"));
gdOps.add("resolution", res);
gdOps.add("value", "Classification=5");

GridDecimationFilter filter;
filter.setOptions(gdOps);
filter.setInput(r);

PointTable table;

filter.prepare(table);
PointViewSet viewSet = filter.execute(table);

EXPECT_EQ(viewSet.size(), 1u);

PointViewPtr view = *viewSet.begin();

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==5) nbThreadPts++;
}

BOX2D bounds;
view->calculateBounds(bounds);
// cf. GridDecimationFilter comment
size_t d_width = std::floor((bounds.maxx - bounds.minx) / res) + 2;
size_t d_height = std::floor((bounds.maxy - bounds.miny) / res) + 2;
EXPECT_LE(nbThreadPts, d_width*d_height); // some cells coul'd be empty

double xmin = bounds.minx;
double ymin = bounds.miny;

for (size_t l(0); l<d_height; l++){
for (size_t c(0); c<d_width; c++){

BOX2D dstBounds(xmin + c*res, ymin + l*res, xmin + (c+1)*res, ymin + (l+1)*res);

double z_pt = point.getFieldAs<double>(Dimension::Id::Z);
if (Zmax==0 or z_pt > Zmax) Zmax = z_pt;
int nbThreadPtsCrop (0), nbPtsCrop(0);
double Zref(0), ZrefGrid(0);
for (PointId i = 0; i < view->size(); ++i)
{
PointRef point = view->point(i);
double x_pt = point.getFieldAs<double>(Dimension::Id::X);
double y_pt = point.getFieldAs<double>(Dimension::Id::Y);
if (!contains(dstBounds, x_pt, y_pt)) continue;
nbPtsCrop++;

double z_pt = point.getFieldAs<double>(Dimension::Id::Z);
if (it==0){ if(Zref==0 or z_pt > Zref) Zref = z_pt; }
else { if(Zref==0 or z_pt < Zref) Zref = z_pt; }

uint8_t classification = point.getFieldAs<uint8_t>(Dimension::Id::Classification);
if (classification==5) {nbThreadPtsCrop++; ZrefGrid=z_pt;}
}

uint8_t classification = point.getFieldAs<uint8_t>(Dimension::Id::Classification);
if (classification==5) {nbThreadPtsCrop++; ZmaxGrid=z_pt;}
if (nbPtsCrop>0)
{
EXPECT_EQ(nbThreadPtsCrop, 1);
EXPECT_EQ(Zref, ZrefGrid);
}
}

EXPECT_EQ(nbThreadPtsCrop, 1);
EXPECT_EQ(Zmax, ZmaxGrid);
}
}
}
Expand Down

0 comments on commit 7f2afdb

Please sign in to comment.