Skip to content

Commit

Permalink
Separate BOX and Bounds.
Browse files Browse the repository at this point in the history
  • Loading branch information
abellgithub committed Apr 23, 2019
1 parent fc5e6bb commit 9aae090
Show file tree
Hide file tree
Showing 28 changed files with 234 additions and 135 deletions.
1 change: 1 addition & 0 deletions filters/CropFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

#include "CropFilter.hpp"

#include <pdal/Bounds.hpp>
#include <pdal/GDALUtils.hpp>
#include <pdal/PointView.hpp>
#include <pdal/StageFactory.hpp>
Expand Down
3 changes: 2 additions & 1 deletion filters/InfoFilter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@

#include <pdal/Filter.hpp>
#include <pdal/Streamable.hpp>
#include <pdal/util/Bounds.hpp>

namespace pdal
{

class BOX3D;

// This is just a pass-through filter, which collects some data about
// the points that are fed through it
class PDAL_DLL InfoFilter : public Filter, public Streamable
Expand Down
2 changes: 1 addition & 1 deletion io/EptReader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@
#include <mutex>
#include <set>

#include <pdal/Bounds.hpp>
#include <pdal/Reader.hpp>
#include <pdal/Streamable.hpp>
#include <pdal/util/Bounds.hpp>

namespace Json
{
Expand Down
1 change: 1 addition & 0 deletions io/GDALWriter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

#include <algorithm>

#include <pdal/Bounds.hpp>
#include <pdal/FlexWriter.hpp>
#include <pdal/PointView.hpp>
#include <pdal/Streamable.hpp>
Expand Down
2 changes: 1 addition & 1 deletion io/LasHeader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

#include <pdal/Dimension.hpp>
#include <pdal/Log.hpp>
#include <pdal/util/Bounds.hpp>
#include <pdal/util/Box.hpp>
#include <pdal/util/Uuid.hpp>
#include <pdal/pdal_config.hpp>
#include <pdal/gitsha.h>
Expand Down
2 changes: 1 addition & 1 deletion io/private/EptSupport.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
#include <pdal/PointLayout.hpp>
#include <pdal/PointTable.hpp>
#include <pdal/Stage.hpp>
#include <pdal/util/Bounds.hpp>
#include <pdal/util/Box.hpp>
#include <pdal/util/Utils.hpp>

#include <arbiter/arbiter.hpp>
Expand Down
121 changes: 121 additions & 0 deletions pdal/Bounds.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/******************************************************************************
* Copyright (c) 2019, Hobu Inc. (info@hobu.co)
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following
* conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided
* with the distribution.
* * Neither the name of Hobu, Inc. names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
****************************************************************************/

#include <pdal/Bounds.hpp>

namespace
{

const double LOWEST = (std::numeric_limits<double>::lowest)();
const double HIGHEST = (std::numeric_limits<double>::max)();

}

namespace pdal
{

Bounds::Bounds(const BOX3D& box) : m_box(box)
{}


Bounds::Bounds(const BOX2D& box) : m_box(box)
{
m_box.minz = HIGHEST;
m_box.maxz = LOWEST;
}


// We don't allow implicit conversion from a BOX2D to BOX3D. Use the explicit
// BOX3D ctor that takes a BOX2D if that's what you want.
BOX3D Bounds::to3d() const
{
if (!is3d())
return BOX3D();
return m_box;
}


BOX2D Bounds::to2d() const
{
return m_box.to2d();
}


bool Bounds::is3d() const
{
return (m_box.minz != HIGHEST || m_box.maxz != LOWEST);
}


void Bounds::set(const BOX3D& box)
{
m_box = box;
}


void Bounds::set(const BOX2D& box)
{
m_box = BOX3D(box);
m_box.minz = HIGHEST;
m_box.maxz = LOWEST;
}

std::istream& operator>>(std::istream& in, Bounds& bounds)
{
std::streampos start = in.tellg();
BOX3D b3d;
in >> b3d;
if (in.fail())
{
in.clear();
in.seekg(start);
BOX2D b2d;
in >> b2d;
if (!in.fail())
bounds.set(b2d);
}
else
bounds.set(b3d);
return in;
}

std::ostream& operator<<(std::ostream& out, const Bounds& bounds)
{
if (bounds.is3d())
out << bounds.to3d();
else
out << bounds.to2d();
return out;
}

} // namespace pdal
74 changes: 74 additions & 0 deletions pdal/Bounds.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/******************************************************************************
* Copyright (c) 2019, Hobu Inc. (info@hobu.co)
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following
* conditions are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided
* with the distribution.
* * Neither the name of Hobu, Inc. nor the names of its contributors
* may be used to endorse or promote products derived from this
* software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
* OF SUCH DAMAGE.
****************************************************************************/

#pragma once

#include <pdal/util/Box.hpp>

namespace pdal
{

/**
Wrapper for BOX3D and BOX2D to allow extraction as either. Typically used
to facilitate streaming either a BOX2D or BOX3D
*/
class PDAL_DLL Bounds
{
public:
Bounds()
{}

explicit Bounds(const BOX3D& box);
explicit Bounds(const BOX2D& box);

BOX3D to3d() const;
BOX2D to2d() const;
bool is3d() const;

friend PDAL_DLL std::istream& operator >> (std::istream& in,
Bounds& bounds);
friend PDAL_DLL std::ostream& operator << (std::ostream& out,
const Bounds& bounds);

private:
BOX3D m_box;

void set(const BOX3D& box);
void set(const BOX2D& box);
};

PDAL_DLL std::istream& operator >> (std::istream& in, Bounds& bounds);
PDAL_DLL std::ostream& operator << (std::ostream& in, const Bounds& bounds);

} // namespace pdal

4 changes: 2 additions & 2 deletions pdal/EigenUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#include <pdal/KDIndex.hpp>
#include <pdal/PointView.hpp>
#include <pdal/SpatialReference.hpp>
#include <pdal/util/Bounds.hpp>
#include <pdal/util/Box.hpp>
#include <pdal/util/Utils.hpp>

#include <Eigen/Dense>
Expand All @@ -58,7 +58,7 @@ Eigen::Vector3d computeCentroid(PointView& view,
const std::vector<PointId>& ids)
{
using namespace Eigen;

double mx, my, mz;
mx = my = mz = 0.0;
point_count_t n(0);
Expand Down
8 changes: 4 additions & 4 deletions pdal/EigenUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
#pragma once

#include <pdal/pdal_internal.hpp>
#include <pdal/util/Bounds.hpp>
#include <pdal/Metadata.hpp>

#include <Eigen/Dense>
Expand All @@ -45,6 +44,7 @@

namespace pdal
{
class BOX2D;
class PointView;
class SpatialReference;

Expand Down Expand Up @@ -269,7 +269,7 @@ PDAL_DLL Eigen::MatrixXd createMaxMatrix2(PointView& view, int rows, int cols,
*/
PDAL_DLL Eigen::MatrixXd createMinMatrix(PointView& view, int rows, int cols,
double cell_size, BOX2D bounds);

/**
Find local minimum elevations by extended local minimum.
Expand Down Expand Up @@ -328,7 +328,7 @@ PDAL_DLL Eigen::MatrixXd matrixOpen(Eigen::MatrixXd data, int radius);
\param data the input raster.
\param rows the number of rows.
\param cols the number of cols.
\param iterations the number of iterations used to approximate a larger
\param iterations the number of iterations used to approximate a larger
structuring element.
\return the morphological dilation of the input raster.
*/
Expand All @@ -347,7 +347,7 @@ PDAL_DLL std::vector<double> dilateDiamond(std::vector<double> data,
\param data the input raster.
\param rows the number of rows.
\param cols the number of cols.
\param iterations the number of iterations used to approximate a larger
\param iterations the number of iterations used to approximate a larger
structuring element.
\return the morphological erosion of the input raster.
*/
Expand Down
15 changes: 6 additions & 9 deletions pdal/GDALUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,18 @@

#pragma once

#include <pdal/pdal_internal.hpp>
#include <pdal/Dimension.hpp>
#include <pdal/SpatialReference.hpp>
#include <pdal/util/Bounds.hpp>

#include <pdal/Log.hpp>

#include <array>
#include <functional>
#include <mutex>
#include <sstream>
#include <vector>

#include <pdal/pdal_internal.hpp>
#include <pdal/Dimension.hpp>
#include <pdal/Log.hpp>
#include <pdal/SpatialReference.hpp>
#include <pdal/util/Box.hpp>

#include <cpl_conv.h>
#include <gdal_priv.h>
#include <ogr_api.h>
Expand All @@ -59,8 +58,6 @@ class OGRGeometry;
namespace pdal
{

class SpatialReference;

namespace gdal
{

Expand Down
3 changes: 2 additions & 1 deletion pdal/Geometry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
#include <pdal/Log.hpp>
#include <pdal/PointRef.hpp>
#include <pdal/SpatialReference.hpp>
#include <pdal/util/Bounds.hpp>

#include <memory>

Expand All @@ -46,6 +45,8 @@ class OGRGeometry;
namespace pdal
{

class BOX3D;

class PDAL_DLL Geometry
{
protected:
Expand Down
1 change: 1 addition & 0 deletions pdal/Metadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

#include <pdal/Metadata.hpp>
#include <pdal/SpatialReference.hpp>
#include <pdal/util/Box.hpp>

namespace pdal
{
Expand Down
2 changes: 1 addition & 1 deletion pdal/Metadata.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

#include <pdal/pdal_internal.hpp>

#include <pdal/util/Bounds.hpp>
#include <pdal/util/Box.hpp>
#include <pdal/util/Utils.hpp>
#include <pdal/util/Uuid.hpp>

Expand Down
1 change: 1 addition & 0 deletions pdal/PDALUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <pdal/Metadata.hpp>
#include <pdal/Dimension.hpp>
#include <pdal/pdal_export.hpp>
#include <pdal/util/Box.hpp>
#include <pdal/util/Inserter.hpp>
#include <pdal/util/Extractor.hpp>

Expand Down

0 comments on commit 9aae090

Please sign in to comment.