passthrough.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$
*
*/
#pragma once
#include <pcl/filters/filter_indices.h>
namespace pcl
{
/** \brief @b PassThrough passes points in a cloud based on constraints for one particular field of the point type.
* \details Iterates through the entire input once, automatically filtering non-finite points and the points outside
* the interval specified by setFilterLimits(), which applies only to the field specified by setFilterFieldName().
* <br><br>
* Usage example:
* \code
* pcl::PassThrough<PointType> ptfilter (true); // Initializing with true will allow us to extract the removed indices
* ptfilter.setInputCloud (cloud_in);
* ptfilter.setFilterFieldName ("x");
* ptfilter.setFilterLimits (0.0, 1000.0);
* ptfilter.filter (*indices_x);
* // The indices_x array indexes all points of cloud_in that have x between 0.0 and 1000.0
* indices_rem = ptfilter.getRemovedIndices ();
* // The indices_rem array indexes all points of cloud_in that have x smaller than 0.0 or larger than 1000.0
* // and also indexes all non-finite points of cloud_in
* ptfilter.setIndices (indices_x);
* ptfilter.setFilterFieldName ("z");
* ptfilter.setFilterLimits (-10.0, 10.0);
* ptfilter.setNegative (true);
* ptfilter.filter (*indices_xz);
* // The indices_xz array indexes all points of cloud_in that have x between 0.0 and 1000.0 and z larger than 10.0 or smaller than -10.0
* ptfilter.setIndices (indices_xz);
* ptfilter.setFilterFieldName ("intensity");
* ptfilter.setFilterLimits (FLT_MIN, 0.5);
* ptfilter.setNegative (false);
* ptfilter.filter (*cloud_out);
* // The resulting cloud_out contains all points of cloud_in that are finite and have:
* // x between 0.0 and 1000.0, z larger than 10.0 or smaller than -10.0 and intensity smaller than 0.5.
* \endcode
* \author Radu Bogdan Rusu
* \ingroup filters
*/
template <typename PointT>
class PassThrough : public FilterIndices<PointT>
{
protected:
using PointCloud = typename FilterIndices<PointT>::PointCloud;
using PointCloudPtr = typename PointCloud::Ptr;
using PointCloudConstPtr = typename PointCloud::ConstPtr;
using FieldList = typename pcl::traits::fieldList<PointT>::type;
public:
using Ptr = shared_ptr<PassThrough<PointT> >;
using ConstPtr = shared_ptr<const PassThrough<PointT> >;
/** \brief Constructor.
* \param[in] extract_removed_indices Set to true if you want to be able to extract the indices of points being removed (default = false).
*/
PassThrough (bool extract_removed_indices = false) :
FilterIndices<PointT>::FilterIndices (extract_removed_indices),
filter_field_name_ (""),
filter_limit_min_ (FLT_MIN),
filter_limit_max_ (FLT_MAX)
{
filter_name_ = "PassThrough";
}
/** \brief Provide the name of the field to be used for filtering data.
* \details In conjunction with setFilterLimits(), points having values outside this interval for this field will be discarded.
* \param[in] field_name The name of the field that will be used for filtering.
*/
inline void
setFilterFieldName (const std::string &field_name)
{
filter_field_name_ = field_name;
}
/** \brief Retrieve the name of the field to be used for filtering data.
* \return The name of the field that will be used for filtering.
*/
inline std::string const
getFilterFieldName () const
{
return (filter_field_name_);
}
/** \brief Set the numerical limits for the field for filtering data.
* \details In conjunction with setFilterFieldName(), points having values outside this interval for this field will be discarded.
* \param[in] limit_min The minimum allowed field value (default = FLT_MIN).
* \param[in] limit_max The maximum allowed field value (default = FLT_MAX).
*/
inline void
setFilterLimits (const float &limit_min, const float &limit_max)
{
filter_limit_min_ = limit_min;
filter_limit_max_ = limit_max;
}
/** \brief Get the numerical limits for the field for filtering data.
* \param[out] limit_min The minimum allowed field value (default = FLT_MIN).
* \param[out] limit_max The maximum allowed field value (default = FLT_MAX).
*/
inline void
getFilterLimits (float &limit_min, float &limit_max) const
{
limit_min = filter_limit_min_;
limit_max = filter_limit_max_;
}
/** \brief Set to true if we want to return the data outside the interval specified by setFilterLimits (min, max)
* Default: false.
* \warning This method will be removed in the future. Use setNegative() instead.
* \param[in] limit_negative return data inside the interval (false) or outside (true)
*/
inline void
setFilterLimitsNegative (const bool limit_negative)
{
negative_ = limit_negative;
}
/** \brief Get whether the data outside the interval (min/max) is to be returned (true) or inside (false).
* \warning This method will be removed in the future. Use getNegative() instead.
* \param[out] limit_negative true if data \b outside the interval [min; max] is to be returned, false otherwise
*/
inline void
getFilterLimitsNegative (bool &limit_negative) const
{
limit_negative = negative_;
}
/** \brief Get whether the data outside the interval (min/max) is to be returned (true) or inside (false).
* \warning This method will be removed in the future. Use getNegative() instead.
* \return true if data \b outside the interval [min; max] is to be returned, false otherwise
*/
inline bool
getFilterLimitsNegative () const
{
return (negative_);
}
protected:
using PCLBase<PointT>::input_;
using PCLBase<PointT>::indices_;
using Filter<PointT>::filter_name_;
using Filter<PointT>::getClassName;
using FilterIndices<PointT>::negative_;
using FilterIndices<PointT>::keep_organized_;
using FilterIndices<PointT>::user_filter_value_;
using FilterIndices<PointT>::extract_removed_indices_;
using FilterIndices<PointT>::removed_indices_;
/** \brief Filtered results are stored in a separate point cloud.
* \param[out] output The resultant point cloud.
*/
void
applyFilter (PointCloud &output) override;
/** \brief Filtered results are indexed by an indices array.
* \param[out] indices The resultant indices.
*/
void
applyFilter (std::vector<int> &indices) override
{
applyFilterIndices (indices);
}
/** \brief Filtered results are indexed by an indices array.
* \param[out] indices The resultant indices.
*/
void
applyFilterIndices (std::vector<int> &indices);
private:
/** \brief The name of the field that will be used for filtering. */
std::string filter_field_name_;
/** \brief The minimum allowed field value (default = FLT_MIN). */
float filter_limit_min_;
/** \brief The maximum allowed field value (default = FLT_MIN). */
float filter_limit_max_;
};
////////////////////////////////////////////////////////////////////////////////////////////
/** \brief PassThrough uses the base Filter class methods to pass through all data that satisfies the user given
* constraints.
* \author Radu B. Rusu
* \ingroup filters
*/
template<>
class PCL_EXPORTS PassThrough<pcl::PCLPointCloud2> : public FilterIndices<pcl::PCLPointCloud2>
{
using PCLPointCloud2 = pcl::PCLPointCloud2;
using PCLPointCloud2Ptr = PCLPointCloud2::Ptr;
using PCLPointCloud2ConstPtr = PCLPointCloud2::ConstPtr;
using Filter<pcl::PCLPointCloud2>::removed_indices_;
using Filter<pcl::PCLPointCloud2>::extract_removed_indices_;
public:
/** \brief Constructor. */
PassThrough (bool extract_removed_indices = false) :
FilterIndices<pcl::PCLPointCloud2>::FilterIndices (extract_removed_indices),
filter_field_name_ (""), filter_limit_min_ (-FLT_MAX), filter_limit_max_ (FLT_MAX)
{
filter_name_ = "PassThrough";
}
/** \brief Provide the name of the field to be used for filtering data. In conjunction with \a setFilterLimits,
* points having values outside this interval will be discarded.
* \param[in] field_name the name of the field that contains values used for filtering
*/
inline void
setFilterFieldName (const std::string &field_name)
{
filter_field_name_ = field_name;
}
/** \brief Get the name of the field used for filtering. */
inline std::string const
getFilterFieldName () const
{
return (filter_field_name_);
}
/** \brief Set the field filter limits. All points having field values outside this interval will be discarded.
* \param[in] limit_min the minimum allowed field value
* \param[in] limit_max the maximum allowed field value
*/
inline void
setFilterLimits (const double &limit_min, const double &limit_max)
{
filter_limit_min_ = limit_min;
filter_limit_max_ = limit_max;
}
/** \brief Get the field filter limits (min/max) set by the user. The default values are -FLT_MAX, FLT_MAX.
* \param[out] limit_min the minimum allowed field value
* \param[out] limit_max the maximum allowed field value
*/
inline void
getFilterLimits (double &limit_min, double &limit_max) const
{
limit_min = filter_limit_min_;
limit_max = filter_limit_max_;
}
/** \brief Set to true if we want to return the data outside the interval specified by setFilterLimits (min, max).
* Default: false.
* \param[in] limit_negative return data inside the interval (false) or outside (true)
*/
[[deprecated("use inherited FilterIndices::setNegative() instead")]]
inline void
setFilterLimitsNegative (const bool limit_negative)
{
negative_ = limit_negative;
}
/** \brief Get whether the data outside the interval (min/max) is to be returned (true) or inside (false).
* \param[out] limit_negative true if data \b outside the interval [min; max] is to be returned, false otherwise
*/
[[deprecated("use inherited FilterIndices::getNegative() instead")]]
inline void
getFilterLimitsNegative (bool &limit_negative) const
{
limit_negative = negative_;
}
/** \brief Get whether the data outside the interval (min/max) is to be returned (true) or inside (false).
* \return true if data \b outside the interval [min; max] is to be returned, false otherwise
*/
[[deprecated("use inherited FilterIndices::getNegative() instead")]]
inline bool
getFilterLimitsNegative () const
{
return (negative_);
}
protected:
void
applyFilter (PCLPointCloud2 &output) override;
void
applyFilter (std::vector<int> &indices) override;
private:
/** \brief The desired user filter field name. */
std::string filter_field_name_;
/** \brief The minimum allowed filter value a point will be considered from. */
double filter_limit_min_;
/** \brief The maximum allowed filter value a point will be considered from. */
double filter_limit_max_;
};
}
#ifdef PCL_NO_PRECOMPILE
#include <pcl/filters/impl/passthrough.hpp>
#endif
pcl::PassThrough::applyFilterIndices
void applyFilterIndices(std::vector< int > &indices)
Filtered results are indexed by an indices array.
Definition: passthrough.hpp:74
pcl
This file defines compatibility wrappers for low level I/O functions.
Definition: convolution.h:45
pcl::Filter< PointInT >::Ptr
shared_ptr< Filter< PointInT > > Ptr
Definition: filter.h:89
pcl::PassThrough< pcl::PCLPointCloud2 >::PassThrough
PassThrough(bool extract_removed_indices=false)
Constructor.
Definition: passthrough.h:239
pcl::PCLBase< PointInT >::PointCloudConstPtr
typename PointCloud::ConstPtr PointCloudConstPtr
Definition: pcl_base.h:74
pcl::PCLBase< PointInT >::PointCloudPtr
typename PointCloud::Ptr PointCloudPtr
Definition: pcl_base.h:73
pcl::PassThrough::setFilterFieldName
void setFilterFieldName(const std::string &field_name)
Provide the name of the field to be used for filtering data.
Definition: passthrough.h:110
pcl::PCLPointCloud2::Ptr
shared_ptr< ::pcl::PCLPointCloud2 > Ptr
Definition: PCLPointCloud2.h:38
pcl::PassThrough::PassThrough
PassThrough(bool extract_removed_indices=false)
Constructor.
Definition: passthrough.h:96
pcl::PCLBase
PCL base class.
Definition: pcl_base.h:69
pcl::PassThrough< pcl::PCLPointCloud2 >::setFilterLimitsNegative
void setFilterLimitsNegative(const bool limit_negative)
Set to true if we want to return the data outside the interval specified by setFilterLimits (min,...
Definition: passthrough.h:291
pcl::PCLBase< pcl::PCLPointCloud2 >::PCLPointCloud2ConstPtr
PCLPointCloud2::ConstPtr PCLPointCloud2ConstPtr
Definition: pcl_base.h:190
pcl::PointCloud< PointInT >
pcl::PointXYZRGB
A point structure representing Euclidean xyz coordinates, and the RGB color.
Definition: point_types.hpp:623
pcl::PCLBase< pcl::PCLPointCloud2 >::PCLPointCloud2Ptr
PCLPointCloud2::Ptr PCLPointCloud2Ptr
Definition: pcl_base.h:189
pcl::PassThrough::getFilterLimitsNegative
void getFilterLimitsNegative(bool &limit_negative) const
Get whether the data outside the interval (min/max) is to be returned (true) or inside (false).
Definition: passthrough.h:163
pcl::PCLPointCloud2::ConstPtr
shared_ptr< const ::pcl::PCLPointCloud2 > ConstPtr
Definition: PCLPointCloud2.h:39
pcl::PassThrough< pcl::PCLPointCloud2 >::setFilterLimits
void setFilterLimits(const double &limit_min, const double &limit_max)
Set the field filter limits.
Definition: passthrough.h:268
pcl::Filter< PointInT >::ConstPtr
shared_ptr< const Filter< PointInT > > ConstPtr
Definition: filter.h:90
pcl::PassThrough< PointInT >::FieldList
typename pcl::traits::fieldList< PointInT >::type FieldList
Definition: passthrough.h:85
pcl::PassThrough< pcl::PCLPointCloud2 >::getFilterFieldName
const std::string getFilterFieldName() const
Get the name of the field used for filtering.
Definition: passthrough.h:258
pcl::FilterIndices
FilterIndices represents the base class for filters that are about binary point removal.
Definition: filter_indices.h:74
pcl::Filter
Filter represents the base filter class.
Definition: filter.h:83
pcl::PassThrough< pcl::PCLPointCloud2 >::getFilterLimitsNegative
void getFilterLimitsNegative(bool &limit_negative) const
Get whether the data outside the interval (min/max) is to be returned (true) or inside (false).
Definition: passthrough.h:301
pcl::PassThrough::getFilterLimitsNegative
bool getFilterLimitsNegative() const
Get whether the data outside the interval (min/max) is to be returned (true) or inside (false).
Definition: passthrough.h:173
pcl::PassThrough< pcl::PCLPointCloud2 >::getFilterLimitsNegative
bool getFilterLimitsNegative() const
Get whether the data outside the interval (min/max) is to be returned (true) or inside (false).
Definition: passthrough.h:311
pcl::PassThrough< pcl::PCLPointCloud2 >::setFilterFieldName
void setFilterFieldName(const std::string &field_name)
Provide the name of the field to be used for filtering data.
Definition: passthrough.h:251
pcl::PCLPointCloud2
Definition: PCLPointCloud2.h:19
pcl::PassThrough< pcl::PCLPointCloud2 >::getFilterLimits
void getFilterLimits(double &limit_min, double &limit_max) const
Get the field filter limits (min/max) set by the user.
Definition: passthrough.h:279
pcl::PassThrough
PassThrough passes points in a cloud based on constraints for one particular field of the point type.
Definition: passthrough.h:79
pcl::PassThrough::setFilterLimitsNegative
void setFilterLimitsNegative(const bool limit_negative)
Set to true if we want to return the data outside the interval specified by setFilterLimits (min,...
Definition: passthrough.h:153
pcl::Filter::filter_name_
std::string filter_name_
The filter name.
Definition: filter.h:164
pcl::PointCloud::Ptr
shared_ptr< PointCloud< PointT > > Ptr
Definition: point_cloud.h:415
pcl::PassThrough::applyFilter
void applyFilter(std::vector< int > &indices) override
Filtered results are indexed by an indices array.
Definition: passthrough.h:199
pcl::PointCloud::ConstPtr
shared_ptr< const PointCloud< PointT > > ConstPtr
Definition: point_cloud.h:416
pcl::PassThrough::getFilterFieldName
const std::string getFilterFieldName() const
Retrieve the name of the field to be used for filtering data.
Definition: passthrough.h:119
pcl::PassThrough::setFilterLimits
void setFilterLimits(const float &limit_min, const float &limit_max)
Set the numerical limits for the field for filtering data.
Definition: passthrough.h:130
pcl::PassThrough::applyFilter
void applyFilter(PointCloud &output) override
Filtered results are stored in a separate point cloud.
Definition: passthrough.hpp:48
pcl::FilterIndices::negative_
bool negative_
False = normal filter behavior (default), true = inverted behavior.
Definition: filter_indices.h:176
pcl::PassThrough::getFilterLimits
void getFilterLimits(float &limit_min, float &limit_max) const
Get the numerical limits for the field for filtering data.
Definition: passthrough.h:141
PCL_EXPORTS
#define PCL_EXPORTS
Definition: pcl_macros.h:253
pcl::shared_ptr
boost::shared_ptr< T > shared_ptr
Alias for boost::shared_ptr.
Definition: pcl_macros.h:90
pcl::traits::fieldList
Definition: point_traits.h:179