Point Cloud Library (PCL)  1.14.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/filters/filter_indices.h>
43 
44 namespace pcl
45 {
46  /** \brief CropBox is a filter that allows the user to filter all the data
47  * inside of a given box.
48  *
49  * \author Justin Rosen
50  * \ingroup filters
51  */
52  template<typename PointT>
53  class CropBox : public FilterIndices<PointT>
54  {
56 
57  using PointCloud = typename Filter<PointT>::PointCloud;
58  using PointCloudPtr = typename PointCloud::Ptr;
60 
61  public:
63 
64  using Ptr = shared_ptr<CropBox<PointT> >;
65  using ConstPtr = shared_ptr<const CropBox<PointT> >;
66 
67  /** \brief Constructor.
68  * \param[in] extract_removed_indices Set to true if you want to be able to extract the indices of points being removed (default = false).
69  */
70  CropBox (bool extract_removed_indices = false) :
71  FilterIndices<PointT> (extract_removed_indices),
72  min_pt_ (Eigen::Vector4f (-1, -1, -1, 1)),
73  max_pt_ (Eigen::Vector4f (1, 1, 1, 1)),
74  rotation_ (Eigen::Vector3f::Zero ()),
75  translation_ (Eigen::Vector3f::Zero ()),
76  transform_ (Eigen::Affine3f::Identity ())
77  {
78  filter_name_ = "CropBox";
79  }
80 
81  /** \brief Set the minimum point of the box
82  * \param[in] min_pt the minimum point of the box
83  */
84  inline void
85  setMin (const Eigen::Vector4f &min_pt)
86  {
87  min_pt_ = min_pt;
88  }
89 
90  /** \brief Get the value of the minimum point of the box, as set by the user
91  * \return the value of the internal \a min_pt parameter.
92  */
93  inline Eigen::Vector4f
94  getMin () const
95  {
96  return (min_pt_);
97  }
98 
99  /** \brief Set the maximum point of the box
100  * \param[in] max_pt the maximum point of the box
101  */
102  inline void
103  setMax (const Eigen::Vector4f &max_pt)
104  {
105  max_pt_ = max_pt;
106  }
107 
108  /** \brief Get the value of the maximum point of the box, as set by the user
109  * \return the value of the internal \a max_pt parameter.
110  */
111  inline Eigen::Vector4f
112  getMax () const
113  {
114  return (max_pt_);
115  }
116 
117  /** \brief Set a translation value for the box
118  * \param[in] translation the (tx,ty,tz) values that the box should be translated by
119  */
120  inline void
121  setTranslation (const Eigen::Vector3f &translation)
122  {
123  translation_ = translation;
124  }
125 
126  /** \brief Get the value of the box translation parameter as set by the user. */
127  Eigen::Vector3f
128  getTranslation () const
129  {
130  return (translation_);
131  }
132 
133  /** \brief Set a rotation value for the box
134  * \param[in] rotation the (rx,ry,rz) values that the box should be rotated by
135  */
136  inline void
137  setRotation (const Eigen::Vector3f &rotation)
138  {
139  rotation_ = rotation;
140  }
141 
142  /** \brief Get the value of the box rotatation parameter, as set by the user. */
143  inline Eigen::Vector3f
144  getRotation () const
145  {
146  return (rotation_);
147  }
148 
149  /** \brief Set a transformation that should be applied to the cloud before filtering
150  * \param[in] transform an affine transformation that needs to be applied to the cloud before filtering
151  */
152  inline void
153  setTransform (const Eigen::Affine3f &transform)
154  {
155  transform_ = transform;
156  }
157 
158  /** \brief Get the value of the transformation parameter, as set by the user. */
159  inline Eigen::Affine3f
160  getTransform () const
161  {
162  return (transform_);
163  }
164 
165  protected:
174 
175  /** \brief Sample of point indices
176  * \param[out] indices the resultant point cloud indices
177  */
178  void
179  applyFilter (Indices &indices) override;
180  private:
181  /** \brief The minimum point of the box. */
182  Eigen::Vector4f min_pt_;
183  /** \brief The maximum point of the box. */
184  Eigen::Vector4f max_pt_;
185  /** \brief The 3D rotation for the box. */
186  Eigen::Vector3f rotation_;
187  /** \brief The 3D translation for the box. */
188  Eigen::Vector3f translation_;
189  /** \brief The affine transform applied to the cloud. */
190  Eigen::Affine3f transform_;
191  };
192 
193  //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
194  /** \brief CropBox is a filter that allows the user to filter all the data
195  * inside of a given box.
196  *
197  * \author Justin Rosen
198  * \ingroup filters
199  */
200  template<>
201  class PCL_EXPORTS CropBox<pcl::PCLPointCloud2> : public FilterIndices<pcl::PCLPointCloud2>
202  {
205 
209 
210  public:
212 
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 (Indices &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 applyFilter(Indices &indices) override
Sample of point indices.
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
PCL_MAKE_ALIGNED_OPERATOR_NEW 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
CropBox is a filter that allows the user to filter all the data inside of a given box.
Definition: crop_box.h:54
void setRotation(const Eigen::Vector3f &rotation)
Set a rotation value for the box.
Definition: crop_box.h:137
Eigen::Vector3f getRotation() const
Get the value of the box rotatation parameter, as set by the user.
Definition: crop_box.h:144
void applyFilter(Indices &indices) override
Sample of point indices.
Definition: crop_box.hpp:51
CropBox(bool extract_removed_indices=false)
Constructor.
Definition: crop_box.h:70
void setTransform(const Eigen::Affine3f &transform)
Set a transformation that should be applied to the cloud before filtering.
Definition: crop_box.h:153
Eigen::Vector4f getMax() const
Get the value of the maximum point of the box, as set by the user.
Definition: crop_box.h:112
Eigen::Vector4f getMin() const
Get the value of the minimum point of the box, as set by the user.
Definition: crop_box.h:94
shared_ptr< CropBox< PointT > > Ptr
Definition: crop_box.h:64
void setMin(const Eigen::Vector4f &min_pt)
Set the minimum point of the box.
Definition: crop_box.h:85
void setTranslation(const Eigen::Vector3f &translation)
Set a translation value for the box.
Definition: crop_box.h:121
shared_ptr< const CropBox< PointT > > ConstPtr
Definition: crop_box.h:65
Eigen::Vector3f getTranslation() const
Get the value of the box translation parameter as set by the user.
Definition: crop_box.h:128
void setMax(const Eigen::Vector4f &max_pt)
Set the maximum point of the box.
Definition: crop_box.h:103
Eigen::Affine3f getTransform() const
Get the value of the transformation parameter, as set by the user.
Definition: crop_box.h:160
Filter represents the base filter class.
Definition: filter.h:81
std::string filter_name_
The filter name.
Definition: filter.h:158
FilterIndices represents the base class for filters that are about binary point removal.
PCLPointCloud2::Ptr PCLPointCloud2Ptr
Definition: pcl_base.h:185
PCLPointCloud2::ConstPtr PCLPointCloud2ConstPtr
Definition: pcl_base.h:186
PCL base class.
Definition: pcl_base.h:70
typename PointCloud::Ptr PointCloudPtr
Definition: pcl_base.h:73
typename PointCloud::ConstPtr PointCloudConstPtr
Definition: pcl_base.h:74
PointCloud represents the base class in PCL for storing collections of 3D points.
Definition: point_cloud.h:173
shared_ptr< PointCloud< PointT > > Ptr
Definition: point_cloud.h:413
shared_ptr< const PointCloud< PointT > > ConstPtr
Definition: point_cloud.h:414
#define PCL_MAKE_ALIGNED_OPERATOR_NEW
Macro to signal a class requires a custom allocator.
Definition: memory.h:63
Definition: bfgs.h:10
IndicesAllocator<> Indices
Type used for indices in PCL.
Definition: types.h:133
#define PCL_EXPORTS
Definition: pcl_macros.h:323
shared_ptr< ::pcl::PCLPointCloud2 > Ptr
shared_ptr< const ::pcl::PCLPointCloud2 > ConstPtr
A point structure representing Euclidean xyz coordinates, and the RGB color.