convolution_3d.h
/*
* Software License Agreement (BSD License)
*
* Point Cloud Library (PCL) - www.pointclouds.org
* Copyright (c) 2010-2012, Willow Garage, Inc.
*
* 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 the copyright holder(s) 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.
*
* $Id$
*
*/
#ifndef PCL_FILTERS_CONVOLUTION_3D_H
#define PCL_FILTERS_CONVOLUTION_3D_H
#include <pcl/pcl_base.h>
#include <pcl/filters/boost.h>
#include <pcl/search/pcl_search.h>
namespace pcl
{
namespace filters
{
/** \brief Class ConvolvingKernel base class for all convolving kernels
* \ingroup filters
*/
template<typename PointInT, typename PointOutT>
class ConvolvingKernel
{
public:
typedef boost::shared_ptr<ConvolvingKernel<PointInT, PointOutT> > Ptr;
typedef boost::shared_ptr<const ConvolvingKernel<PointInT, PointOutT> > ConstPtr;
typedef typename PointCloud<PointInT>::ConstPtr PointCloudInConstPtr;
/// \brief empty constructor
ConvolvingKernel () {}
/// \brief empty destructor
virtual ~ConvolvingKernel () {}
/** \brief Set input cloud
* \param[in] input source point cloud
*/
void
setInputCloud (const PointCloudInConstPtr& input) { input_ = input; }
/** \brief Convolve point at the center of this local information
* \param[in] indices indices of the point in the source point cloud
* \param[in] distances euclidean distance squared from the query point
* \return the convolved point
*/
virtual PointOutT
operator() (const std::vector<int>& indices, const std::vector<float>& distances) = 0;
/** \brief Must call this methode before doing any computation
* \note make sure to override this with at least
* \code
* bool initCompute ()
* {
* return (true);
* }
* \endcode
* in your kernel interface, else you are going nowhere!
*/
virtual bool
initCompute () { return false; }
/** \brief Utility function that annihilates a point making it fail the \ref pcl::isFinite test
* \param p point to annihilate
*/
static void
makeInfinite (PointOutT& p)
{
p.x = p.y = p.z = std::numeric_limits<float>::quiet_NaN ();
}
protected:
/// source cloud
PointCloudInConstPtr input_;
};
/** \brief Gaussian kernel implementation interface
* Use this as implementation reference
* \ingroup filters
*/
template<typename PointInT, typename PointOutT>
class GaussianKernel : public ConvolvingKernel <PointInT, PointOutT>
{
public:
using ConvolvingKernel<PointInT, PointOutT>::initCompute;
using ConvolvingKernel<PointInT, PointOutT>::input_;
using ConvolvingKernel<PointInT, PointOutT>::operator ();
using ConvolvingKernel<PointInT, PointOutT>::makeInfinite;
typedef boost::shared_ptr<GaussianKernel<PointInT, PointOutT> > Ptr;
typedef boost::shared_ptr<GaussianKernel<PointInT, PointOutT> > ConstPtr;
/** Default constructor */
GaussianKernel ()
: ConvolvingKernel <PointInT, PointOutT> ()
, sigma_ (0)
, threshold_ (std::numeric_limits<float>::infinity ())
{}
virtual ~GaussianKernel () {}
/** Set the sigma parameter of the Gaussian
* \param[in] sigma
*/
inline void
setSigma (float sigma) { sigma_ = sigma; }
/** Set the distance threshold relative to a sigma factor i.e. points such as
* ||pi - q|| > sigma_coefficient^2 * sigma^2 are not considered.
*/
inline void
setThresholdRelativeToSigma (float sigma_coefficient)
{
sigma_coefficient_.reset (sigma_coefficient);
}
/** Set the distance threshold such as pi, ||pi - q|| > threshold are not considered. */
inline void
setThreshold (float threshold) { threshold_ = threshold; }
/** Must call this methode before doing any computation */
bool initCompute ();
virtual PointOutT
operator() (const std::vector<int>& indices, const std::vector<float>& distances);
protected:
float sigma_;
float sigma_sqr_;
float threshold_;
boost::optional<float> sigma_coefficient_;
};
/** \brief Gaussian kernel implementation interface with RGB channel handling
* Use this as implementation reference
* \ingroup filters
*/
template<typename PointInT, typename PointOutT>
class GaussianKernelRGB : public GaussianKernel <PointInT, PointOutT>
{
public:
using GaussianKernel<PointInT, PointOutT>::initCompute;
using GaussianKernel<PointInT, PointOutT>::input_;
using GaussianKernel<PointInT, PointOutT>::operator ();
using GaussianKernel<PointInT, PointOutT>::makeInfinite;
using GaussianKernel<PointInT, PointOutT>::sigma_sqr_;
using GaussianKernel<PointInT, PointOutT>::threshold_;
typedef boost::shared_ptr<GaussianKernelRGB<PointInT, PointOutT> > Ptr;
typedef boost::shared_ptr<GaussianKernelRGB<PointInT, PointOutT> > ConstPtr;
/** Default constructor */
GaussianKernelRGB ()
: GaussianKernel <PointInT, PointOutT> ()
{}
~GaussianKernelRGB () {}
PointOutT
operator() (const std::vector<int>& indices, const std::vector<float>& distances);
};
/** Convolution3D handles the non organized case where width and height are unknown or if you
* are only interested in convolving based on local neighborhood information.
* The convolving kernel MUST be a radial symmetric and implement \ref ConvolvingKernel
* interface.
*/
template <typename PointIn, typename PointOut, typename KernelT>
class Convolution3D : public pcl::PCLBase <PointIn>
{
public:
typedef typename pcl::PointCloud<PointIn> PointCloudIn;
typedef typename PointCloudIn::ConstPtr PointCloudInConstPtr;
typedef typename pcl::search::Search<PointIn> KdTree;
typedef typename pcl::search::Search<PointIn>::Ptr KdTreePtr;
typedef typename pcl::PointCloud<PointOut> PointCloudOut;
typedef boost::shared_ptr<Convolution3D<PointIn, PointOut, KernelT> > Ptr;
typedef boost::shared_ptr<Convolution3D<PointIn, PointOut, KernelT> > ConstPtr;
using pcl::PCLBase<PointIn>::indices_;
using pcl::PCLBase<PointIn>::input_;
/** \brief Constructor */
Convolution3D ();
/** \brief Empty destructor */
~Convolution3D () {}
/** \brief Initialize the scheduler and set the number of threads to use.
* \param nr_threads the number of hardware threads to use (0 sets the value back to automatic)
*/
inline void
setNumberOfThreads (unsigned int nr_threads = 0) { threads_ = nr_threads; }
/** \brief Set convolving kernel
* \param[in] kernel convolving element
*/
inline void
setKernel (const KernelT& kernel) { kernel_ = kernel; }
/** \brief Provide a pointer to the input dataset that we need to estimate features at every point for.
* \param cloud the const boost shared pointer to a PointCloud message
*/
inline void
setSearchSurface (const PointCloudInConstPtr &cloud) { surface_ = cloud; }
/** \brief Get a pointer to the surface point cloud dataset. */
inline PointCloudInConstPtr
getSearchSurface () { return (surface_); }
/** \brief Provide a pointer to the search object.
* \param tree a pointer to the spatial search object.
*/
inline void
setSearchMethod (const KdTreePtr &tree) { tree_ = tree; }
/** \brief Get a pointer to the search method used. */
inline KdTreePtr
getSearchMethod () { return (tree_); }
/** \brief Set the sphere radius that is to be used for determining the nearest neighbors
* \param radius the sphere radius used as the maximum distance to consider a point a neighbor
*/
inline void
setRadiusSearch (double radius) { search_radius_ = radius; }
/** \brief Get the sphere radius used for determining the neighbors. */
inline double
getRadiusSearch () { return (search_radius_); }
/** Convolve point cloud.
* \param[out] output the convolved cloud
*/
void
convolve (PointCloudOut& output);
protected:
/** \brief initialize computation */
bool initCompute ();
/** \brief An input point cloud describing the surface that is to be used for nearest neighbors estimation. */
PointCloudInConstPtr surface_;
/** \brief A pointer to the spatial search object. */
KdTreePtr tree_;
/** \brief The nearest neighbors search radius for each point. */
double search_radius_;
/** \brief number of threads */
unsigned int threads_;
/** \brief convlving kernel */
KernelT kernel_;
};
}
}
#include <pcl/filters/impl/convolution_3d.hpp>
#endif // PCL_FILTERS_CONVOLUTION_3D_H
pcl::filters::Convolution3D::KdTree
pcl::search::Search< PointIn > KdTree
Definition: convolution_3d.h:205
pcl::filters::GaussianKernelRGB::Ptr
boost::shared_ptr< GaussianKernelRGB< PointInT, PointOutT > > Ptr
Definition: convolution_3d.h:180
pcl::filters::GaussianKernelRGB::ConstPtr
boost::shared_ptr< GaussianKernelRGB< PointInT, PointOutT > > ConstPtr
Definition: convolution_3d.h:181
pcl::filters::GaussianKernel::Ptr
boost::shared_ptr< GaussianKernel< PointInT, PointOutT > > Ptr
Definition: convolution_3d.h:122
pcl::filters::Convolution3D::PointCloudIn
pcl::PointCloud< PointIn > PointCloudIn
Definition: convolution_3d.h:203
pcl::filters::GaussianKernel::sigma_sqr_
float sigma_sqr_
Definition: convolution_3d.h:161
pcl::filters::Convolution3D::tree_
KdTreePtr tree_
A pointer to the spatial search object.
Definition: convolution_3d.h:276
pcl::filters::Convolution3D::setRadiusSearch
void setRadiusSearch(double radius)
Set the sphere radius that is to be used for determining the nearest neighbors.
Definition: convolution_3d.h:256
pcl::filters::GaussianKernel::ConstPtr
boost::shared_ptr< GaussianKernel< PointInT, PointOutT > > ConstPtr
Definition: convolution_3d.h:123
pcl::filters::GaussianKernel::setThresholdRelativeToSigma
void setThresholdRelativeToSigma(float sigma_coefficient)
Set the distance threshold relative to a sigma factor i.e.
Definition: convolution_3d.h:144
pcl::filters::GaussianKernel::sigma_
float sigma_
Definition: convolution_3d.h:160
pcl::filters::Convolution3D::surface_
PointCloudInConstPtr surface_
An input point cloud describing the surface that is to be used for nearest neighbors estimation...
Definition: convolution_3d.h:273
pcl
Definition: cloud_iterator.h:46
pcl::filters::GaussianKernel::threshold_
float threshold_
Definition: convolution_3d.h:162
std
Definition: multi_grid_octree_data.hpp:45
pcl::filters::Convolution3D::kernel_
KernelT kernel_
convlving kernel
Definition: convolution_3d.h:285
pcl::filters::GaussianKernel::setThreshold
void setThreshold(float threshold)
Set the distance threshold such as pi, ||pi - q|| > threshold are not considered. ...
Definition: convolution_3d.h:151
pcl::filters::Convolution3D::PointCloudInConstPtr
PointCloudIn::ConstPtr PointCloudInConstPtr
Definition: convolution_3d.h:204
pcl::filters::GaussianKernel::sigma_coefficient_
boost::optional< float > sigma_coefficient_
Definition: convolution_3d.h:163
pcl::filters::Convolution3D::getRadiusSearch
double getRadiusSearch()
Get the sphere radius used for determining the neighbors.
Definition: convolution_3d.h:260
pcl::filters::ConvolvingKernel::Ptr
boost::shared_ptr< ConvolvingKernel< PointInT, PointOutT > > Ptr
Definition: convolution_3d.h:58
pcl::filters::ConvolvingKernel::ConstPtr
boost::shared_ptr< const ConvolvingKernel< PointInT, PointOutT > > ConstPtr
Definition: convolution_3d.h:59
pcl::filters::ConvolvingKernel::input_
PointCloudInConstPtr input_
source cloud
Definition: convolution_3d.h:107
pcl::filters::Convolution3D::setNumberOfThreads
void setNumberOfThreads(unsigned int nr_threads=0)
Initialize the scheduler and set the number of threads to use.
Definition: convolution_3d.h:224
pcl::filters::ConvolvingKernel::~ConvolvingKernel
virtual ~ConvolvingKernel()
empty destructor
Definition: convolution_3d.h:67
pcl::filters::GaussianKernelRGB
Gaussian kernel implementation interface with RGB channel handling Use this as implementation referen...
Definition: convolution_3d.h:171
pcl::filters::GaussianKernelRGB::GaussianKernelRGB
GaussianKernelRGB()
Default constructor.
Definition: convolution_3d.h:184
pcl::filters::Convolution3D
Convolution3D handles the non organized case where width and height are unknown or if you are only in...
Definition: convolution_3d.h:200
pcl::filters::Convolution3D::getSearchSurface
PointCloudInConstPtr getSearchSurface()
Get a pointer to the surface point cloud dataset.
Definition: convolution_3d.h:240
pcl::filters::Convolution3D::KdTreePtr
pcl::search::Search< PointIn >::Ptr KdTreePtr
Definition: convolution_3d.h:206
pcl::search::Search::Ptr
boost::shared_ptr< pcl::search::Search< PointT > > Ptr
Definition: search.h:81
pcl::filters::Convolution3D::PointCloudOut
pcl::PointCloud< PointOut > PointCloudOut
Definition: convolution_3d.h:207
pcl::filters::Convolution3D::setKernel
void setKernel(const KernelT &kernel)
Set convolving kernel.
Definition: convolution_3d.h:230
pcl::PCLBase
PCL base class.
Definition: pcl_base.h:68
pcl::filters::Convolution3D::search_radius_
double search_radius_
The nearest neighbors search radius for each point.
Definition: convolution_3d.h:279
pcl::filters::GaussianKernel
Gaussian kernel implementation interface Use this as implementation reference.
Definition: convolution_3d.h:115
pcl::filters::ConvolvingKernel::makeInfinite
static void makeInfinite(PointOutT &p)
Utility function that annihilates a point making it fail the pcl::isFinite test.
Definition: convolution_3d.h:100
pcl::PointCloud::ConstPtr
boost::shared_ptr< const PointCloud< PointT > > ConstPtr
Definition: point_cloud.h:429
pcl::filters::ConvolvingKernel::operator()
virtual PointOutT operator()(const std::vector< int > &indices, const std::vector< float > &distances)=0
Convolve point at the center of this local information.
pcl::PointCloud
PointCloud represents the base class in PCL for storing collections of 3D points. ...
Definition: projection_matrix.h:53
pcl::filters::ConvolvingKernel
Class ConvolvingKernel base class for all convolving kernels.
Definition: convolution_3d.h:55
pcl::filters::GaussianKernelRGB::~GaussianKernelRGB
~GaussianKernelRGB()
Definition: convolution_3d.h:188
pcl::filters::Convolution3D::setSearchMethod
void setSearchMethod(const KdTreePtr &tree)
Provide a pointer to the search object.
Definition: convolution_3d.h:246
pcl::filters::Convolution3D::Ptr
boost::shared_ptr< Convolution3D< PointIn, PointOut, KernelT > > Ptr
Definition: convolution_3d.h:208
pcl::filters::Convolution3D::setSearchSurface
void setSearchSurface(const PointCloudInConstPtr &cloud)
Provide a pointer to the input dataset that we need to estimate features at every point for...
Definition: convolution_3d.h:236
pcl::filters::Convolution3D::ConstPtr
boost::shared_ptr< Convolution3D< PointIn, PointOut, KernelT > > ConstPtr
Definition: convolution_3d.h:209
pcl::filters::Convolution3D::getSearchMethod
KdTreePtr getSearchMethod()
Get a pointer to the search method used.
Definition: convolution_3d.h:250
pcl::filters::GaussianKernel::~GaussianKernel
virtual ~GaussianKernel()
Definition: convolution_3d.h:132
pcl::filters::GaussianKernel::GaussianKernel
GaussianKernel()
Default constructor.
Definition: convolution_3d.h:126
pcl::filters::ConvolvingKernel::setInputCloud
void setInputCloud(const PointCloudInConstPtr &input)
Set input cloud.
Definition: convolution_3d.h:73
pcl::filters::ConvolvingKernel::ConvolvingKernel
ConvolvingKernel()
empty constructor
Definition: convolution_3d.h:64
pcl::filters::GaussianKernel::setSigma
void setSigma(float sigma)
Set the sigma parameter of the Gaussian.
Definition: convolution_3d.h:138
pcl::filters::Convolution3D::threads_
unsigned int threads_
number of threads
Definition: convolution_3d.h:282
pcl::filters::Convolution3D::~Convolution3D
~Convolution3D()
Empty destructor.
Definition: convolution_3d.h:218
pcl::filters::ConvolvingKernel::PointCloudInConstPtr
PointCloud< PointInT >::ConstPtr PointCloudInConstPtr
Definition: convolution_3d.h:61
pcl::filters::ConvolvingKernel::initCompute
virtual bool initCompute()
Must call this methode before doing any computation.
Definition: convolution_3d.h:94
pcl::search::Search< PointIn >