Skip to content

Commit f30572a

Browse files
committed
[WIP] Implement CropBox prototype
1 parent 8800b44 commit f30572a

File tree

1 file changed

+20
-40
lines changed
  • filters/include/pcl/filters/experimental

1 file changed

+20
-40
lines changed

filters/include/pcl/filters/experimental/crop_box.h

Lines changed: 20 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -12,46 +12,19 @@
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

1617
namespace pcl {
1718
namespace 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
*/
5326
template <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
@@ -171,9 +142,23 @@ class CropBox : public CropBoxFilter<PointT> {
171142
rotation_(1),
172143
rotation_(2),
173144
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
177162
}
178163

179164
protected:
@@ -201,11 +186,6 @@ class CropBox : public CropBoxFilter<PointT> {
201186

202187
/** \brief The affine transform applied to the cloud. */
203188
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
209189
};
210190
} // namespace experimental
211191
} // namespace pcl

0 commit comments

Comments
 (0)