filter.h
/*
* Software License Agreement (BSD License)
*
* Point Cloud Library (PCL) - www.pointclouds.org
* Copyright (c) 2010-2011, 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_FILTER_H_
#define PCL_FILTER_H_
#include <pcl/pcl_base.h>
#include <pcl/conversions.h>
#include <pcl/filters/boost.h>
#include <cfloat>
#include <pcl/PointIndices.h>
namespace pcl
{
/** \brief Removes points with x, y, or z equal to NaN
* \param[in] cloud_in the input point cloud
* \param[out] cloud_out the input point cloud
* \param[out] index the mapping (ordered): cloud_out.points[i] = cloud_in.points[index[i]]
* \note The density of the point cloud is lost.
* \note Can be called with cloud_in == cloud_out
* \ingroup filters
*/
template<typename PointT> void
removeNaNFromPointCloud (const pcl::PointCloud<PointT> &cloud_in,
pcl::PointCloud<PointT> &cloud_out,
std::vector<int> &index);
/** \brief Removes points that have their normals invalid (i.e., equal to NaN)
* \param[in] cloud_in the input point cloud
* \param[out] cloud_out the input point cloud
* \param[out] index the mapping (ordered): cloud_out.points[i] = cloud_in.points[index[i]]
* \note The density of the point cloud is lost.
* \note Can be called with cloud_in == cloud_out
* \ingroup filters
*/
template<typename PointT> void
removeNaNNormalsFromPointCloud (const pcl::PointCloud<PointT> &cloud_in,
pcl::PointCloud<PointT> &cloud_out,
std::vector<int> &index);
////////////////////////////////////////////////////////////////////////////////////////////
/** \brief Filter represents the base filter class. All filters must inherit from this interface.
* \author Radu B. Rusu
* \ingroup filters
*/
template<typename PointT>
class Filter : public PCLBase<PointT>
{
public:
using PCLBase<PointT>::indices_;
using PCLBase<PointT>::input_;
typedef boost::shared_ptr< Filter<PointT> > Ptr;
typedef boost::shared_ptr< const Filter<PointT> > ConstPtr;
typedef pcl::PointCloud<PointT> PointCloud;
typedef typename PointCloud::Ptr PointCloudPtr;
typedef typename PointCloud::ConstPtr PointCloudConstPtr;
/** \brief Empty constructor.
* \param[in] extract_removed_indices set to true if the filtered data indices should be saved in a
* separate list. Default: false.
*/
Filter (bool extract_removed_indices = false) :
removed_indices_ (new std::vector<int>),
filter_name_ (),
extract_removed_indices_ (extract_removed_indices)
{
}
/** \brief Empty destructor */
virtual ~Filter () {}
/** \brief Get the point indices being removed */
inline IndicesConstPtr const
getRemovedIndices ()
{
return (removed_indices_);
}
/** \brief Get the point indices being removed
* \param[out] pi the resultant point indices that have been removed
*/
inline void
getRemovedIndices (PointIndices &pi)
{
pi.indices = *removed_indices_;
}
/** \brief Calls the filtering method and returns the filtered dataset in output.
* \param[out] output the resultant filtered point cloud dataset
*/
inline void
filter (PointCloud &output)
{
if (!initCompute ())
return;
// Resize the output dataset
//if (output.points.size () != indices_->size ())
// output.points.resize (indices_->size ());
// Copy header at a minimum
output.header = input_->header;
output.sensor_origin_ = input_->sensor_origin_;
output.sensor_orientation_ = input_->sensor_orientation_;
// Apply the actual filter
applyFilter (output);
deinitCompute ();
}
protected:
using PCLBase<PointT>::initCompute;
using PCLBase<PointT>::deinitCompute;
/** \brief Indices of the points that are removed */
IndicesPtr removed_indices_;
/** \brief The filter name. */
std::string filter_name_;
/** \brief Set to true if we want to return the indices of the removed points. */
bool extract_removed_indices_;
/** \brief Abstract filter method.
*
* The implementation needs to set output.{points, width, height, is_dense}.
*
* \param[out] output the resultant filtered point cloud
*/
virtual void
applyFilter (PointCloud &output) = 0;
/** \brief Get a string representation of the name of this class. */
inline const std::string&
getClassName () const
{
return (filter_name_);
}
};
////////////////////////////////////////////////////////////////////////////////////////////
/** \brief Filter represents the base filter class. All filters must inherit from this interface.
* \author Radu B. Rusu
* \ingroup filters
*/
template<>
class PCL_EXPORTS Filter<pcl::PCLPointCloud2> : public PCLBase<pcl::PCLPointCloud2>
{
public:
typedef boost::shared_ptr< Filter<pcl::PCLPointCloud2> > Ptr;
typedef boost::shared_ptr< const Filter<pcl::PCLPointCloud2> > ConstPtr;
typedef pcl::PCLPointCloud2 PCLPointCloud2;
typedef PCLPointCloud2::Ptr PCLPointCloud2Ptr;
typedef PCLPointCloud2::ConstPtr PCLPointCloud2ConstPtr;
/** \brief Empty constructor.
* \param[in] extract_removed_indices set to true if the filtered data indices should be saved in a
* separate list. Default: false.
*/
Filter (bool extract_removed_indices = false) :
removed_indices_ (new std::vector<int>),
extract_removed_indices_ (extract_removed_indices),
filter_name_ ()
{
}
/** \brief Empty destructor */
virtual ~Filter () {}
/** \brief Get the point indices being removed */
inline IndicesConstPtr const
getRemovedIndices ()
{
return (removed_indices_);
}
/** \brief Get the point indices being removed
* \param[out] pi the resultant point indices that have been removed
*/
inline void
getRemovedIndices (PointIndices &pi)
{
pi.indices = *removed_indices_;
}
/** \brief Calls the filtering method and returns the filtered dataset in output.
* \param[out] output the resultant filtered point cloud dataset
*/
void
filter (PCLPointCloud2 &output);
protected:
/** \brief Indices of the points that are removed */
IndicesPtr removed_indices_;
/** \brief Set to true if we want to return the indices of the removed points. */
bool extract_removed_indices_;
/** \brief The filter name. */
std::string filter_name_;
/** \brief Abstract filter method.
*
* The implementation needs to set output.{data, row_step, point_step, width, height, is_dense}.
*
* \param[out] output the resultant filtered point cloud
*/
virtual void
applyFilter (PCLPointCloud2 &output) = 0;
/** \brief Get a string representation of the name of this class. */
inline const std::string&
getClassName () const
{
return (filter_name_);
}
};
}
#ifdef PCL_NO_PRECOMPILE
#include <pcl/filters/impl/filter.hpp>
#endif
#endif //#ifndef PCL_FILTER_H_
pcl::removeNaNNormalsFromPointCloud
void removeNaNNormalsFromPointCloud(const pcl::PointCloud< PointT > &cloud_in, pcl::PointCloud< PointT > &cloud_out, std::vector< int > &index)
Removes points that have their normals invalid (i.e., equal to NaN)
Definition: filter.hpp:97
pcl::Filter< pcl::PCLPointCloud2 >::getRemovedIndices
void getRemovedIndices(PointIndices &pi)
Get the point indices being removed.
Definition: filter.h:223
pcl::Filter< pcl::PCLPointCloud2 >::PCLPointCloud2ConstPtr
PCLPointCloud2::ConstPtr PCLPointCloud2ConstPtr
Definition: filter.h:196
pcl::Filter< pcl::PCLPointCloud2 >::filter_name_
std::string filter_name_
The filter name.
Definition: filter.h:243
pcl::IndicesPtr
boost::shared_ptr< std::vector< int > > IndicesPtr
Definition: pcl_base.h:60
pcl
Definition: cloud_iterator.h:46
pcl::removeNaNFromPointCloud
void removeNaNFromPointCloud(const pcl::PointCloud< PointT > &cloud_in, pcl::PointCloud< PointT > &cloud_out, std::vector< int > &index)
Removes points with x, y, or z equal to NaN.
Definition: filter.hpp:46
pcl::Filter::PointCloud
pcl::PointCloud< PointT > PointCloud
Definition: filter.h:93
pcl::Filter::~Filter
virtual ~Filter()
Empty destructor.
Definition: filter.h:109
pcl::Filter< pcl::PCLPointCloud2 >::PCLPointCloud2
pcl::PCLPointCloud2 PCLPointCloud2
Definition: filter.h:194
pcl::Filter< pcl::PCLPointCloud2 >::ConstPtr
boost::shared_ptr< const Filter< pcl::PCLPointCloud2 > > ConstPtr
Definition: filter.h:192
std
Definition: multi_grid_octree_data.hpp:45
pcl::PointIndices::indices
std::vector< int > indices
Definition: PointIndices.h:19
pcl::Filter::filter
void filter(PointCloud &output)
Calls the filtering method and returns the filtered dataset in output.
Definition: filter.h:131
pcl::Filter::Filter
Filter(bool extract_removed_indices=false)
Empty constructor.
Definition: filter.h:101
pcl::Filter::Ptr
boost::shared_ptr< Filter< PointT > > Ptr
Definition: filter.h:89
pcl::PCLPointCloud2::Ptr
boost::shared_ptr< ::pcl::PCLPointCloud2 > Ptr
Definition: PCLPointCloud2.h:51
pcl::PCLBase::initCompute
bool initCompute()
This method should get called before starting the actual computation.
Definition: pcl_base.hpp:139
pcl::PointCloud::Ptr
boost::shared_ptr< PointCloud< PointT > > Ptr
Definition: point_cloud.h:428
pcl::PointCloud::sensor_origin_
Eigen::Vector4f sensor_origin_
Sensor acquisition pose (origin/translation).
Definition: point_cloud.h:421
pcl::Filter< pcl::PCLPointCloud2 >::Filter
Filter(bool extract_removed_indices=false)
Empty constructor.
Definition: filter.h:202
pcl::PointIndices
Definition: PointIndices.h:12
pcl::Filter
Filter represents the base filter class.
Definition: filter.h:83
pcl::Filter::getRemovedIndices
IndicesConstPtr const getRemovedIndices()
Get the point indices being removed.
Definition: filter.h:113
pcl::Filter::getRemovedIndices
void getRemovedIndices(PointIndices &pi)
Get the point indices being removed.
Definition: filter.h:122
pcl::Filter< pcl::PCLPointCloud2 >::getRemovedIndices
IndicesConstPtr const getRemovedIndices()
Get the point indices being removed.
Definition: filter.h:214
pcl::PCLBase
PCL base class.
Definition: pcl_base.h:68
pcl::Filter::removed_indices_
IndicesPtr removed_indices_
Indices of the points that are removed.
Definition: filter.h:157
pcl::PointCloud::sensor_orientation_
Eigen::Quaternionf sensor_orientation_
Sensor acquisition pose (rotation).
Definition: point_cloud.h:423
pcl::PointCloud::ConstPtr
boost::shared_ptr< const PointCloud< PointT > > ConstPtr
Definition: point_cloud.h:429
pcl::Filter::PointCloudConstPtr
PointCloud::ConstPtr PointCloudConstPtr
Definition: filter.h:95
pcl::PCLPointCloud2::ConstPtr
boost::shared_ptr< ::pcl::PCLPointCloud2 const > ConstPtr
Definition: PCLPointCloud2.h:52
pcl::PCLBase::deinitCompute
bool deinitCompute()
This method should get called after finishing the actual computation.
Definition: pcl_base.hpp:174
pcl::PointCloud
PointCloud represents the base class in PCL for storing collections of 3D points. ...
Definition: projection_matrix.h:53
pcl::PointCloud::header
pcl::PCLHeader header
The point cloud header.
Definition: point_cloud.h:407
pcl::Filter< pcl::PCLPointCloud2 >::Ptr
boost::shared_ptr< Filter< pcl::PCLPointCloud2 > > Ptr
Definition: filter.h:191
pcl::IndicesConstPtr
boost::shared_ptr< const std::vector< int > > IndicesConstPtr
Definition: pcl_base.h:61
pcl::Filter< pcl::PCLPointCloud2 >::extract_removed_indices_
bool extract_removed_indices_
Set to true if we want to return the indices of the removed points.
Definition: filter.h:240
pcl::Filter::extract_removed_indices_
bool extract_removed_indices_
Set to true if we want to return the indices of the removed points.
Definition: filter.h:163
pcl::Filter< pcl::PCLPointCloud2 >::PCLPointCloud2Ptr
PCLPointCloud2::Ptr PCLPointCloud2Ptr
Definition: filter.h:195
pcl::PCLPointCloud2
Definition: PCLPointCloud2.h:20
pcl::Filter::PointCloudPtr
PointCloud::Ptr PointCloudPtr
Definition: filter.h:94
pcl::Filter::applyFilter
virtual void applyFilter(PointCloud &output)=0
Abstract filter method.
pcl::Filter< pcl::PCLPointCloud2 >::~Filter
virtual ~Filter()
Empty destructor.
Definition: filter.h:210
pcl::PCLBase::input_
PointCloudConstPtr input_
The input point cloud dataset.
Definition: pcl_base.h:150
pcl::Filter::filter_name_
std::string filter_name_
The filter name.
Definition: filter.h:160
pcl::Filter< pcl::PCLPointCloud2 >::getClassName
const std::string & getClassName() const
Get a string representation of the name of this class.
Definition: filter.h:256
pcl::Filter::ConstPtr
boost::shared_ptr< const Filter< PointT > > ConstPtr
Definition: filter.h:90
pcl::Filter::getClassName
const std::string & getClassName() const
Get a string representation of the name of this class.
Definition: filter.h:176
pcl::Filter< pcl::PCLPointCloud2 >::removed_indices_
IndicesPtr removed_indices_
Indices of the points that are removed.
Definition: filter.h:237