Skip to content

Commit

Permalink
fix up filters.pcl to work with schema-less stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
hobu committed Aug 8, 2014
1 parent 3c13e3e commit 82dfff7
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 50 deletions.
45 changes: 15 additions & 30 deletions include/pdal/PCLConversions.hpp
Expand Up @@ -52,21 +52,11 @@ namespace
using namespace pdal;

template<typename CLOUDFETCH>
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
Expand All @@ -79,8 +69,7 @@ namespace pdal
* Converts PCD data to PDAL format.
*/
template <typename CloudT>
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<typename CloudT::PointType>::type
Expand All @@ -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<typename CloudT::PointType>::value && iDim)
if (pcl::traits::has_intensity<typename CloudT::PointType>::value)
{
for (size_t i = 0; i < cloud.points.size(); ++i)
{
Expand All @@ -110,7 +99,7 @@ void PCDtoPDAL(CloudT &cloud, PointBuffer& buf, DimensionPtr xDim,
pcl::for_each_type<FieldList>
(pcl::CopyIfFieldExists<typename CloudT::PointType, float>
(p, "intensity", hasIntensity, f));
buf.setField(iDim, i, f);
buf.setField(Dimension::Id::Intensity, i, f);
}
}
#endif
Expand All @@ -123,8 +112,7 @@ void PCDtoPDAL(CloudT &cloud, PointBuffer& buf, DimensionPtr xDim,
* Converts PDAL data to PCD format.
*/
template <typename CloudT>
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<typename CloudT::PointType>::type
Expand All @@ -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<int32_t>(xDim, i, false) *
xDim->getNumericScale();
double yd = data.getFieldAs<int32_t>(yDim, i, false) *
yDim->getNumericScale();
double zd = data.getFieldAs<double>(zDim, i, false) *
zDim->getNumericScale();
double xd = data.getFieldAs<double>(Dimension::Id::X, i);
double yd = data.getFieldAs<double>(Dimension::Id::Y, i);
double zd = data.getFieldAs<double>(Dimension::Id::Z, i);

This comment has been minimized.

Copy link
@chambbj

chambbj Aug 12, 2014

Member

@hobu @abellgithub This certainly looks much nicer. I'd still like the ability to back out the offset though. Once I start casting large coordinates (e.g., UTM nothing/easting in meters) down to floats (required for PCL), I'm going to lose precision.

This comment has been minimized.

Copy link
@abellgithub

abellgithub via email Aug 13, 2014

Contributor

typename CloudT::PointType p = cloud.points[i];
p.x = (float)xd;
Expand All @@ -154,11 +139,11 @@ void PDALtoPCD(PointBuffer& data, CloudT &cloud, DimensionPtr xDim,
}
}

if (pcl::traits::has_intensity<typename CloudT::PointType>::value && iDim)
if (pcl::traits::has_intensity<typename CloudT::PointType>::value)
{
for (size_t i = 0; i < cloud.points.size(); ++i)
{
float f = data.getFieldAs<float>(iDim, i);
float f = data.getFieldAs<float>(Dimension::Id::Intensity, i);

typename CloudT::PointType p = cloud.points[i];
pcl::for_each_type<FieldList>
Expand Down
38 changes: 18 additions & 20 deletions src/filters/PCLBlock.cpp
Expand Up @@ -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");

}


Expand All @@ -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<double>(m_xDim, 0) << ", " <<
input->getFieldAs<double>(m_yDim, 0) << ", " <<
input->getFieldAs<double>(m_zDim, 0) << std::endl;
log()->get(logDEBUG2) << "Process PCLBlock..." << std::endl;
log()->get(LogLevel::DEBUG2) << input->getFieldAs<double>(Dimension::Id::X, 0) << ", " <<
input->getFieldAs<double>(Dimension::Id::Y, 0) << ", " <<
input->getFieldAs<double>(Dimension::Id::Z, 0) << std::endl;
log()->get(LogLevel::DEBUG2) << "Process PCLBlock..." << std::endl;

// convert PointBuffer to PointNormal
typedef pcl::PointCloud<pcl::PointNormal> 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();
Expand Down Expand Up @@ -114,27 +111,28 @@ PointBufferSet PCLBlock::run(PointBufferPtr input)
pcl::Pipeline<pcl::PointNormal> 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);
pipeline.filter(*cloud_f);

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<double>(m_xDim, 0) << ", " <<
output->getFieldAs<double>(m_yDim, 0) << ", " <<
output->getFieldAs<double>(m_zDim, 0) << std::endl;
log()->get(LogLevel::DEBUG2) << output->size() << std::endl;
log()->get(LogLevel::DEBUG2) << output->getFieldAs<double>(Dimension::Id::X, 0) << ", " <<
output->getFieldAs<double>(Dimension::Id::Y, 0) << ", " <<
output->getFieldAs<double>(Dimension::Id::Z, 0) << std::endl;
#endif
return pbSet;
}
Expand Down

0 comments on commit 82dfff7

Please sign in to comment.