Skip to content

Commit

Permalink
Merge branch '1.3-maintenance' of github.com:PDAL/PDAL into 1.3-maint…
Browse files Browse the repository at this point in the history
…enance
  • Loading branch information
hobu committed Oct 27, 2016
2 parents f164c48 + 15db3d0 commit c972f25
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 19 deletions.
25 changes: 17 additions & 8 deletions filters/splitter/SplitterFilter.cpp
Expand Up @@ -51,6 +51,9 @@ static PluginInfo const s_info = PluginInfo(

CREATE_STATIC_PLUGIN(1, 0, SplitterFilter, Filter, s_info)

SplitterFilter::SplitterFilter() : m_viewMap(CoordCompare())
{}

std::string SplitterFilter::getName() const { return s_info.name; }

void SplitterFilter::addArgs(ProgramArgs& args)
Expand All @@ -64,6 +67,7 @@ void SplitterFilter::addArgs(ProgramArgs& args)


//This used to be a lambda, but the VS compiler exploded, I guess.
/**
typedef std::pair<int, int> Coord;
namespace
{
Expand All @@ -79,16 +83,14 @@ class CoordCompare
};
};
}
**/

PointViewSet SplitterFilter::run(PointViewPtr inView)
{
PointViewSet viewSet;
if (!inView->size())
return viewSet;

CoordCompare compare;
std::map<Coord, PointViewPtr, CoordCompare> viewMap(compare);

// Use the location of the first point as the origin, unless specified.
// (!= test == isnan(), which doesn't exist on windows)
if (m_xOrigin != m_xOrigin)
Expand All @@ -101,20 +103,27 @@ PointViewSet SplitterFilter::run(PointViewPtr inView)
for (PointId idx = 0; idx < inView->size(); idx++)
{
double x = inView->getFieldAs<double>(Dimension::Id::X, idx);
int xpos = (x - m_xOrigin) / m_length;
x -= m_xOrigin;
int xpos = x / m_length;
if (x < 0)
xpos--;

double y = inView->getFieldAs<double>(Dimension::Id::Y, idx);
int ypos = (y - m_yOrigin) / m_length;
y -= m_yOrigin;
int ypos = y / m_length;
if (y < 0)
ypos--;

Coord loc(xpos, ypos);
PointViewPtr& outView = viewMap[loc];
PointViewPtr& outView = m_viewMap[loc];
if (!outView)
outView = inView->makeNew();
outView->appendPoint(*inView.get(), idx);
}

// Pull the buffers out of the map and stick them in the standard
// output set, setting the bounds as we go.
for (auto bi = viewMap.begin(); bi != viewMap.end(); ++bi)
// output set.
for (auto bi = m_viewMap.begin(); bi != m_viewMap.end(); ++bi)
viewSet.insert(bi->second);
return viewSet;
}
Expand Down
19 changes: 17 additions & 2 deletions filters/splitter/SplitterFilter.hpp
Expand Up @@ -45,9 +45,23 @@ namespace pdal

class PDAL_DLL SplitterFilter : public pdal::Filter
{
private:
//This used to be a lambda, but the VS compiler exploded, I guess.
typedef std::pair<int, int> Coord;
class CoordCompare
{
public:
bool operator () (const Coord& c1, const Coord& c2) const
{
return c1.first < c2.first ? true :
c1.first > c2.first ? false :
c1.second < c2.second ? true :
false;
};
};

public:
SplitterFilter() : Filter()
{}
SplitterFilter();

static void * create();
static int32_t destroy(void *);
Expand All @@ -57,6 +71,7 @@ class PDAL_DLL SplitterFilter : public pdal::Filter
double m_length;
double m_xOrigin;
double m_yOrigin;
std::map<Coord, PointViewPtr, CoordCompare> m_viewMap;

virtual void addArgs(ProgramArgs& args);
virtual PointViewSet run(PointViewPtr view);
Expand Down
30 changes: 21 additions & 9 deletions test/unit/filters/SplitterTest.cpp
Expand Up @@ -76,25 +76,37 @@ TEST(SplitterTest, test_tile_filter)
StageWrapper::done(s, table);

std::vector<PointViewPtr> views;
for (auto it = viewSet.begin(); it != viewSet.end(); ++it)
views.push_back(*it);
std::map<PointViewPtr, BOX2D> bounds;

auto sorter = [](PointViewPtr p1, PointViewPtr p2)
for (auto it = viewSet.begin(); it != viewSet.end(); ++it)
{
BOX2D b1, b2;
BOX2D b;
PointViewPtr v = *it;
v->calculateBounds(b);
EXPECT_TRUE(b.maxx - b.minx <= 1000);
EXPECT_TRUE(b.maxy - b.miny <= 1000);

for (auto& p : bounds)
EXPECT_FALSE(p.second.overlaps(b));

p1->calculateBounds(b1);
p2->calculateBounds(b2);
bounds[v] = b;
views.push_back(v);
}

auto sorter = [&bounds](PointViewPtr p1, PointViewPtr p2)
{
BOX2D b1 = bounds[p1];
BOX2D b2 = bounds[p2];

return b1.minx < b2.minx ? true :
b1.minx > b2.minx ? false :
b1.miny < b2.miny;
};
std::sort(views.begin(), views.end(), sorter);

EXPECT_EQ(views.size(), 15u);
size_t counts[] = {24, 27, 26, 27, 10, 166, 142, 76, 141, 132, 63, 70, 67,
34, 60 };
EXPECT_EQ(views.size(), 24u);
size_t counts[] = {24, 25, 2, 26, 27, 10, 82, 68, 43, 57, 7, 71, 73,
61, 33, 84, 74, 4, 59, 70, 67, 34, 60, 4 };
for (size_t i = 0; i < views.size(); ++i)
{
PointViewPtr view = views[i];
Expand Down

0 comments on commit c972f25

Please sign in to comment.