Skip to content

Commit

Permalink
Use proper logic for multiple crop regions.
Browse files Browse the repository at this point in the history
Close #2198
  • Loading branch information
abellgithub committed Oct 2, 2018
1 parent c226abe commit 90a7faf
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 27 deletions.
14 changes: 7 additions & 7 deletions filters/CropFilter.cpp
Expand Up @@ -146,18 +146,18 @@ bool CropFilter::processOne(PointRef& point)
{
for (auto& g : m_geoms)
for (auto& gridPnp : g.m_gridPnps)
if (!crop(point, *gridPnp))
return false;
if (crop(point, *gridPnp))
return true;

for (auto& box : m_boxes)
if (!crop(point, box))
return false;
if (crop(point, box))
return true;

for (auto& center: m_args->m_centers)
if (!crop(point, center))
return false;
if (crop(point, center))
return true;

return true;
return false;
}


Expand Down
2 changes: 1 addition & 1 deletion pdal/Streamable.hpp
Expand Up @@ -57,7 +57,7 @@ class PDAL_DLL Streamable : public virtual Stage
Not all stages support streaming mode and an exception will be thrown
when attempting to \ref execute an unsupported stage.
Streaming points can reduce memory consumption, but may limit access
Streaming points can reduce memory consumption, but will limit access
to algorithms that need to operate on full point sets.
\param table Streaming point table used for stage pipeline. This must be
Expand Down
62 changes: 43 additions & 19 deletions test/unit/filters/CropFilterTest.cpp
Expand Up @@ -258,6 +258,7 @@ TEST(CropFilterTest, multibounds)
EXPECT_EQ(total_cnt, 7);
}


TEST(CropFilterTest, stream)
{
using namespace Dimension;
Expand Down Expand Up @@ -301,6 +302,11 @@ TEST(CropFilterTest, stream)
point.setField(Id::X, 12);
point.setField(Id::Y, 2);
}
else if (i == 5)
{
point.setField(Id::X, 105);
point.setField(Id::Y, 105);
}
else
return false;
i++;
Expand All @@ -315,39 +321,57 @@ TEST(CropFilterTest, stream)
o.add("bounds", "([1, 3], [1, 3])");
o.add("bounds", "([5, 7], [1, 3])");
o.add("polygon", "POLYGON ((9 1, 11 1, 11 3, 9 3, 9 1))");
o.add("polygon", "MULTIPOLYGON (((9 1, 11 1, 11 3, 9 3, 9 1)),"
"((100 100, 110 100, 110 110, 100 110, 100 100 )))");
crop.setInput(r);
crop.setOptions(o);

auto cb = [](PointRef& point)
class TestFilter : public Filter, public Streamable
{
static int i = 0;
if (i == 0)
{
EXPECT_EQ(point.getFieldAs<int>(Id::X), 2);
EXPECT_EQ(point.getFieldAs<int>(Id::Y), 2);
}
if (i == 1)
public:
std::string getName() const
{ return "filters.testfilter"; }
point_count_t m_count;

private:
virtual void ready(PointTableRef)
{
EXPECT_EQ(point.getFieldAs<int>(Id::X), 6);
EXPECT_EQ(point.getFieldAs<int>(Id::Y), 2);
m_count = 0;
}
if (i == 2)

virtual bool processOne(PointRef& point)
{
EXPECT_EQ(point.getFieldAs<int>(Id::X), 10);
EXPECT_EQ(point.getFieldAs<int>(Id::Y), 2);
if (m_count == 0)
{
EXPECT_EQ(point.getFieldAs<int>(Id::X), 2);
EXPECT_EQ(point.getFieldAs<int>(Id::Y), 2);
}
if (m_count == 1)
{
EXPECT_EQ(point.getFieldAs<int>(Id::X), 6);
EXPECT_EQ(point.getFieldAs<int>(Id::Y), 2);
}
if (m_count == 2)
{
EXPECT_EQ(point.getFieldAs<int>(Id::X), 10);
EXPECT_EQ(point.getFieldAs<int>(Id::Y), 2);
}
if (m_count == 3)
{
EXPECT_EQ(point.getFieldAs<int>(Id::X), 105);
EXPECT_EQ(point.getFieldAs<int>(Id::Y), 105);
}
m_count++;
return true;
}
else
return false;
i++;
return true;
};

StreamCallbackFilter f;
f.setCallback(cb);
TestFilter f;
f.setInput(crop);

f.prepare(table);
f.execute(table);
EXPECT_EQ(f.m_count, (point_count_t)4);
}


Expand Down

0 comments on commit 90a7faf

Please sign in to comment.