Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into readers.numpy
Browse files Browse the repository at this point in the history
  • Loading branch information
hobu committed Mar 12, 2018
2 parents b66838e + 444681a commit 3b0bce1
Show file tree
Hide file tree
Showing 13 changed files with 189 additions and 68 deletions.
24 changes: 21 additions & 3 deletions io/BpfReader.cpp
Expand Up @@ -135,13 +135,31 @@ void BpfReader::initialize()
Utils::toString(zone));
code += (zone < 10 ? "0" : "") + Utils::toString(zone);
}
else if (m_header.m_coordType == static_cast<int>(BpfCoordType::TCR))
{
// TCR is ECEF meters, or EPSG:4978
// According to the 1.0 spec, the m_coordId must be 1 to be
// valid.
if (m_header.m_coordId == 1)
code = std::string("EPSG:4978");
else
{
std::ostringstream oss;
oss << "BPF has ECEF/TCR coordinate type defined, but the ID of '"
<< m_header.m_coordId << "' is invalid";
throwError(oss.str());
}
}
else
{
// BPF supports something called Terrestrial Centered Rotational
// (BpfCoordType::TCR) and East North Up (BpfCoordType::ENU)
// BPF also supports something East North Up (BpfCoordType::ENU)
// which we can figure out when we run into a file with these
// coordinate systems.
throwError("BPF file contains unsupported coordinate system");
std::ostringstream oss;
oss << "BPF file contains unsupported coordinate system with "
<< "coordinate type: '" << m_header.m_coordType
<< "' and coordinate id: '" << m_header.m_coordId << "'";
throwError(oss.str());
}
SpatialReference srs(code);
setSpatialReference(srs);
Expand Down
47 changes: 29 additions & 18 deletions io/GDALGrid.cpp
Expand Up @@ -48,6 +48,15 @@ GDALGrid::GDALGrid(size_t width, size_t height, double edgeLength,
m_width(width), m_height(height), m_windowSize(windowSize),
m_edgeLength(edgeLength), m_radius(radius), m_outputTypes(outputTypes)
{
if (width > std::numeric_limits<int>::max() ||
height > std::numeric_limits<int>::max())
{
std::ostringstream oss;
oss << "Grid width or height is too large. Width and height are "
"limited to " << std::numeric_limits<int>::max() << " cells."
"Try setting bounds or increasing resolution.";
throw error(oss.str());
}
size_t size(width * height);

m_count.reset(new DataVec(size));
Expand Down Expand Up @@ -199,9 +208,11 @@ void GDALGrid::addPoint(double x, double y, double z)
// <- v


int i, j;
int iStart, jStart;
// First quadrant;
int i = iOrigin + 1;
int j = jOrigin;
i = iStart = std::max(0, iOrigin + 1);
j = std::min(jOrigin, int(m_height - 1));
while (i < (int)m_width && j >= 0)
{
double d = distance(i, j, x, y);
Expand All @@ -212,16 +223,16 @@ void GDALGrid::addPoint(double x, double y, double z)
}
else
{
if (i == iOrigin + 1)
if (i == iStart)
break;
i = iOrigin + 1;
i = iStart;
j--;
}
}

// Second quadrant;
i = iOrigin;
j = jOrigin - 1;
i = std::min(iOrigin, int(m_width - 1));
j = jStart = std::min(jOrigin - 1, int(m_height - 1));
while (i >= 0 && j >= 0)
{
double d = distance(i, j, x, y);
Expand All @@ -232,16 +243,16 @@ void GDALGrid::addPoint(double x, double y, double z)
}
else
{
if (j == jOrigin - 1)
if (j == jStart)
break;
j = jOrigin - 1;
j = jStart;
i--;
}
}

// Third quadrant;
i = iOrigin - 1;
j = jOrigin;
i = iStart = std::min(iOrigin - 1, int(m_width - 1));
j = std::max(jOrigin, 0);
while (i >= 0 && j < (int)m_height)
{
double d = distance(i, j, x, y);
Expand All @@ -252,15 +263,15 @@ void GDALGrid::addPoint(double x, double y, double z)
}
else
{
if (i == iOrigin - 1)
if (i == iStart)
break;
i = iOrigin - 1;
i = iStart;
j++;
}
}
// Fourth quadrant;
i = iOrigin;
j = jOrigin + 1;
i = std::max(iOrigin, 0);
j = jStart = std::max(jOrigin + 1, 0);
while (i < (int)m_width && j < (int)m_height)
{
double d = distance(i, j, x, y);
Expand All @@ -271,9 +282,9 @@ void GDALGrid::addPoint(double x, double y, double z)
}
else
{
if (j == jOrigin + 1)
if (j == jStart)
break;
j = jOrigin + 1;
j = jStart;
i++;
}
}
Expand All @@ -283,11 +294,11 @@ void GDALGrid::addPoint(double x, double y, double z)
double d = distance(iOrigin, jOrigin, x, y);
if (d < m_radius &&
iOrigin >= 0 && jOrigin >= 0 &&
iOrigin < (int)m_width && jOrigin <= (int)m_height)
iOrigin < (int)m_width && jOrigin < (int)m_height)
update(iOrigin, jOrigin, z, d);
}

void GDALGrid::update(int i, int j, double val, double dist)
void GDALGrid::update(size_t i, size_t j, double val, double dist)
{
// Once we determine that a point is close enough to a cell to count it,
// this function does the actual math. We use the value of the
Expand Down
2 changes: 1 addition & 1 deletion io/GDALGrid.hpp
Expand Up @@ -139,7 +139,7 @@ class GDALGrid
}

// Update cell at i, j with value at a distance.
void update(int i, int j, double val, double dist);
void update(size_t i, size_t j, double val, double dist);

// Fill cell at index \c i with the nondata value.
void fillNodata(size_t i);
Expand Down
11 changes: 9 additions & 2 deletions io/GDALWriter.cpp
Expand Up @@ -143,8 +143,15 @@ void GDALWriter::createGrid(BOX2D bounds)
m_curBounds = bounds;
size_t width = ((m_curBounds.maxx - m_curBounds.minx) / m_edgeLength) + 1;
size_t height = ((m_curBounds.maxy - m_curBounds.miny) / m_edgeLength) + 1;
m_grid.reset(new GDALGrid(width, height, m_edgeLength, m_radius,
m_outputTypes, m_windowSize));
try
{
m_grid.reset(new GDALGrid(width, height, m_edgeLength, m_radius,
m_outputTypes, m_windowSize));
}
catch (GDALGrid::error& err)
{
throwError(err.what());
}
}


Expand Down
2 changes: 1 addition & 1 deletion io/LasReader.cpp
Expand Up @@ -159,7 +159,7 @@ void LasReader::initializeLocal(PointTableRef table, MetadataNode& m)
{
try
{
m_extraDims = LasUtils::parse(m_extraDimSpec);
m_extraDims = LasUtils::parse(m_extraDimSpec, false);
}
catch (const LasUtils::error& err)
{
Expand Down
7 changes: 6 additions & 1 deletion io/LasUtils.cpp
Expand Up @@ -212,7 +212,7 @@ std::vector<IgnoreVLR> parseIgnoreVLRs(const StringList& ignored)
return ignoredVLRs;

}
std::vector<ExtraDim> parse(const StringList& dimString)
std::vector<ExtraDim> parse(const StringList& dimString, bool allOk)
{
std::vector<ExtraDim> extraDims;
bool all = false;
Expand All @@ -221,6 +221,11 @@ std::vector<ExtraDim> parse(const StringList& dimString)
{
if (dim == "all")
{
// We only accept all for LasWriter.
if (!allOk)
throw error("Invalid extra dimension specified: '" + dim +
"'. Need <dimension>=<type>. See documentation "
" for details.");
all = true;
continue;
}
Expand Down
2 changes: 1 addition & 1 deletion io/LasUtils.hpp
Expand Up @@ -171,7 +171,7 @@ struct error : public std::runtime_error
{}
};

std::vector<ExtraDim> parse(const StringList& dimString);
std::vector<ExtraDim> parse(const StringList& dimString, bool allOk);


struct IgnoreVLR
Expand Down
2 changes: 1 addition & 1 deletion io/LasWriter.cpp
Expand Up @@ -152,7 +152,7 @@ void LasWriter::initialize()
#endif
try
{
m_extraDims = LasUtils::parse(m_extraDimSpec);
m_extraDims = LasUtils::parse(m_extraDimSpec, true);
}
catch (const LasUtils::error& err)
{
Expand Down
41 changes: 21 additions & 20 deletions plugins/pcl/CMakeLists.txt
Expand Up @@ -34,16 +34,14 @@ set_package_properties(PCL PROPERTIES DESCRIPTION "Point Cloud Library"
URL "http://pointclouds.org" TYPE RECOMMENDED
PURPOSE "Enables PCD reader/writer, PCLVisualizer, PCLBlock filter, ICP filter, and ground, pcl, smooth, and view kernels")

set(INCLUDE_DIRS
${ROOT_DIR}
${PCL_INCLUDE_DIRS}
${CMAKE_CURRENT_LIST_DIR}
)

add_definitions(${PCL_DEFINITIONS})
if (NOT WIN32)
add_definitions("-fvisibility-inlines-hidden")
endif()
#
# This can cause problems if you inline some code that instantiates a static.
# I'm not sure why it was here, but I'm keeping it for now in case someone
# goes looking for it. - ABELL 3/18
#if (NOT WIN32)
# add_definitions("-fvisibility-inlines-hidden")
#endif()

# PCL's configuration clobbers Boost find_package - do it again
find_package(Boost QUIET 1.52 COMPONENTS program_options iostreams filesystem system thread)
Expand All @@ -57,7 +55,7 @@ PDAL_ADD_PLUGIN(pcd_reader_libname reader pcd
io/PcdReader.cpp
LINK_WITH ${PCL_LIBRARIES})
target_include_directories(${pcd_reader_libname} PRIVATE
${INCLUDE_DIRS})
${PCL_INCLUDE_DIRS})
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU" )
set_source_files_properties(io/PcdReader.cpp PROPERTIES COMPILE_FLAGS -Wno-pedantic)
endif()
Expand All @@ -71,7 +69,7 @@ PDAL_ADD_PLUGIN(pcd_writer_libname writer pcd
io/PcdWriter.cpp
LINK_WITH ${PCL_LIBRARIES})
target_include_directories(${pcd_writer_libname} PRIVATE
${INCLUDE_DIRS})
${PCL_INCLUDE_DIRS})
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU" )
set_source_files_properties(io/PcdWriter.cpp PROPERTIES COMPILE_FLAGS -Wno-pedantic)
endif()
Expand All @@ -89,23 +87,25 @@ PDAL_ADD_PLUGIN(pclblock_libname filter pclblock
)
target_include_directories(${pclblock_libname}
PRIVATE
${INCLUDE_DIRS}
${PCL_INCLUDE_DIRS}
${PDAL_JSONCPP_INCLUDE_DIR}
)

PDAL_ADD_PLUGIN(voxelgrid_filter_libname filter voxelgrid
FILES
filters/VoxelGridFilter.cpp
LINK_WITH ${PCL_LIBRARIES})
target_include_directories(${voxelgrid_filter_libname} PRIVATE
${INCLUDE_DIRS})
target_include_directories(${voxelgrid_filter_libname}
PRIVATE
${PCL_INCLUDE_DIRS}
)

PDAL_ADD_PLUGIN(movingleastsquares_filter_libname filter movingleastsquares
FILES
filters/MovingLeastSquaresFilter.cpp
LINK_WITH ${PCL_LIBRARIES})
target_include_directories(${movingleastsquares_filter_libname} PRIVATE
${INCLUDE_DIRS})
${PCL_INCLUDE_DIRS})
if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" OR CMAKE_CXX_COMPILER_ID MATCHES "GNU" )
set_source_files_properties(filters/MovingLeastSquaresFilter.cpp PROPERTIES COMPILE_FLAGS -Wno-pedantic)
endif()
Expand All @@ -116,14 +116,14 @@ PDAL_ADD_PLUGIN(gridprojection_filter_libname filter gridprojection
filters/GridProjectionFilter.cpp
LINK_WITH ${PCL_LIBRARIES})
target_include_directories(${gridprojection_filter_libname} PRIVATE
${INCLUDE_DIRS})
${PCL_INCLUDE_DIRS})

PDAL_ADD_PLUGIN(icp_filter_libname filter icp
FILES
filters/IcpFilter.cpp
LINK_WITH ${PCL_LIBRARIES})
target_include_directories(${icp_filter_libname} PRIVATE
${INCLUDE_DIRS})
${PCL_INCLUDE_DIRS})

#
# PCL Kernel
Expand All @@ -134,7 +134,7 @@ PDAL_ADD_PLUGIN(pcl_libname kernel pcl
LINK_WITH ${PCL_LIBRARIES} ${pclblock_libname})
target_include_directories(${pcl_libname} PRIVATE
${PDAL_IO_DIR}
${INCLUDE_DIRS})
${PCL_INCLUDE_DIRS})

#
# Smooth Kernel
Expand All @@ -145,7 +145,7 @@ PDAL_ADD_PLUGIN(smooth_libname kernel smooth
kernel/SmoothKernel.cpp
LINK_WITH ${PCL_LIBRARIES} ${pclblock_libname})
target_include_directories(${smooth_libname} PRIVATE
${INCLUDE_DIRS}
${PCL_INCLUDE_DIRS}
${PDAL_IO_DIR})

if (WITH_TESTS)
Expand All @@ -162,5 +162,6 @@ if (WITH_TESTS)
LINK_WITH
${icp_filter_libname}
)
target_include_directories(pdal_filters_icp_test PRIVATE ${INCLUDE_DIRS})
target_include_directories(pdal_filters_icp_test PRIVATE
${PCL_INCLUDE_DIRS})
endif()
4 changes: 2 additions & 2 deletions plugins/pcl/filters/IcpFilter.cpp
Expand Up @@ -32,8 +32,8 @@
* OF SUCH DAMAGE.
****************************************************************************/

#include "PCLConversions.hpp"
#include <filters/IcpFilter.hpp>
#include "../PCLConversions.hpp"
#include "IcpFilter.hpp"
#include <pcl/point_types.h>
#include <pcl/registration/icp.h>
#include <pdal/EigenUtils.hpp>
Expand Down
8 changes: 5 additions & 3 deletions plugins/pcl/test/IcpFilterTest.cpp
Expand Up @@ -34,12 +34,12 @@

#include "Support.hpp"
#include <Eigen/Dense>
#include <filters/IcpFilter.hpp>
#include <filters/TransformationFilter.hpp>
#include <io/LasReader.hpp>
#include <memory>
#include <pdal/pdal_test_main.hpp>
#include <pdal/EigenUtils.hpp>
#include <pdal/StageFactory.hpp>

namespace pdal
{
Expand All @@ -55,9 +55,11 @@ std::unique_ptr<LasReader> newReader()
return reader;
}

std::unique_ptr<IcpFilter> newFilter()
Stage* newFilter()
{
return std::unique_ptr<IcpFilter>(new IcpFilter());
static StageFactory f;

return f.createStage("filters.icp");
}

void checkPointsEqualReader(const PointViewSet& pointViewSet, double tolerance)
Expand Down

0 comments on commit 3b0bce1

Please sign in to comment.