From 82dfff7876f1fd81effd8c445fd8f975a13741e4 Mon Sep 17 00:00:00 2001 From: Howard Butler Date: Fri, 8 Aug 2014 15:45:24 -0500 Subject: [PATCH] fix up filters.pcl to work with schema-less stuff --- include/pdal/PCLConversions.hpp | 45 +++++++++++---------------------- src/filters/PCLBlock.cpp | 38 +++++++++++++--------------- 2 files changed, 33 insertions(+), 50 deletions(-) diff --git a/include/pdal/PCLConversions.hpp b/include/pdal/PCLConversions.hpp index 747a57537c..015b1b95b2 100755 --- a/include/pdal/PCLConversions.hpp +++ b/include/pdal/PCLConversions.hpp @@ -52,21 +52,11 @@ namespace using namespace pdal; template -void setValues(PointBuffer& buf, DimensionPtr dim, size_t numPts, +void setValues(PointBuffer& buf, Dimension::Id::Enum dim, size_t numPts, CLOUDFETCH fetcher) { - switch (dim->getInterpretation()) - { - case dimension::Float: - case dimension::UnsignedInteger: - case dimension::SignedInteger: - for (size_t i = 0; i < numPts; ++i) - buf.setField(dim, i, fetcher(i) / dim->getNumericScale()); - break; - case dimension::Undefined: - throw pdal_error("Dimension data type unable to be scaled " - "in conversion from PCL to PDAL"); - } + for (size_t i = 0; i < numPts; ++i) + buf.setField(dim, i, fetcher(i)); } } //namespace @@ -79,8 +69,7 @@ namespace pdal * Converts PCD data to PDAL format. */ template -void PCDtoPDAL(CloudT &cloud, PointBuffer& buf, DimensionPtr xDim, - DimensionPtr yDim, DimensionPtr zDim, DimensionPtr iDim) +void PCDtoPDAL(CloudT &cloud, PointBuffer& buf) { #ifdef PDAL_HAVE_PCL typedef typename pcl::traits::fieldList::type @@ -94,12 +83,12 @@ void PCDtoPDAL(CloudT &cloud, PointBuffer& buf, DimensionPtr xDim, { return cloud.points[i].y; }; auto getZ = [&cloud](size_t i) { return cloud.points[i].z; }; - setValues(buf, xDim, cloud.points.size(), getX); - setValues(buf, yDim, cloud.points.size(), getY); - setValues(buf, zDim, cloud.points.size(), getZ); + setValues(buf, Dimension::Id::X, cloud.points.size(), getX); + setValues(buf, Dimension::Id::Y, cloud.points.size(), getY); + setValues(buf, Dimension::Id::Z, cloud.points.size(), getZ); } - if (pcl::traits::has_intensity::value && iDim) + if (pcl::traits::has_intensity::value) { for (size_t i = 0; i < cloud.points.size(); ++i) { @@ -110,7 +99,7 @@ void PCDtoPDAL(CloudT &cloud, PointBuffer& buf, DimensionPtr xDim, pcl::for_each_type (pcl::CopyIfFieldExists (p, "intensity", hasIntensity, f)); - buf.setField(iDim, i, f); + buf.setField(Dimension::Id::Intensity, i, f); } } #endif @@ -123,8 +112,7 @@ void PCDtoPDAL(CloudT &cloud, PointBuffer& buf, DimensionPtr xDim, * Converts PDAL data to PCD format. */ template -void PDALtoPCD(PointBuffer& data, CloudT &cloud, DimensionPtr xDim, - DimensionPtr yDim, DimensionPtr zDim, DimensionPtr iDim) +void PDALtoPCD(PointBuffer& data, CloudT &cloud) { #ifdef PDAL_HAVE_PCL typedef typename pcl::traits::fieldList::type @@ -139,12 +127,9 @@ void PDALtoPCD(PointBuffer& data, CloudT &cloud, DimensionPtr xDim, { for (size_t i = 0; i < cloud.points.size(); ++i) { - double xd = data.getFieldAs(xDim, i, false) * - xDim->getNumericScale(); - double yd = data.getFieldAs(yDim, i, false) * - yDim->getNumericScale(); - double zd = data.getFieldAs(zDim, i, false) * - zDim->getNumericScale(); + double xd = data.getFieldAs(Dimension::Id::X, i); + double yd = data.getFieldAs(Dimension::Id::Y, i); + double zd = data.getFieldAs(Dimension::Id::Z, i); typename CloudT::PointType p = cloud.points[i]; p.x = (float)xd; @@ -154,11 +139,11 @@ void PDALtoPCD(PointBuffer& data, CloudT &cloud, DimensionPtr xDim, } } - if (pcl::traits::has_intensity::value && iDim) + if (pcl::traits::has_intensity::value) { for (size_t i = 0; i < cloud.points.size(); ++i) { - float f = data.getFieldAs(iDim, i); + float f = data.getFieldAs(Dimension::Id::Intensity, i); typename CloudT::PointType p = cloud.points[i]; pcl::for_each_type diff --git a/src/filters/PCLBlock.cpp b/src/filters/PCLBlock.cpp index 4892712e56..8cf2d84a25 100644 --- a/src/filters/PCLBlock.cpp +++ b/src/filters/PCLBlock.cpp @@ -57,10 +57,7 @@ void PCLBlock::processOptions(const Options& options) void PCLBlock::ready(PointContext ctx) { - m_iDim = ctx.schema()->getDimension("Intensity"); - m_xDim = ctx.schema()->getDimension("X"); - m_yDim = ctx.schema()->getDimension("Y"); - m_zDim = ctx.schema()->getDimension("Z"); + } @@ -71,21 +68,21 @@ PointBufferSet PCLBlock::run(PointBufferPtr input) pbSet.insert(output); #ifdef PDAL_HAVE_PCL - bool logOutput = log()->getLevel() > logDEBUG1; + bool logOutput = log()->getLevel() > LogLevel::DEBUG1; if (logOutput) log()->floatPrecision(8); - log()->get(logDEBUG2) << input->getFieldAs(m_xDim, 0) << ", " << - input->getFieldAs(m_yDim, 0) << ", " << - input->getFieldAs(m_zDim, 0) << std::endl; - log()->get(logDEBUG2) << "Process PCLBlock..." << std::endl; + log()->get(LogLevel::DEBUG2) << input->getFieldAs(Dimension::Id::X, 0) << ", " << + input->getFieldAs(Dimension::Id::Y, 0) << ", " << + input->getFieldAs(Dimension::Id::Z, 0) << std::endl; + log()->get(LogLevel::DEBUG2) << "Process PCLBlock..." << std::endl; // convert PointBuffer to PointNormal typedef pcl::PointCloud Cloud; Cloud::Ptr cloud(new Cloud); - PDALtoPCD(*input, *cloud, m_xDim, m_yDim, m_zDim, m_iDim); + PDALtoPCD(*input, *cloud); - log()->get(logDEBUG2) << cloud->points[0].x << ", " << + log()->get(LogLevel::DEBUG2) << cloud->points[0].x << ", " << cloud->points[0].y << ", " << cloud->points[0].z << std::endl; int level = log()->getLevel(); @@ -114,8 +111,9 @@ PointBufferSet PCLBlock::run(PointBufferPtr input) pcl::Pipeline pipeline; pipeline.setInputCloud(cloud); pipeline.setFilename(m_filename); - pipeline.setOffsets(m_xDim->getNumericOffset(), m_yDim->getNumericOffset(), - m_zDim->getNumericOffset()); + // FIXME: pcl::Pipieline might need to be updated now that + // PDAL is always doubles for XYZ dimensions +// pipeline.setOffsets(m_xDim->getNumericOffset(), m_yDim->getNumericOffset(), m_zDim->getNumericOffset()); // create PointCloud for results Cloud::Ptr cloud_f(new Cloud); @@ -123,18 +121,18 @@ PointBufferSet PCLBlock::run(PointBufferPtr input) if (cloud_f->points.empty()) { - log()->get(logDEBUG2) << "Filtered cloud has no points!" << std::endl; + log()->get(LogLevel::DEBUG2) << "Filtered cloud has no points!" << std::endl; return pbSet; } - PCDtoPDAL(*cloud_f, *output, m_xDim, m_yDim, m_zDim, m_iDim); + PCDtoPDAL(*cloud_f, *output); - log()->get(logDEBUG2) << cloud->points.size() << " before, " << + log()->get(LogLevel::DEBUG2) << cloud->points.size() << " before, " << cloud_f->points.size() << " after" << std::endl; - log()->get(logDEBUG2) << output->size() << std::endl; - log()->get(logDEBUG2) << output->getFieldAs(m_xDim, 0) << ", " << - output->getFieldAs(m_yDim, 0) << ", " << - output->getFieldAs(m_zDim, 0) << std::endl; + log()->get(LogLevel::DEBUG2) << output->size() << std::endl; + log()->get(LogLevel::DEBUG2) << output->getFieldAs(Dimension::Id::X, 0) << ", " << + output->getFieldAs(Dimension::Id::Y, 0) << ", " << + output->getFieldAs(Dimension::Id::Z, 0) << std::endl; #endif return pbSet; }