Point Cloud Library (PCL)  1.8.1-dev
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
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  private:
190  /** \brief The minimum point of the box. */
191  Eigen::Vector4f min_pt_;
192  /** \brief The maximum point of the box. */
193  Eigen::Vector4f max_pt_;
194  /** \brief The 3D rotation for the box. */
195  Eigen::Vector3f rotation_;
196  /** \brief The 3D translation for the box. */
197  Eigen::Vector3f translation_;
198  /** \brief The affine transform applied to the cloud. */
199  Eigen::Affine3f transform_;
200  };
201 
202  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
203  /** \brief CropBox is a filter that allows the user to filter all the data
204  * inside of a given box.
205  *
206  * \author Justin Rosen
207  * \ingroup filters
208  */
209  template<>
210  class PCL_EXPORTS CropBox<pcl::PCLPointCloud2> : public FilterIndices<pcl::PCLPointCloud2>
211  {
214 
218 
219  public:
220  /** \brief Constructor.
221  * \param[in] extract_removed_indices Set to true if you want to be able to extract the indices of points being removed (default = false).
222  */
223  CropBox (bool extract_removed_indices = false) :
224  FilterIndices<pcl::PCLPointCloud2>::FilterIndices (extract_removed_indices),
225  min_pt_(Eigen::Vector4f (-1, -1, -1, 1)),
226  max_pt_(Eigen::Vector4f (1, 1, 1, 1)),
227  translation_ (Eigen::Vector3f::Zero ()),
228  rotation_ (Eigen::Vector3f::Zero ()),
229  transform_(Eigen::Affine3f::Identity ())
230  {
231  filter_name_ = "CropBox";
232  }
233 
234  /** \brief Set the minimum point of the box
235  * \param[in] min_pt the minimum point of the box
236  */
237  inline void
238  setMin (const Eigen::Vector4f& min_pt)
239  {
240  min_pt_ = min_pt;
241  }
242 
243  /** \brief Get the value of the minimum point of the box, as set by the user
244  * \return the value of the internal \a min_pt parameter.
245  */
246  inline Eigen::Vector4f
247  getMin () const
248  {
249  return (min_pt_);
250  }
251 
252  /** \brief Set the maximum point of the box
253  * \param[in] max_pt the maximum point of the box
254  */
255  inline void
256  setMax (const Eigen::Vector4f &max_pt)
257  {
258  max_pt_ = max_pt;
259  }
260 
261  /** \brief Get the value of the maxiomum point of the box, as set by the user
262  * \return the value of the internal \a max_pt parameter.
263  */
264  inline Eigen::Vector4f
265  getMax () const
266  {
267  return (max_pt_);
268  }
269 
270  /** \brief Set a translation value for the box
271  * \param[in] translation the (tx,ty,tz) values that the box should be translated by
272  */
273  inline void
274  setTranslation (const Eigen::Vector3f &translation)
275  {
276  translation_ = translation;
277  }
278 
279  /** \brief Get the value of the box translation parameter as set by the user. */
280  inline Eigen::Vector3f
281  getTranslation () const
282  {
283  return (translation_);
284  }
285 
286  /** \brief Set a rotation value for the box
287  * \param[in] rotation the (rx,ry,rz) values that the box should be rotated by
288  */
289  inline void
290  setRotation (const Eigen::Vector3f &rotation)
291  {
292  rotation_ = rotation;
293  }
294 
295  /** \brief Get the value of the box rotatation parameter, as set by the user. */
296  inline Eigen::Vector3f
297  getRotation () const
298  {
299  return (rotation_);
300  }
301 
302  /** \brief Set a transformation that should be applied to the cloud before filtering
303  * \param[in] transform an affine transformation that needs to be applied to the cloud before filtering
304  */
305  inline void
306  setTransform (const Eigen::Affine3f &transform)
307  {
308  transform_ = transform;
309  }
310 
311  /** \brief Get the value of the transformation parameter, as set by the user. */
312  inline Eigen::Affine3f
313  getTransform () const
314  {
315  return (transform_);
316  }
317 
318  protected:
319  /** \brief Sample of point indices into a separate PointCloud
320  * \param output the resultant point cloud
321  */
322  void
323  applyFilter (PCLPointCloud2 &output);
324 
325  /** \brief Sample of point indices
326  * \param indices the resultant point cloud indices
327  */
328  void
329  applyFilter (std::vector<int> &indices);
330 
331  /** \brief The minimum point of the box. */
332  Eigen::Vector4f min_pt_;
333  /** \brief The maximum point of the box. */
334  Eigen::Vector4f max_pt_;
335  /** \brief The 3D translation for the box. */
336  Eigen::Vector3f translation_;
337  /** \brief The 3D rotation for the box. */
338  Eigen::Vector3f rotation_;
339  /** \brief The affine transform applied to the cloud. */
340  Eigen::Affine3f transform_;
341  };
342 }
343 
344 #ifdef PCL_NO_PRECOMPILE
345 #include <pcl/filters/impl/crop_box.hpp>
346 #endif
347 
348 #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:247
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:332
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:281
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:313
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:306
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:265
Eigen::Vector3f rotation_
The 3D rotation for the box.
Definition: crop_box.h:338
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:223
Eigen::Vector3f translation_
The 3D translation for the box.
Definition: crop_box.h:336
void setRotation(const Eigen::Vector3f &rotation)
Set a rotation value for the box.
Definition: crop_box.h:290
boost::shared_ptr< ::pcl::PCLPointCloud2 > PCLPointCloud2Ptr
Eigen::Affine3f transform_
The affine transform applied to the cloud.
Definition: crop_box.h:340
Eigen::Vector3f getRotation() const
Get the value of the box rotatation parameter, as set by the user.
Definition: crop_box.h:297
Eigen::Vector4f max_pt_
The maximum point of the box.
Definition: crop_box.h:334
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:274
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:256
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:238
void applyFilter(PointCloud &output)
Sample of point indices into a separate PointCloud.
Definition: crop_box.hpp:49