Point Cloud Library (PCL)  1.8.1-dev
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 #ifndef PCL_FILTERS_CROP_BOX_H_
41 #define PCL_FILTERS_CROP_BOX_H_
42 
43 #include <pcl/point_types.h>
44 #include <pcl/filters/filter_indices.h>
45 #include <pcl/common/transforms.h>
46 #include <pcl/common/eigen.h>
47 
48 namespace pcl
49 {
50  /** \brief CropBox is a filter that allows the user to filter all the data
51  * inside of a given box.
52  *
53  * \author Justin Rosen
54  * \ingroup filters
55  */
56  template<typename PointT>
57  class CropBox : public FilterIndices<PointT>
58  {
60 
61  typedef typename Filter<PointT>::PointCloud PointCloud;
62  typedef typename PointCloud::Ptr PointCloudPtr;
64 
65  public:
66 
67  typedef boost::shared_ptr< CropBox<PointT> > Ptr;
68  typedef boost::shared_ptr< const CropBox<PointT> > ConstPtr;
69 
70  /** \brief Constructor.
71  * \param[in] extract_removed_indices Set to true if you want to be able to extract the indices of points being removed (default = false).
72  */
73  CropBox (bool extract_removed_indices = false) :
74  FilterIndices<PointT>::FilterIndices (extract_removed_indices),
75  min_pt_ (Eigen::Vector4f (-1, -1, -1, 1)),
76  max_pt_ (Eigen::Vector4f (1, 1, 1, 1)),
77  rotation_ (Eigen::Vector3f::Zero ()),
78  translation_ (Eigen::Vector3f::Zero ()),
79  transform_ (Eigen::Affine3f::Identity ())
80  {
81  filter_name_ = "CropBox";
82  }
83 
84  /** \brief Set the minimum point of the box
85  * \param[in] min_pt the minimum point of the box
86  */
87  inline void
88  setMin (const Eigen::Vector4f &min_pt)
89  {
90  min_pt_ = min_pt;
91  }
92 
93  /** \brief Get the value of the minimum point of the box, as set by the user
94  * \return the value of the internal \a min_pt parameter.
95  */
96  inline Eigen::Vector4f
97  getMin () const
98  {
99  return (min_pt_);
100  }
101 
102  /** \brief Set the maximum point of the box
103  * \param[in] max_pt the maximum point of the box
104  */
105  inline void
106  setMax (const Eigen::Vector4f &max_pt)
107  {
108  max_pt_ = max_pt;
109  }
110 
111  /** \brief Get the value of the maxiomum point of the box, as set by the user
112  * \return the value of the internal \a max_pt parameter.
113  */
114  inline Eigen::Vector4f
115  getMax () const
116  {
117  return (max_pt_);
118  }
119 
120  /** \brief Set a translation value for the box
121  * \param[in] translation the (tx,ty,tz) values that the box should be translated by
122  */
123  inline void
124  setTranslation (const Eigen::Vector3f &translation)
125  {
126  translation_ = translation;
127  }
128 
129  /** \brief Get the value of the box translation parameter as set by the user. */
130  Eigen::Vector3f
131  getTranslation () const
132  {
133  return (translation_);
134  }
135 
136  /** \brief Set a rotation value for the box
137  * \param[in] rotation the (rx,ry,rz) values that the box should be rotated by
138  */
139  inline void
140  setRotation (const Eigen::Vector3f &rotation)
141  {
142  rotation_ = rotation;
143  }
144 
145  /** \brief Get the value of the box rotatation parameter, as set by the user. */
146  inline Eigen::Vector3f
147  getRotation () const
148  {
149  return (rotation_);
150  }
151 
152  /** \brief Set a transformation that should be applied to the cloud before filtering
153  * \param[in] transform an affine transformation that needs to be applied to the cloud before filtering
154  */
155  inline void
156  setTransform (const Eigen::Affine3f &transform)
157  {
158  transform_ = transform;
159  }
160 
161  /** \brief Get the value of the transformation parameter, as set by the user. */
162  inline Eigen::Affine3f
163  getTransform () const
164  {
165  return (transform_);
166  }
167 
168  protected:
177 
178  /** \brief Sample of point indices into a separate PointCloud
179  * \param[out] output the resultant point cloud
180  */
181  void
182  applyFilter (PointCloud &output);
183 
184  /** \brief Sample of point indices
185  * \param[out] indices the resultant point cloud indices
186  */
187  void
188  applyFilter (std::vector<int> &indices);
189 
190  private:
191  /** \brief The minimum point of the box. */
192  Eigen::Vector4f min_pt_;
193  /** \brief The maximum point of the box. */
194  Eigen::Vector4f max_pt_;
195  /** \brief The 3D rotation for the box. */
196  Eigen::Vector3f rotation_;
197  /** \brief The 3D translation for the box. */
198  Eigen::Vector3f translation_;
199  /** \brief The affine transform applied to the cloud. */
200  Eigen::Affine3f transform_;
201  };
202 
203  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
204  /** \brief CropBox is a filter that allows the user to filter all the data
205  * inside of a given box.
206  *
207  * \author Justin Rosen
208  * \ingroup filters
209  */
210  template<>
211  class PCL_EXPORTS CropBox<pcl::PCLPointCloud2> : public FilterIndices<pcl::PCLPointCloud2>
212  {
215 
219 
220  public:
221  /** \brief Constructor.
222  * \param[in] extract_removed_indices Set to true if you want to be able to extract the indices of points being removed (default = false).
223  */
224  CropBox (bool extract_removed_indices = false) :
225  FilterIndices<pcl::PCLPointCloud2>::FilterIndices (extract_removed_indices),
226  min_pt_(Eigen::Vector4f (-1, -1, -1, 1)),
227  max_pt_(Eigen::Vector4f (1, 1, 1, 1)),
228  translation_ (Eigen::Vector3f::Zero ()),
229  rotation_ (Eigen::Vector3f::Zero ()),
230  transform_(Eigen::Affine3f::Identity ())
231  {
232  filter_name_ = "CropBox";
233  }
234 
235  /** \brief Set the minimum point of the box
236  * \param[in] min_pt the minimum point of the box
237  */
238  inline void
239  setMin (const Eigen::Vector4f& min_pt)
240  {
241  min_pt_ = min_pt;
242  }
243 
244  /** \brief Get the value of the minimum point of the box, as set by the user
245  * \return the value of the internal \a min_pt parameter.
246  */
247  inline Eigen::Vector4f
248  getMin () const
249  {
250  return (min_pt_);
251  }
252 
253  /** \brief Set the maximum point of the box
254  * \param[in] max_pt the maximum point of the box
255  */
256  inline void
257  setMax (const Eigen::Vector4f &max_pt)
258  {
259  max_pt_ = max_pt;
260  }
261 
262  /** \brief Get the value of the maxiomum point of the box, as set by the user
263  * \return the value of the internal \a max_pt parameter.
264  */
265  inline Eigen::Vector4f
266  getMax () const
267  {
268  return (max_pt_);
269  }
270 
271  /** \brief Set a translation value for the box
272  * \param[in] translation the (tx,ty,tz) values that the box should be translated by
273  */
274  inline void
275  setTranslation (const Eigen::Vector3f &translation)
276  {
277  translation_ = translation;
278  }
279 
280  /** \brief Get the value of the box translation parameter as set by the user. */
281  inline Eigen::Vector3f
282  getTranslation () const
283  {
284  return (translation_);
285  }
286 
287  /** \brief Set a rotation value for the box
288  * \param[in] rotation the (rx,ry,rz) values that the box should be rotated by
289  */
290  inline void
291  setRotation (const Eigen::Vector3f &rotation)
292  {
293  rotation_ = rotation;
294  }
295 
296  /** \brief Get the value of the box rotatation parameter, as set by the user. */
297  inline Eigen::Vector3f
298  getRotation () const
299  {
300  return (rotation_);
301  }
302 
303  /** \brief Set a transformation that should be applied to the cloud before filtering
304  * \param[in] transform an affine transformation that needs to be applied to the cloud before filtering
305  */
306  inline void
307  setTransform (const Eigen::Affine3f &transform)
308  {
309  transform_ = transform;
310  }
311 
312  /** \brief Get the value of the transformation parameter, as set by the user. */
313  inline Eigen::Affine3f
314  getTransform () const
315  {
316  return (transform_);
317  }
318 
319  protected:
320  /** \brief Sample of point indices into a separate PointCloud
321  * \param output the resultant point cloud
322  */
323  void
324  applyFilter (PCLPointCloud2 &output);
325 
326  /** \brief Sample of point indices
327  * \param indices the resultant point cloud indices
328  */
329  void
330  applyFilter (std::vector<int> &indices);
331 
332  /** \brief The minimum point of the box. */
333  Eigen::Vector4f min_pt_;
334  /** \brief The maximum point of the box. */
335  Eigen::Vector4f max_pt_;
336  /** \brief The 3D translation for the box. */
337  Eigen::Vector3f translation_;
338  /** \brief The 3D rotation for the box. */
339  Eigen::Vector3f rotation_;
340  /** \brief The affine transform applied to the cloud. */
341  Eigen::Affine3f transform_;
342  };
343 }
344 
345 #ifdef PCL_NO_PRECOMPILE
346 #include <pcl/filters/impl/crop_box.hpp>
347 #endif
348 
349 #endif // PCL_FILTERS_CROP_BOX_H_
void setRotation(const Eigen::Vector3f &rotation)
Set a rotation value for the box.
Definition: crop_box.h:140
Eigen::Vector3f getTranslation() const
Get the value of the box translation parameter as set by the user.
Definition: crop_box.h:131
Eigen::Vector4f getMin() const
Get the value of the minimum point of the box, as set by the user.
Definition: crop_box.h:248
boost::shared_ptr< const PointCloud< PointT > > ConstPtr
Definition: point_cloud.h:429
PointCloud::ConstPtr PointCloudConstPtr
Definition: pcl_base.h:73
boost::shared_ptr< const CropBox< PointT > > ConstPtr
Definition: crop_box.h:68
boost::shared_ptr< PointCloud< PointT > > Ptr
Definition: point_cloud.h:428
void setMin(const Eigen::Vector4f &min_pt)
Set the minimum point of the box.
Definition: crop_box.h:88
Eigen::Vector4f min_pt_
The minimum point of the box.
Definition: crop_box.h:333
boost::shared_ptr< ::pcl::PCLPointCloud2 const > PCLPointCloud2ConstPtr
Eigen::Vector3f getTranslation() const
Get the value of the box translation parameter as set by the user.
Definition: crop_box.h:282
boost::shared_ptr< ::pcl::PCLPointCloud2 > Ptr
Eigen::Affine3f getTransform() const
Get the value of the transformation parameter, as set by the user.
Definition: crop_box.h:314
Eigen::Affine3f getTransform() const
Get the value of the transformation parameter, as set by the user.
Definition: crop_box.h:163
void setTransform(const Eigen::Affine3f &transform)
Set a transformation that should be applied to the cloud before filtering.
Definition: crop_box.h:307
FilterIndices represents the base class for filters that are about binary point removal.
PointCloud::Ptr PointCloudPtr
Definition: pcl_base.h:72
Eigen::Vector4f getMax() const
Get the value of the maxiomum point of the box, as set by the user.
Definition: crop_box.h:115
Filter represents the base filter class.
Definition: filter.h:84
boost::shared_ptr< CropBox< PointT > > Ptr
Definition: crop_box.h:67
CropBox is a filter that allows the user to filter all the data inside of a given box...
Definition: crop_box.h:57
Eigen::Vector4f getMin() const
Get the value of the minimum point of the box, as set by the user.
Definition: crop_box.h:97
PCL base class.
Definition: pcl_base.h:68
Eigen::Vector4f getMax() const
Get the value of the maxiomum point of the box, as set by the user.
Definition: crop_box.h:266
Eigen::Vector3f rotation_
The 3D rotation for the box.
Definition: crop_box.h:339
Eigen::Vector3f getRotation() const
Get the value of the box rotatation parameter, as set by the user.
Definition: crop_box.h:147
void setTransform(const Eigen::Affine3f &transform)
Set a transformation that should be applied to the cloud before filtering.
Definition: crop_box.h:156
boost::shared_ptr< ::pcl::PCLPointCloud2 const > ConstPtr
CropBox(bool extract_removed_indices=false)
Constructor.
Definition: crop_box.h:224
Eigen::Vector3f translation_
The 3D translation for the box.
Definition: crop_box.h:337
void setRotation(const Eigen::Vector3f &rotation)
Set a rotation value for the box.
Definition: crop_box.h:291
boost::shared_ptr< ::pcl::PCLPointCloud2 > PCLPointCloud2Ptr
Eigen::Affine3f transform_
The affine transform applied to the cloud.
Definition: crop_box.h:341
Eigen::Vector3f getRotation() const
Get the value of the box rotatation parameter, as set by the user.
Definition: crop_box.h:298
Eigen::Vector4f max_pt_
The maximum point of the box.
Definition: crop_box.h:335
void setMax(const Eigen::Vector4f &max_pt)
Set the maximum point of the box.
Definition: crop_box.h:106
CropBox(bool extract_removed_indices=false)
Constructor.
Definition: crop_box.h:73
void setTranslation(const Eigen::Vector3f &translation)
Set a translation value for the box.
Definition: crop_box.h:275
std::string filter_name_
The filter name.
Definition: filter.h:166
A point structure representing Euclidean xyz coordinates, and the RGB color.
void setMax(const Eigen::Vector4f &max_pt)
Set the maximum point of the box.
Definition: crop_box.h:257
void setTranslation(const Eigen::Vector3f &translation)
Set a translation value for the box.
Definition: crop_box.h:124
void setMin(const Eigen::Vector4f &min_pt)
Set the minimum point of the box.
Definition: crop_box.h:239
void applyFilter(PointCloud &output)
Sample of point indices into a separate PointCloud.
Definition: crop_box.hpp:49