Point Cloud Library (PCL)  1.9.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 #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  typedef typename Filter<PointT>::PointCloud PointCloud;
61  typedef typename PointCloud::Ptr PointCloudPtr;
63 
64  public:
65 
66  typedef boost::shared_ptr< CropBox<PointT> > Ptr;
67  typedef boost::shared_ptr< const CropBox<PointT> > ConstPtr;
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>::FilterIndices (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 into a separate PointCloud
178  * \param[out] output the resultant point cloud
179  */
180  void
181  applyFilter (PointCloud &output) override;
182 
183  /** \brief Sample of point indices
184  * \param[out] indices the resultant point cloud indices
185  */
186  void
187  applyFilter (std::vector<int> &indices) override;
188  private:
189  /** \brief The minimum point of the box. */
190  Eigen::Vector4f min_pt_;
191  /** \brief The maximum point of the box. */
192  Eigen::Vector4f max_pt_;
193  /** \brief The 3D rotation for the box. */
194  Eigen::Vector3f rotation_;
195  /** \brief The 3D translation for the box. */
196  Eigen::Vector3f translation_;
197  /** \brief The affine transform applied to the cloud. */
198  Eigen::Affine3f transform_;
199  };
200 
201  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
202  /** \brief CropBox is a filter that allows the user to filter all the data
203  * inside of a given box.
204  *
205  * \author Justin Rosen
206  * \ingroup filters
207  */
208  template<>
209  class PCL_EXPORTS CropBox<pcl::PCLPointCloud2> : public FilterIndices<pcl::PCLPointCloud2>
210  {
213 
217 
218  public:
219  /** \brief Constructor.
220  * \param[in] extract_removed_indices Set to true if you want to be able to extract the indices of points being removed (default = false).
221  */
222  CropBox (bool extract_removed_indices = false) :
223  FilterIndices<pcl::PCLPointCloud2>::FilterIndices (extract_removed_indices),
224  min_pt_(Eigen::Vector4f (-1, -1, -1, 1)),
225  max_pt_(Eigen::Vector4f (1, 1, 1, 1)),
226  translation_ (Eigen::Vector3f::Zero ()),
227  rotation_ (Eigen::Vector3f::Zero ()),
228  transform_(Eigen::Affine3f::Identity ())
229  {
230  filter_name_ = "CropBox";
231  }
232 
233  /** \brief Set the minimum point of the box
234  * \param[in] min_pt the minimum point of the box
235  */
236  inline void
237  setMin (const Eigen::Vector4f& min_pt)
238  {
239  min_pt_ = min_pt;
240  }
241 
242  /** \brief Get the value of the minimum point of the box, as set by the user
243  * \return the value of the internal \a min_pt parameter.
244  */
245  inline Eigen::Vector4f
246  getMin () const
247  {
248  return (min_pt_);
249  }
250 
251  /** \brief Set the maximum point of the box
252  * \param[in] max_pt the maximum point of the box
253  */
254  inline void
255  setMax (const Eigen::Vector4f &max_pt)
256  {
257  max_pt_ = max_pt;
258  }
259 
260  /** \brief Get the value of the maxiomum point of the box, as set by the user
261  * \return the value of the internal \a max_pt parameter.
262  */
263  inline Eigen::Vector4f
264  getMax () const
265  {
266  return (max_pt_);
267  }
268 
269  /** \brief Set a translation value for the box
270  * \param[in] translation the (tx,ty,tz) values that the box should be translated by
271  */
272  inline void
273  setTranslation (const Eigen::Vector3f &translation)
274  {
275  translation_ = translation;
276  }
277 
278  /** \brief Get the value of the box translation parameter as set by the user. */
279  inline Eigen::Vector3f
280  getTranslation () const
281  {
282  return (translation_);
283  }
284 
285  /** \brief Set a rotation value for the box
286  * \param[in] rotation the (rx,ry,rz) values that the box should be rotated by
287  */
288  inline void
289  setRotation (const Eigen::Vector3f &rotation)
290  {
291  rotation_ = rotation;
292  }
293 
294  /** \brief Get the value of the box rotatation parameter, as set by the user. */
295  inline Eigen::Vector3f
296  getRotation () const
297  {
298  return (rotation_);
299  }
300 
301  /** \brief Set a transformation that should be applied to the cloud before filtering
302  * \param[in] transform an affine transformation that needs to be applied to the cloud before filtering
303  */
304  inline void
305  setTransform (const Eigen::Affine3f &transform)
306  {
307  transform_ = transform;
308  }
309 
310  /** \brief Get the value of the transformation parameter, as set by the user. */
311  inline Eigen::Affine3f
312  getTransform () const
313  {
314  return (transform_);
315  }
316 
317  protected:
318  /** \brief Sample of point indices into a separate PointCloud
319  * \param output the resultant point cloud
320  */
321  void
322  applyFilter (PCLPointCloud2 &output) override;
323 
324  /** \brief Sample of point indices
325  * \param indices the resultant point cloud indices
326  */
327  void
328  applyFilter (std::vector<int> &indices) override;
329 
330  /** \brief The minimum point of the box. */
331  Eigen::Vector4f min_pt_;
332  /** \brief The maximum point of the box. */
333  Eigen::Vector4f max_pt_;
334  /** \brief The 3D translation for the box. */
335  Eigen::Vector3f translation_;
336  /** \brief The 3D rotation for the box. */
337  Eigen::Vector3f rotation_;
338  /** \brief The affine transform applied to the cloud. */
339  Eigen::Affine3f transform_;
340  };
341 }
342 
343 #ifdef PCL_NO_PRECOMPILE
344 #include <pcl/filters/impl/crop_box.hpp>
345 #endif
void setRotation(const Eigen::Vector3f &rotation)
Set a rotation value for the box.
Definition: crop_box.h:139
Eigen::Vector3f getTranslation() const
Get the value of the box translation parameter as set by the user.
Definition: crop_box.h:130
Eigen::Vector4f getMin() const
Get the value of the minimum point of the box, as set by the user.
Definition: crop_box.h:246
PointCloud::ConstPtr PointCloudConstPtr
Definition: pcl_base.h:73
boost::shared_ptr< const CropBox< PointT > > ConstPtr
Definition: crop_box.h:67
void setMin(const Eigen::Vector4f &min_pt)
Set the minimum point of the box.
Definition: crop_box.h:87
This file defines compatibility wrappers for low level I/O functions.
Definition: convolution.h:44
Eigen::Vector4f min_pt_
The minimum point of the box.
Definition: crop_box.h:331
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:280
Definition: bfgs.h:9
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:312
Eigen::Affine3f getTransform() const
Get the value of the transformation parameter, as set by the user.
Definition: crop_box.h:162
boost::shared_ptr< PointCloud< PointT > > Ptr
Definition: point_cloud.h:427
void setTransform(const Eigen::Affine3f &transform)
Set a transformation that should be applied to the cloud before filtering.
Definition: crop_box.h:305
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 maximum point of the box, as set by the user.
Definition: crop_box.h:114
Filter represents the base filter class.
Definition: filter.h:83
boost::shared_ptr< CropBox< PointT > > Ptr
Definition: crop_box.h:66
CropBox is a filter that allows the user to filter all the data inside of a given box...
Definition: crop_box.h:56
Eigen::Vector4f getMin() const
Get the value of the minimum point of the box, as set by the user.
Definition: crop_box.h:96
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:264
Eigen::Vector3f rotation_
The 3D rotation for the box.
Definition: crop_box.h:337
Eigen::Vector3f getRotation() const
Get the value of the box rotatation parameter, as set by the user.
Definition: crop_box.h:146
void setTransform(const Eigen::Affine3f &transform)
Set a transformation that should be applied to the cloud before filtering.
Definition: crop_box.h:155
boost::shared_ptr< const PointCloud< PointT > > ConstPtr
Definition: point_cloud.h:428
boost::shared_ptr< ::pcl::PCLPointCloud2 const > ConstPtr
CropBox(bool extract_removed_indices=false)
Constructor.
Definition: crop_box.h:222
Eigen::Vector3f translation_
The 3D translation for the box.
Definition: crop_box.h:335
PointCloud represents the base class in PCL for storing collections of 3D points. ...
void setRotation(const Eigen::Vector3f &rotation)
Set a rotation value for the box.
Definition: crop_box.h:289
void applyFilter(PointCloud &output) override
Sample of point indices into a separate PointCloud.
Definition: crop_box.hpp:49
boost::shared_ptr< ::pcl::PCLPointCloud2 > PCLPointCloud2Ptr
Eigen::Affine3f transform_
The affine transform applied to the cloud.
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:296
Eigen::Vector4f max_pt_
The maximum point of the box.
Definition: crop_box.h:333
void setMax(const Eigen::Vector4f &max_pt)
Set the maximum point of the box.
Definition: crop_box.h:105
CropBox(bool extract_removed_indices=false)
Constructor.
Definition: crop_box.h:72
void setTranslation(const Eigen::Vector3f &translation)
Set a translation value for the box.
Definition: crop_box.h:273
std::string filter_name_
The filter name.
Definition: filter.h:164
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:255
void setTranslation(const Eigen::Vector3f &translation)
Set a translation value for the box.
Definition: crop_box.h:123
void setMin(const Eigen::Vector4f &min_pt)
Set the minimum point of the box.
Definition: crop_box.h:237