Skip to content

Commit

Permalink
Move calc bounds (#3051)
Browse files Browse the repository at this point in the history
* Move calculateBounds back to PointView.

* Remove debug.

* Remove junk.
  • Loading branch information
abellgithub committed Apr 29, 2020
1 parent 526392c commit 4754f6f
Show file tree
Hide file tree
Showing 13 changed files with 33 additions and 58 deletions.
2 changes: 1 addition & 1 deletion filters/ELMFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ void ELMFilter::filter(PointView& view)
return;

BOX2D bounds;
calculateBounds(view, bounds);
view.calculateBounds(bounds);

size_t cols =
static_cast<size_t>(((bounds.maxx - bounds.minx) / m_cell) + 1);
Expand Down
4 changes: 2 additions & 2 deletions filters/MortonOrderFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ PointViewSet MortonOrderFilter::reverseMorton(PointViewPtr inView)

// compute range
BOX2D buffer_bounds;
calculateBounds(*inView, buffer_bounds);
inView->calculateBounds(buffer_bounds);
const double xrange = buffer_bounds.maxx - buffer_bounds.minx;
const double yrange = buffer_bounds.maxy - buffer_bounds.miny;

Expand Down Expand Up @@ -192,7 +192,7 @@ PointViewSet MortonOrderFilter::morton(PointViewPtr inView)
std::multimap<Coord, PointId, CmpZOrder> sorted(compare);

BOX2D buffer_bounds;
calculateBounds(*inView, buffer_bounds);
inView->calculateBounds(buffer_bounds);
double xrange = buffer_bounds.maxx - buffer_bounds.minx;
double yrange = buffer_bounds.maxy - buffer_bounds.miny;

Expand Down
2 changes: 1 addition & 1 deletion filters/PMFFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ void PMFFilter::processGround(PointViewPtr view)
{
// initialize bounds, rows, columns, and surface
BOX2D bounds;
calculateBounds(*view, bounds);
view->calculateBounds(bounds);
size_t cols = static_cast<size_t>(
((bounds.maxx - bounds.minx) / m_args->m_cellSize) + 1);
size_t rows = static_cast<size_t>(
Expand Down
2 changes: 1 addition & 1 deletion filters/SMRFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ PointViewSet SMRFilter::run(PointViewPtr view)

m_srs = inlierView->spatialReference();

calculateBounds(*inlierView, m_bounds);
inlierView->calculateBounds(m_bounds);
m_cols = static_cast<int>(
((m_bounds.maxx - m_bounds.minx) / m_args->m_cell) + 1);
m_rows = static_cast<int>(
Expand Down
2 changes: 1 addition & 1 deletion filters/VoxelCenterNearestNeighborFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void VoxelCenterNearestNeighborFilter::addArgs(ProgramArgs& args)
PointViewSet VoxelCenterNearestNeighborFilter::run(PointViewPtr view)
{
BOX3D bounds;
calculateBounds(*view, bounds);
view->calculateBounds(bounds);

// Find distance from voxel center to point. If the distance is less
// than previous (or is the first one for the voxel), store the
Expand Down
2 changes: 1 addition & 1 deletion io/GDALWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ void GDALWriter::writeView(const PointViewPtr view)
if (!m_fixedGrid)
{
BOX2D bounds;
calculateBounds(*view, bounds);
view->calculateBounds(bounds);
if (!m_grid)
createGrid(bounds);
else
Expand Down
24 changes: 0 additions & 24 deletions pdal/EigenUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,30 +49,6 @@ namespace pdal
#pragma warning (push)
#pragma warning (disable: 4244)

void calculateBounds(const PointView& view, BOX2D& output)
{
for (PointId idx = 0; idx < view.size(); idx++)
{
double x = view.getFieldAs<double>(Dimension::Id::X, idx);
double y = view.getFieldAs<double>(Dimension::Id::Y, idx);

output.grow(x, y);
}
}


void calculateBounds(const PointView& view, BOX3D& output)
{
for (PointId idx = 0; idx < view.size(); idx++)
{
double x = view.getFieldAs<double>(Dimension::Id::X, idx);
double y = view.getFieldAs<double>(Dimension::Id::Y, idx);
double z = view.getFieldAs<double>(Dimension::Id::Z, idx);

output.grow(x, y, z);
}
}

PointViewPtr demeanPointView(const PointView& view)
{
using namespace Eigen;
Expand Down
13 changes: 0 additions & 13 deletions pdal/EigenUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,6 @@ class SpatialReference;

typedef std::shared_ptr<PointView> PointViewPtr;

/*! @return a cumulated bounds of all points in the PointView.
\verbatim embed:rst
.. note::
This method requires that an `X`, `Y`, and `Z` dimension be
available, and that it can be casted into a *double* data
type using the :cpp:func:`pdal::Dimension::applyScaling`
method. Otherwise, an exception will be thrown.
\endverbatim
*/
PDAL_DLL void calculateBounds(const PointView& view, BOX2D& box);
PDAL_DLL void calculateBounds(const PointView& view, BOX3D& box);

PDAL_DLL PointViewPtr demeanPointView(const PointView& view);
PDAL_DLL PointViewPtr demeanPointView(const PointView& ,double* centroid);
PDAL_DLL PointViewPtr transform(const PointView&, double* matrix);
Expand Down
5 changes: 2 additions & 3 deletions pdal/KDIndex.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@

#include <nanoflann/nanoflann.hpp>

#include <pdal/EigenUtils.hpp>
#include <pdal/PointView.hpp>

namespace nanoflann
Expand Down Expand Up @@ -589,7 +588,7 @@ bool KDIndex<2>::kdtree_get_bbox(BBOX& bb) const
else
{
BOX2D bounds;
calculateBounds(m_buf, bounds);
m_buf.calculateBounds(bounds);

bb[0].low = bounds.minx;
bb[0].high = bounds.maxx;
Expand All @@ -615,7 +614,7 @@ bool KDIndex<3>::kdtree_get_bbox(BBOX& bb) const
else
{
BOX3D bounds;
calculateBounds(m_buf, bounds);
m_buf.calculateBounds(bounds);

bb[0].low = bounds.minx;
bb[0].high = bounds.maxx;
Expand Down
17 changes: 15 additions & 2 deletions pdal/PointView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,26 @@ void PointView::setFieldInternal(Dimension::Id dim, PointId idx,

void PointView::calculateBounds(BOX2D& output) const
{
pdal::calculateBounds(*this, output);
for (PointId idx = 0; idx < size(); idx++)
{
double x = getFieldAs<double>(Dimension::Id::X, idx);
double y = getFieldAs<double>(Dimension::Id::Y, idx);

output.grow(x, y);
}
}


void PointView::calculateBounds(BOX3D& output) const
{
pdal::calculateBounds(*this, output);
for (PointId idx = 0; idx < size(); idx++)
{
double x = getFieldAs<double>(Dimension::Id::X, idx);
double y = getFieldAs<double>(Dimension::Id::Y, idx);
double z = getFieldAs<double>(Dimension::Id::Z, idx);

output.grow(x, y, z);
}
}


Expand Down
6 changes: 3 additions & 3 deletions test/unit/EigenTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ TEST(EigenTest, calcBounds)
const double lim_max = (std::numeric_limits<double>::max)();
PointViewPtr b0(new PointView(table));
BOX3D box_b0;
calculateBounds(*b0, box_b0);
b0->calculateBounds(box_b0);
check_bounds(box_b0, lim_max, lim_min, lim_max, lim_min, lim_max, lim_min);

PointViewPtr b1(new PointView(table));
Expand All @@ -208,11 +208,11 @@ TEST(EigenTest, calcBounds)
bs.insert(b2);

BOX3D box_b1;
calculateBounds(*b1, box_b1);
b1->calculateBounds(box_b1);
check_bounds(box_b1, 0.0, 2.0, 0.0, 2.0, 0.0, 2.0);

BOX3D box_b2;
calculateBounds(*b2, box_b2);
b2->calculateBounds(box_b2);
check_bounds(box_b2, 1.0, 3.0, 1.0, 3.0, 1.0, 3.0);
}

Expand Down
6 changes: 3 additions & 3 deletions test/unit/filters/ChipperTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ TEST(ChipperTest, test_construction)
BOX2D b1;
BOX2D b2;

calculateBounds(*p1, b1);
calculateBounds(*p2, b2);
p1->calculateBounds(b1);
p2->calculateBounds(b2);

return b1.minx < b2.minx ? true :
b1.minx > b2.minx ? false :
Expand All @@ -91,7 +91,7 @@ TEST(ChipperTest, test_construction)

PointViewPtr view = views[2];
BOX2D bounds;
calculateBounds(*view, bounds);
view->calculateBounds(bounds);

EXPECT_NEAR(bounds.minx, 635674.05, 0.05);
EXPECT_NEAR(bounds.maxx, 635993.93, 0.05);
Expand Down
6 changes: 3 additions & 3 deletions test/unit/filters/SplitterTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ TEST(SplitterTest, test_tile_filter)
{
BOX2D b;
PointViewPtr v = *it;
calculateBounds(*v, b);
v->calculateBounds(b);
EXPECT_TRUE(b.maxx - b.minx <= 1000);
EXPECT_TRUE(b.maxy - b.miny <= 1000);

Expand Down Expand Up @@ -130,7 +130,7 @@ TEST(SplitterTest, test_buffer)
{
BOX2D b;
PointViewPtr v = *it;
calculateBounds(*v, b);
v->calculateBounds(b);
EXPECT_TRUE(b.maxx - b.minx <= 1040);
EXPECT_TRUE(b.maxy - b.miny <= 1040);
bounds[v] = b;
Expand Down Expand Up @@ -187,7 +187,7 @@ TEST(SplitterTest, test_buffer2)
for (PointViewPtr v : s)
{
BOX2D b;
calculateBounds(*v, b);
v->calculateBounds(b);
bounds[v] = b;
vvec.push_back(v);
}
Expand Down

0 comments on commit 4754f6f

Please sign in to comment.