Point Cloud Library (PCL)  1.11.1
crop_box.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2009-2011, Willow Garage, Inc.
6  *
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * * Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  * * Redistributions in binary form must reproduce the above
16  * copyright notice, this list of conditions and the following
17  * disclaimer in the documentation and/or other materials provided
18  * with the distribution.
19  * * Neither the name of the copyright holder(s) nor the names of its
20  * contributors may be used to endorse or promote products derived
21  * from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  * POSSIBILITY OF SUCH DAMAGE.
35  *
36  * $Id: crop_box.h 1370 2011-06-19 01:06:01Z jspricke $
37  *
38  */
39 
40 #pragma once
41 
42 #include <pcl/point_types.h>
43 #include <pcl/filters/filter_indices.h>
44 #include <pcl/common/transforms.h>
45 #include <pcl/common/eigen.h>
46 
47 namespace pcl
48 {
49  /** \brief CropBox is a filter that allows the user to filter all the data
50  * inside of a given box.
51  *
52  * \author Justin Rosen
53  * \ingroup filters
54  */
55  template<typename PointT>
56  class CropBox : public FilterIndices<PointT>
57  {
59 
60  using PointCloud = typename Filter<PointT>::PointCloud;
61  using PointCloudPtr = typename PointCloud::Ptr;
63 
64  public:
65 
66  using Ptr = shared_ptr<CropBox<PointT> >;
67  using ConstPtr = shared_ptr<const CropBox<PointT> >;
68 
69  /** \brief Constructor.
70  * \param[in] extract_removed_indices Set to true if you want to be able to extract the indices of points being removed (default = false).
71  */
72  CropBox (bool extract_removed_indices = false) :
73  FilterIndices<PointT> (extract_removed_indices),
74  min_pt_ (Eigen::Vector4f (-1, -1, -1, 1)),
75  max_pt_ (Eigen::Vector4f (1, 1, 1, 1)),
76  rotation_ (Eigen::Vector3f::Zero ()),
77  translation_ (Eigen::Vector3f::Zero ()),
78  transform_ (Eigen::Affine3f::Identity ())
79  {
80  filter_name_ = "CropBox";
81  }
82 
83  /** \brief Set the minimum point of the box
84  * \param[in] min_pt the minimum point of the box
85  */
86  inline void
87  setMin (const Eigen::Vector4f &min_pt)
88  {
89  min_pt_ = min_pt;
90  }
91 
92  /** \brief Get the value of the minimum point of the box, as set by the user
93  * \return the value of the internal \a min_pt parameter.
94  */
95  inline Eigen::Vector4f
96  getMin () const
97  {
98  return (min_pt_);
99  }
100 
101  /** \brief Set the maximum point of the box
102  * \param[in] max_pt the maximum point of the box
103  */
104  inline void
105  setMax (const Eigen::Vector4f &max_pt)
106  {
107  max_pt_ = max_pt;
108  }
109 
110  /** \brief Get the value of the maximum point of the box, as set by the user
111  * \return the value of the internal \a max_pt parameter.
112  */
113  inline Eigen::Vector4f
114  getMax () const
115  {
116  return (max_pt_);
117  }
118 
119  /** \brief Set a translation value for the box
120  * \param[in] translation the (tx,ty,tz) values that the box should be translated by
121  */
122  inline void
123  setTranslation (const Eigen::Vector3f &translation)
124  {
125  translation_ = translation;
126  }
127 
128  /** \brief Get the value of the box translation parameter as set by the user. */
129  Eigen::Vector3f
130  getTranslation () const
131  {
132  return (translation_);
133  }
134 
135  /** \brief Set a rotation value for the box
136  * \param[in] rotation the (rx,ry,rz) values that the box should be rotated by
137  */
138  inline void
139  setRotation (const Eigen::Vector3f &rotation)
140  {
141  rotation_ = rotation;
142  }
143 
144  /** \brief Get the value of the box rotatation parameter, as set by the user. */
145  inline Eigen::Vector3f
146  getRotation () const
147  {
148  return (rotation_);
149  }
150 
151  /** \brief Set a transformation that should be applied to the cloud before filtering
152  * \param[in] transform an affine transformation that needs to be applied to the cloud before filtering
153  */
154  inline void
155  setTransform (const Eigen::Affine3f &transform)
156  {
157  transform_ = transform;
158  }
159 
160  /** \brief Get the value of the transformation parameter, as set by the user. */
161  inline Eigen::Affine3f
162  getTransform () const
163  {
164  return (transform_);
165  }
166 
167  protected:
176 
177  /** \brief Sample of point indices
178  * \param[out] indices the resultant point cloud indices
179  */
180  void
181  applyFilter (std::vector<int> &indices) override;
182  private:
183  /** \brief The minimum point of the box. */
184  Eigen::Vector4f min_pt_;
185  /** \brief The maximum point of the box. */
186  Eigen::Vector4f max_pt_;
187  /** \brief The 3D rotation for the box. */
188  Eigen::Vector3f rotation_;
189  /** \brief The 3D translation for the box. */
190  Eigen::Vector3f translation_;
191  /** \brief The affine transform applied to the cloud. */
192  Eigen::Affine3f transform_;
193  };
194 
195  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
196  /** \brief CropBox is a filter that allows the user to filter all the data
197  * inside of a given box.
198  *
199  * \author Justin Rosen
200  * \ingroup filters
201  */
202  template<>
203  class PCL_EXPORTS CropBox<pcl::PCLPointCloud2> : public FilterIndices<pcl::PCLPointCloud2>
204  {
207 
211 
212  public:
213  /** \brief Constructor.
214  * \param[in] extract_removed_indices Set to true if you want to be able to extract the indices of points being removed (default = false).
215  */
216  CropBox (bool extract_removed_indices = false) :
217  FilterIndices<pcl::PCLPointCloud2>::FilterIndices (extract_removed_indices),
218  min_pt_(Eigen::Vector4f (-1, -1, -1, 1)),
219  max_pt_(Eigen::Vector4f (1, 1, 1, 1)),
220  translation_ (Eigen::Vector3f::Zero ()),
221  rotation_ (Eigen::Vector3f::Zero ()),
222  transform_(Eigen::Affine3f::Identity ())
223  {
224  filter_name_ = "CropBox";
225  }
226 
227  /** \brief Set the minimum point of the box
228  * \param[in] min_pt the minimum point of the box
229  */
230  inline void
231  setMin (const Eigen::Vector4f& min_pt)
232  {
233  min_pt_ = min_pt;
234  }
235 
236  /** \brief Get the value of the minimum point of the box, as set by the user
237  * \return the value of the internal \a min_pt parameter.
238  */
239  inline Eigen::Vector4f
240  getMin () const
241  {
242  return (min_pt_);
243  }
244 
245  /** \brief Set the maximum point of the box
246  * \param[in] max_pt the maximum point of the box
247  */
248  inline void
249  setMax (const Eigen::Vector4f &max_pt)
250  {
251  max_pt_ = max_pt;
252  }
253 
254  /** \brief Get the value of the maxiomum point of the box, as set by the user
255  * \return the value of the internal \a max_pt parameter.
256  */
257  inline Eigen::Vector4f
258  getMax () const
259  {
260  return (max_pt_);
261  }
262 
263  /** \brief Set a translation value for the box
264  * \param[in] translation the (tx,ty,tz) values that the box should be translated by
265  */
266  inline void
267  setTranslation (const Eigen::Vector3f &translation)
268  {
269  translation_ = translation;
270  }
271 
272  /** \brief Get the value of the box translation parameter as set by the user. */
273  inline Eigen::Vector3f
274  getTranslation () const
275  {
276  return (translation_);
277  }
278 
279  /** \brief Set a rotation value for the box
280  * \param[in] rotation the (rx,ry,rz) values that the box should be rotated by
281  */
282  inline void
283  setRotation (const Eigen::Vector3f &rotation)
284  {
285  rotation_ = rotation;
286  }
287 
288  /** \brief Get the value of the box rotatation parameter, as set by the user. */
289  inline Eigen::Vector3f
290  getRotation () const
291  {
292  return (rotation_);
293  }
294 
295  /** \brief Set a transformation that should be applied to the cloud before filtering
296  * \param[in] transform an affine transformation that needs to be applied to the cloud before filtering
297  */
298  inline void
299  setTransform (const Eigen::Affine3f &transform)
300  {
301  transform_ = transform;
302  }
303 
304  /** \brief Get the value of the transformation parameter, as set by the user. */
305  inline Eigen::Affine3f
306  getTransform () const
307  {
308  return (transform_);
309  }
310 
311  protected:
312  /** \brief Sample of point indices into a separate PointCloud
313  * \param output the resultant point cloud
314  */
315  void
316  applyFilter (PCLPointCloud2 &output) override;
317 
318  /** \brief Sample of point indices
319  * \param indices the resultant point cloud indices
320  */
321  void
322  applyFilter (std::vector<int> &indices) override;
323 
324  /** \brief The minimum point of the box. */
325  Eigen::Vector4f min_pt_;
326  /** \brief The maximum point of the box. */
327  Eigen::Vector4f max_pt_;
328  /** \brief The 3D translation for the box. */
329  Eigen::Vector3f translation_;
330  /** \brief The 3D rotation for the box. */
331  Eigen::Vector3f rotation_;
332  /** \brief The affine transform applied to the cloud. */
333  Eigen::Affine3f transform_;
334  };
335 }
336 
337 #ifdef PCL_NO_PRECOMPILE
338 #include <pcl/filters/impl/crop_box.hpp>
339 #endif
void applyFilter(PCLPointCloud2 &output) override
Sample of point indices into a separate PointCloud.
Eigen::Vector3f getTranslation() const
Get the value of the box translation parameter as set by the user.
Definition: crop_box.h:274
Eigen::Vector3f translation_
The 3D translation for the box.
Definition: crop_box.h:329
void setMax(const Eigen::Vector4f &max_pt)
Set the maximum point of the box.
Definition: crop_box.h:249
void setTransform(const Eigen::Affine3f &transform)
Set a transformation that should be applied to the cloud before filtering.
Definition: crop_box.h:299
Eigen::Affine3f transform_
The affine transform applied to the cloud.
Definition: crop_box.h:333
CropBox(bool extract_removed_indices=false)
Constructor.
Definition: crop_box.h:216
Eigen::Vector4f getMax() const
Get the value of the maxiomum point of the box, as set by the user.
Definition: crop_box.h:258
void setMin(const Eigen::Vector4f &min_pt)
Set the minimum point of the box.
Definition: crop_box.h:231
Eigen::Vector3f getRotation() const
Get the value of the box rotatation parameter, as set by the user.
Definition: crop_box.h:290
void setRotation(const Eigen::Vector3f &rotation)
Set a rotation value for the box.
Definition: crop_box.h:283
void setTranslation(const Eigen::Vector3f &translation)
Set a translation value for the box.
Definition: crop_box.h:267
Eigen::Vector3f rotation_
The 3D rotation for the box.
Definition: crop_box.h:331
Eigen::Vector4f max_pt_
The maximum point of the box.
Definition: crop_box.h:327
Eigen::Vector4f getMin() const
Get the value of the minimum point of the box, as set by the user.
Definition: crop_box.h:240
Eigen::Affine3f getTransform() const
Get the value of the transformation parameter, as set by the user.
Definition: crop_box.h:306
Eigen::Vector4f min_pt_
The minimum point of the box.
Definition: crop_box.h:325
void applyFilter(std::vector< int > &indices) override
Sample of point indices.
CropBox is a filter that allows the user to filter all the data inside of a given box.
Definition: crop_box.h:57
void setRotation(const Eigen::Vector3f &rotation)
Set a rotation value for the box.
Definition: crop_box.h:139
Eigen::Vector3f getRotation() const
Get the value of the box rotatation parameter, as set by the user.
Definition: crop_box.h:146
CropBox(bool extract_removed_indices=false)
Constructor.
Definition: crop_box.h:72
void setTransform(const Eigen::Affine3f &transform)
Set a transformation that should be applied to the cloud before filtering.
Definition: crop_box.h:155
Eigen::Vector4f getMax() const
Get the value of the maximum point of the box, as set by the user.
Definition: crop_box.h:114
Eigen::Vector4f getMin() const
Get the value of the minimum point of the box, as set by the user.
Definition: crop_box.h:96
shared_ptr< CropBox< PointT > > Ptr
Definition: crop_box.h:66
void setMin(const Eigen::Vector4f &min_pt)
Set the minimum point of the box.
Definition: crop_box.h:87
void setTranslation(const Eigen::Vector3f &translation)
Set a translation value for the box.
Definition: crop_box.h:123
shared_ptr< const CropBox< PointT > > ConstPtr
Definition: crop_box.h:67
Eigen::Vector3f getTranslation() const
Get the value of the box translation parameter as set by the user.
Definition: crop_box.h:130
void setMax(const Eigen::Vector4f &max_pt)
Set the maximum point of the box.
Definition: crop_box.h:105
Eigen::Affine3f getTransform() const
Get the value of the transformation parameter, as set by the user.
Definition: crop_box.h:162
void applyFilter(std::vector< int > &indices) override
Sample of point indices.
Definition: crop_box.hpp:48
Filter represents the base filter class.
Definition: filter.h:84
std::string filter_name_
The filter name.
Definition: filter.h:161
FilterIndices represents the base class for filters that are about binary point removal.
PCLPointCloud2::Ptr PCLPointCloud2Ptr
Definition: pcl_base.h:188
PCLPointCloud2::ConstPtr PCLPointCloud2ConstPtr
Definition: pcl_base.h:189
PCL base class.
Definition: pcl_base.h:73
typename PointCloud::Ptr PointCloudPtr
Definition: pcl_base.h:76
typename PointCloud::ConstPtr PointCloudConstPtr
Definition: pcl_base.h:77
PointCloud represents the base class in PCL for storing collections of 3D points.
Definition: point_cloud.h:181
shared_ptr< PointCloud< PointT > > Ptr
Definition: point_cloud.h:429
shared_ptr< const PointCloud< PointT > > ConstPtr
Definition: point_cloud.h:430
Defines all the PCL implemented PointT point type structures.
Definition: bfgs.h:10
#define PCL_EXPORTS
Definition: pcl_macros.h:328
shared_ptr< ::pcl::PCLPointCloud2 > Ptr
shared_ptr< const ::pcl::PCLPointCloud2 > ConstPtr
A point structure representing Euclidean xyz coordinates, and the RGB color.