Skip to content

Commit

Permalink
Add origin support for SplitterFilter.
Browse files Browse the repository at this point in the history
  • Loading branch information
abellgithub committed May 7, 2015
1 parent c7152e9 commit bae837b
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 10 deletions.
49 changes: 49 additions & 0 deletions doc/stages/filters.splitter.rst
@@ -0,0 +1,49 @@
.. _filters.splitter:

filters.splitter
===============

The splitter filter breaks a point cloud into square tiles of a size that
you choose. The origin of the tiles is chosen arbitrarily unless specified
as an option.

The splitter takes a single PointView as its input and creates a PointView
for each tile as its output.

Splitting is usually applied to data read from files (which produce one large
stream of points) before the points are written to a database (which prefer
data segmented into smaller blocks).

Example
-------

.. code-block:: xml
<?xml version="1.0" encoding="utf-8"?>
<Pipeline version="1.0">
<Writer type="writers.pgpointcloud">
<Option name="connection">dbname='lidar' user='user'</Option>
<Filter type="filters.chipper">
<Option name="length">100</Option>
<Option name="origin_x">638900.0</Option>
<Option name="origin_y">835500.0</Option>
<Reader type="readers.las">
<Option name="filename">example.las</Option>
</Reader>
</Filter>
</Writer>
</Pipeline>
Options
-------

length
Length of the sides of the tiles that are created to hold points.
[Default: 1000]

origin_x
X Origin of the tiles. [Default: none (chosen arbitarily)]

origin_y
Y Origin of the tiles. [Default: none (chosen arbitarily)]

23 changes: 14 additions & 9 deletions filters/splitter/SplitterFilter.cpp
Expand Up @@ -53,7 +53,11 @@ std::string SplitterFilter::getName() const { return s_info.name; }

void SplitterFilter::processOptions(const Options& options)
{
m_length = options.getValueOrDefault<uint32_t>("length", 1000);
m_length = options.getValueOrDefault<double>("length", 1000.0);
m_xOrigin = options.getValueOrDefault<double>("origin_x",
std::numeric_limits<double>::quiet_NaN());
m_yOrigin = options.getValueOrDefault<double>("origin_y",
std::numeric_limits<double>::quiet_NaN());
}


Expand Down Expand Up @@ -94,24 +98,25 @@ PointViewSet SplitterFilter::run(PointViewPtr inView)
std::map<Coord, PointViewPtr, CoordCompare> viewMap(compare);

// Use the location of the first point as the origin.
double xOrigin = inView->getFieldAs<double>(Dimension::Id::X, 0);
double yOrigin = inView->getFieldAs<double>(Dimension::Id::Y, 0);
if (m_xOrigin == std::numeric_limits<double>::quiet_NaN())
m_xOrigin = inView->getFieldAs<double>(Dimension::Id::X, 0);
if (m_yOrigin == std::numeric_limits<double>::quiet_NaN())
m_yOrigin = inView->getFieldAs<double>(Dimension::Id::Y, 0);

// Overlay a grid of squares on the points (m_length sides). Each square
// corresponds to a new point buffer. Place the points falling in the
// each square in the corresponding point buffer.
for (PointId idx = 0; idx < inView->size(); idx++)
{
int xpos = (inView->getFieldAs<double>(Dimension::Id::X, idx) - xOrigin) /
m_length;
int ypos = (inView->getFieldAs<double>(Dimension::Id::Y, idx) - yOrigin) /
m_length;
double x = inView->getFieldAs<double>(Dimension::Id::X, idx);
int xpos = (x - m_xOrigin) / m_length;
double y = inView->getFieldAs<double>(Dimension::Id::Y, idx);
int ypos = (y - m_yOrigin) / m_length;

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

Expand Down
4 changes: 3 additions & 1 deletion filters/splitter/SplitterFilter.hpp
Expand Up @@ -55,7 +55,9 @@ class PDAL_DLL SplitterFilter : public pdal::Filter
Options getDefaultOptions();

private:
uint32_t m_length;
double m_length;
double m_xOrigin;
double m_yOrigin;

virtual void processOptions(const Options& options);
virtual PointViewSet run(PointViewPtr view);
Expand Down

0 comments on commit bae837b

Please sign in to comment.