12
12
#include < pcl/common/eigen.h> // for getTransformation
13
13
#include < pcl/common/point_tests.h> // for isFinite
14
14
#include < pcl/filters/experimental/functor_filter.h>
15
+ #include < pcl/filters/filter_indices.h>
15
16
16
17
namespace pcl {
17
18
namespace experimental {
18
19
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
-
47
20
/* * \brief CropBox is a filter that allows the user to filter all the data
48
21
* inside of a given box.
49
22
*
50
23
* \author Justin Rosen
51
24
* \ingroup filters
52
25
*/
53
26
template <typename PointT>
54
- class CropBox : public CropBoxFilter <PointT> {
27
+ class CropBox : public FilterIndices <PointT> {
55
28
using PointCloud = typename FilterIndices<PointT>::PointCloud;
56
29
using PointCloudPtr = typename PointCloud::Ptr;
57
30
using PointCloudConstPtr = typename PointCloud::ConstPtr;
@@ -65,11 +38,9 @@ class CropBox : public CropBoxFilter<PointT> {
65
38
* the indices of points being removed (default = false).
66
39
*/
67
40
CropBox (bool extract_removed_indices = false )
68
- : CropBoxFilter <PointT>(extract_removed_indices)
41
+ : FilterIndices <PointT>(extract_removed_indices)
69
42
{
70
43
filter_name_ = " CropBox" ;
71
- CropBoxFilter<PointT>::setFunctionObject (
72
- CropBoxFunctor<PointT>(&min_pt_, &max_pt_, &pt_transform_));
73
44
}
74
45
75
46
/* * \brief Set the minimum point of the box
@@ -171,9 +142,23 @@ class CropBox : public CropBoxFilter<PointT> {
171
142
rotation_ (1 ),
172
143
rotation_ (2 ),
173
144
box_transform);
174
- pt_transform_ = box_transform.inverse () * transform_;
175
-
176
- CropBoxFilter<PointT>::applyFilter (indices);
145
+ Eigen::Affine3f pt_transform = box_transform.inverse () * transform_;
146
+
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
177
162
}
178
163
179
164
protected:
@@ -201,11 +186,6 @@ class CropBox : public CropBoxFilter<PointT> {
201
186
202
187
/* * \brief The affine transform applied to the cloud. */
203
188
Eigen::Affine3f transform_ = Eigen::Affine3f::Identity();
204
-
205
- /* * \brief The final transform applied to the points. */
206
- Eigen::Affine3f pt_transform_;
207
-
208
- using CropBoxFilter<PointT>::getFunctionObject; // hide method
209
189
};
210
190
} // namespace experimental
211
191
} // namespace pcl
0 commit comments