1212#include < pcl/common/eigen.h> // for getTransformation
1313#include < pcl/common/point_tests.h> // for isFinite
1414#include < pcl/filters/experimental/functor_filter.h>
15+ #include < pcl/filters/filter_indices.h>
1516
1617namespace pcl {
1718namespace experimental {
1819
19- template <typename PointT>
20- struct CropBoxFunctor {
21- CropBoxFunctor () = default ;
22- CropBoxFunctor (const Eigen::Vector4f* min_pt,
23- const Eigen::Vector4f* max_pt,
24- const Eigen::Affine3f* pt_transform)
25- : min_pt_(min_pt), max_pt_(max_pt), pt_transform_(pt_transform)
26- {}
27-
28- bool
29- operator ()(const PointCloud<PointT>& cloud, index_t idx) const
30- {
31- // Not all fields are NaN checked
32- // only checked with isXYZFinite in FunctorFilter
33- const Eigen::Vector4f pt = (*pt_transform_) * cloud.at (idx).getVector4fMap ();
34- return (pt.array () >= min_pt_->array ()).template head <3 >().all () &&
35- (pt.array () <= max_pt_->array ()).template head <3 >().all ();
36- }
37-
38- private:
39- const Eigen::Vector4f* min_pt_ = nullptr ;
40- const Eigen::Vector4f* max_pt_ = nullptr ;
41- const Eigen::Affine3f* pt_transform_ = nullptr ;
42- };
43-
44- template <typename PointT>
45- using CropBoxFilter = advanced::FunctorFilter<PointT, CropBoxFunctor<PointT>>;
46-
4720/* * \brief CropBox is a filter that allows the user to filter all the data
4821 * inside of a given box.
4922 *
5023 * \author Justin Rosen
5124 * \ingroup filters
5225 */
5326template <typename PointT>
54- class CropBox : public CropBoxFilter <PointT> {
27+ class CropBox : public FilterIndices <PointT> {
5528 using PointCloud = typename FilterIndices<PointT>::PointCloud;
5629 using PointCloudPtr = typename PointCloud::Ptr;
5730 using PointCloudConstPtr = typename PointCloud::ConstPtr;
@@ -65,11 +38,9 @@ class CropBox : public CropBoxFilter<PointT> {
6538 * the indices of points being removed (default = false).
6639 */
6740 CropBox (bool extract_removed_indices = false )
68- : CropBoxFilter <PointT>(extract_removed_indices)
41+ : FilterIndices <PointT>(extract_removed_indices)
6942 {
7043 filter_name_ = " CropBox" ;
71- CropBoxFilter<PointT>::setFunctionObject (
72- CropBoxFunctor<PointT>(&min_pt_, &max_pt_, &pt_transform_));
7344 }
7445
7546 /* * \brief Set the minimum point of the box
@@ -173,7 +144,21 @@ class CropBox : public CropBoxFilter<PointT> {
173144 box_transform);
174145 pt_transform_ = box_transform.inverse () * transform_;
175146
176- CropBoxFilter<PointT>::applyFilter (indices);
147+ const auto lambda = [&](const PointCloud& cloud, index_t idx) {
148+ const Eigen::Vector4f pt = pt_transform_ * cloud.at (idx).getVector4fMap ();
149+ return (pt.array () >= min_pt_.array ()).template head <3 >().all () &&
150+ (pt.array () <= max_pt_.array ()).template head <3 >().all ();
151+ };
152+
153+ auto filter = advanced::FunctorFilter<PointT, decltype (lambda)>(
154+ lambda, this ->extract_removed_indices_ );
155+ filter.setNegative (this ->getNegative ());
156+ filter.setKeepOrganized (this ->getKeepOrganized ());
157+ filter.setIndices (this ->getIndices ());
158+ filter.setInputCloud (this ->getInputCloud ());
159+ filter.applyFilter (indices);
160+ if (this ->extract_removed_indices_ )
161+ *removed_indices_ = *filter.getRemovedIndices (); // copy
177162 }
178163
179164protected:
@@ -204,8 +189,6 @@ class CropBox : public CropBoxFilter<PointT> {
204189
205190 /* * \brief The final transform applied to the points. */
206191 Eigen::Affine3f pt_transform_;
207-
208- using CropBoxFilter<PointT>::getFunctionObject; // hide method
209192};
210193} // namespace experimental
211194} // namespace pcl
0 commit comments