Skip to content

Executor integration with filters #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: executors
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions filters/include/pcl/filters/crop_box.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,25 @@ namespace pcl
template<typename PointT>
class CropBox : public FilterIndices<PointT>
{
using Filter<PointT>::getClassName;
using Self = CropBox<PointT>;
using Base = FilterIndices<PointT>;

using PointCloud = typename Filter<PointT>::PointCloud;
using Base::getClassName;

using PointCloud = typename Filter<PointT, Base>::PointCloud;
using PointCloudPtr = typename PointCloud::Ptr;
using PointCloudConstPtr = typename PointCloud::ConstPtr;

public:

using Ptr = shared_ptr<CropBox<PointT> >;
using ConstPtr = shared_ptr<const CropBox<PointT> >;
using Ptr = shared_ptr<Self>;
using ConstPtr = shared_ptr<const Self>;

/** \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).
*/
CropBox (bool extract_removed_indices = false) :
FilterIndices<PointT> (extract_removed_indices),
Base(extract_removed_indices),
min_pt_ (Eigen::Vector4f (-1, -1, -1, 1)),
max_pt_ (Eigen::Vector4f (1, 1, 1, 1)),
rotation_ (Eigen::Vector3f::Zero ()),
Expand Down Expand Up @@ -164,12 +167,12 @@ namespace pcl
protected:
using PCLBase<PointT>::input_;
using PCLBase<PointT>::indices_;
using Filter<PointT>::filter_name_;
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_;
using Filter<PointT, Base>::filter_name_;
using Base::negative_;
using Base::keep_organized_;
using Base::user_filter_value_;
using Base::extract_removed_indices_;
using Base::removed_indices_;

/** \brief Sample of point indices
* \param[out] indices the resultant point cloud indices
Expand Down
15 changes: 9 additions & 6 deletions filters/include/pcl/filters/crop_hull.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,21 @@ namespace pcl
template<typename PointT>
class CropHull: public FilterIndices<PointT>
{
using Filter<PointT>::filter_name_;
using Filter<PointT>::indices_;
using Filter<PointT>::input_;
using Self = CropHull<PointT>;
using Base = FilterIndices<PointT>;

using Filter<PointT, Base>::filter_name_;
using Filter<PointT, Base>::indices_;
using Filter<PointT, Base>::input_;

using PointCloud = typename Filter<PointT>::PointCloud;
using PointCloud = typename Filter<PointT, Base>::PointCloud;
using PointCloudPtr = typename PointCloud::Ptr;
using PointCloudConstPtr = typename PointCloud::ConstPtr;

public:

using Ptr = shared_ptr<CropHull<PointT> >;
using ConstPtr = shared_ptr<const CropHull<PointT> >;
using Ptr = shared_ptr<Self>;
using ConstPtr = shared_ptr<const Self>;

/** \brief Empty Constructor. */
CropHull () :
Expand Down
25 changes: 14 additions & 11 deletions filters/include/pcl/filters/extract_indices.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,22 +68,25 @@ namespace pcl
template<typename PointT>
class ExtractIndices : public FilterIndices<PointT>
{
using Self = ExtractIndices<PointT>;
using Base = FilterIndices<PointT>;

protected:
using PointCloud = typename FilterIndices<PointT>::PointCloud;
using PointCloud = typename Base::PointCloud;
using PointCloudPtr = typename PointCloud::Ptr;
using PointCloudConstPtr = typename PointCloud::ConstPtr;
using FieldList = typename pcl::traits::fieldList<PointT>::type;

public:

using Ptr = shared_ptr<ExtractIndices<PointT> >;
using ConstPtr = shared_ptr<const ExtractIndices<PointT> >;
using Ptr = shared_ptr<Self>;
using ConstPtr = shared_ptr<const Self>;

/** \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).
*/
ExtractIndices (bool extract_removed_indices = false) :
FilterIndices<PointT>::FilterIndices (extract_removed_indices)
Base(extract_removed_indices)
{
use_indices_ = true;
filter_name_ = "ExtractIndices";
Expand All @@ -104,13 +107,13 @@ namespace pcl
using PCLBase<PointT>::input_;
using PCLBase<PointT>::indices_;
using PCLBase<PointT>::use_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_;
using Filter<PointT, Base>::filter_name_;
using Filter<PointT, Base>::getClassName;
using Base::negative_;
using Base::keep_organized_;
using Base::user_filter_value_;
using Base::extract_removed_indices_;
using Base::removed_indices_;

/** \brief Filtered results are stored in a separate point cloud.
* \param[out] output The resultant point cloud.
Expand Down
106 changes: 78 additions & 28 deletions filters/include/pcl/filters/filter.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include <pcl/pcl_base.h>
#include <pcl/common/io.h>
#include <pcl/PointIndices.h>
#include <pcl/experimental/executor/executor.h>

namespace pcl
{
Expand All @@ -56,7 +57,7 @@ namespace pcl
template<typename PointT> void
removeNaNFromPointCloud (const pcl::PointCloud<PointT> &cloud_in,
pcl::PointCloud<PointT> &cloud_out,
std::vector<int> &index);
Indices &index);

/** \brief Removes points that have their normals invalid (i.e., equal to NaN)
* \param[in] cloud_in the input point cloud
Expand All @@ -69,19 +70,23 @@ namespace pcl
template<typename PointT> void
removeNaNNormalsFromPointCloud (const pcl::PointCloud<PointT> &cloud_in,
pcl::PointCloud<PointT> &cloud_out,
std::vector<int> &index);
Indices &index);

////////////////////////////////////////////////////////////////////////////////////////////
/** \brief Filter represents the base filter class. All filters must inherit from this interface.
* \warning PCLPointCloud2 is not currently supported by executors
* \author Radu B. Rusu
* \ingroup filters
*/
template<typename PointT>
template<typename PointT, typename DerivedFilter = void>
class Filter : public PCLBase<PointT>
{
using Self = Filter<PointT, DerivedFilter>;
using Base = PCLBase<PointT>;

public:
using Ptr = shared_ptr<Filter<PointT> >;
using ConstPtr = shared_ptr<const Filter<PointT> >;
using Ptr = shared_ptr<Self>;
using ConstPtr = shared_ptr<const Self>;


using PointCloud = pcl::PointCloud<PointT>;
Expand All @@ -93,7 +98,7 @@ namespace pcl
* separate list. Default: false.
*/
Filter (bool extract_removed_indices = false) :
removed_indices_ (new std::vector<int>),
removed_indices_ (new Indices),
extract_removed_indices_ (extract_removed_indices)
{
}
Expand All @@ -120,27 +125,36 @@ namespace pcl
inline void
filter (PointCloud &output)
{
if (!initCompute ())
return;
auto filterCloud = [this](PointCloud& output) {
applyFilter(output);
};

if (input_.get () == &output) // cloud_in = cloud_out
{
PointCloud output_temp;
applyFilter (output_temp);
output_temp.header = input_->header;
output_temp.sensor_origin_ = input_->sensor_origin_;
output_temp.sensor_orientation_ = input_->sensor_orientation_;
pcl::copyPointCloud (output_temp, output);
}
else
{
output.header = input_->header;
output.sensor_origin_ = input_->sensor_origin_;
output.sensor_orientation_ = input_->sensor_orientation_;
applyFilter (output);
}
filterImpl(filterCloud, output);
}

deinitCompute ();
/** \brief filter method with specified executor.
*
* The implementation needs to set output.{points, width, height, is_dense}.
*
* \param[int] exec the executor to run the filter using
* \param[out] output the resultant filtered point cloud
*/
template <typename Executor>
inline void
filter(const Executor& exec, PointCloud& output)
{
static_assert(pcl::is_invocable_v<
decltype(&DerivedFilter::template applyFilter<Executor>),
DerivedFilter&,
Executor const&,
PointCloud&>,
"An executor overload for applyFilter doesn't exist.");

auto filterCloud = [exec, this](PointCloud& output) {
static_cast<DerivedFilter&>(*this).applyFilter(exec, output);
};

filterImpl(filterCloud, output);
}

protected:
Expand Down Expand Up @@ -169,6 +183,40 @@ namespace pcl
virtual void
applyFilter (PointCloud &output) = 0;

/** \brief implementation of filter method
* Added to ensure no code duplication is present in the filter method
* overloads, with and without the executor
*
* \param[int] filterIndices the callable which calls the filter method
* \param[out] output the resultant filtered point cloud
*/
template <typename Callable>
void
filterImpl (Callable &filterCloud, PointCloud &output)
{
if (!initCompute ())
return;

if (input_.get () == &output) // cloud_in = cloud_out
{
PointCloud output_temp;
filterCloud(output_temp);
output_temp.header = input_->header;
output_temp.sensor_origin_ = input_->sensor_origin_;
output_temp.sensor_orientation_ = input_->sensor_orientation_;
pcl::copyPointCloud (output_temp, output);
}
else
{
output.header = input_->header;
output.sensor_origin_ = input_->sensor_origin_;
output.sensor_orientation_ = input_->sensor_orientation_;
filterCloud(output);
}

deinitCompute ();
}

/** \brief Get a string representation of the name of this class. */
inline const std::string&
getClassName () const
Expand All @@ -177,8 +225,12 @@ namespace pcl
}
};

template <typename PointT>
using FilterLegacy = Filter<PointT>;

////////////////////////////////////////////////////////////////////////////////////////////
/** \brief Filter represents the base filter class. All filters must inherit from this interface.
* \warning PCLPointCloud2 is not currently supported by executors
* \author Radu B. Rusu
* \ingroup filters
*/
Expand All @@ -198,7 +250,7 @@ namespace pcl
* separate list. Default: false.
*/
Filter (bool extract_removed_indices = false) :
removed_indices_ (new std::vector<int>),
removed_indices_ (new Indices),
extract_removed_indices_ (extract_removed_indices)
{
}
Expand Down Expand Up @@ -254,6 +306,4 @@ namespace pcl
};
}

#ifdef PCL_NO_PRECOMPILE
#include <pcl/filters/impl/filter.hpp>
#endif
Loading