Point Cloud Library (PCL)  1.6.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
crop_box.h
Go to the documentation of this file.
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 Willow Garage, Inc. 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 4865 2012-03-01 02:07:13Z rusu $
37  *
38  */
39 
40 #ifndef PCL_FILTERS_CROP_BOX_H_
41 #define PCL_FILTERS_CROP_BOX_H_
42 
43 #include <pcl/point_types.h>
45 #include <pcl/common/transforms.h>
46 #include <pcl/common/eigen.h>
47 
48 namespace pcl
49 {
56  template<typename PointT>
57  class CropBox : public FilterIndices<PointT>
58  {
63 
64  typedef typename Filter<PointT>::PointCloud PointCloud;
65  typedef typename PointCloud::Ptr PointCloudPtr;
67 
68  public:
70  CropBox () :
71  min_pt_ (Eigen::Vector4f (-1, -1, -1, 1)),
72  max_pt_ (Eigen::Vector4f (1, 1, 1, 1)),
73  rotation_ (Eigen::Vector3f::Zero ()),
74  translation_ (Eigen::Vector3f::Zero ()),
75  transform_ (Eigen::Affine3f::Identity ())
76  {
77  filter_name_ = "CropBox";
78  }
79 
83  inline void
84  setMin (const Eigen::Vector4f &min_pt)
85  {
86  min_pt_ = min_pt;
87  }
88 
92  inline Eigen::Vector4f
93  getMin () const
94  {
95  return (min_pt_);
96  }
97 
101  inline void
102  setMax (const Eigen::Vector4f &max_pt)
103  {
104  max_pt_ = max_pt;
105  }
106 
110  inline Eigen::Vector4f
111  getMax () const
112  {
113  return (max_pt_);
114  }
115 
119  inline void
120  setTranslation (const Eigen::Vector3f &translation)
121  {
122  translation_ = translation;
123  }
124 
126  Eigen::Vector3f
127  getTranslation () const
128  {
129  return (translation_);
130  }
131 
135  inline void
136  setRotation (const Eigen::Vector3f &rotation)
137  {
138  rotation_ = rotation;
139  }
140 
142  inline Eigen::Vector3f
143  getRotation () const
144  {
145  return (rotation_);
146  }
147 
151  inline void
152  setTransform (const Eigen::Affine3f &transform)
153  {
154  transform_ = transform;
155  }
156 
158  inline Eigen::Affine3f
159  getTransform () const
160  {
161  return (transform_);
162  }
163 
164  protected:
168  void
169  applyFilter (PointCloud &output);
170 
174  void
175  applyFilter (std::vector<int> &indices);
176 
177  private:
179  Eigen::Vector4f min_pt_;
181  Eigen::Vector4f max_pt_;
183  Eigen::Vector3f rotation_;
185  Eigen::Vector3f translation_;
187  Eigen::Affine3f transform_;
188  };
189 
191 
197  template<>
198  class PCL_EXPORTS CropBox<sensor_msgs::PointCloud2> : public FilterIndices<sensor_msgs::PointCloud2>
199  {
202 
206 
207  public:
209  CropBox () :
210  min_pt_(Eigen::Vector4f (-1, -1, -1, 1)),
211  max_pt_(Eigen::Vector4f (1, 1, 1, 1)),
212  translation_ (Eigen::Vector3f::Zero ()),
213  rotation_ (Eigen::Vector3f::Zero ()),
214  transform_(Eigen::Affine3f::Identity ())
215  {
216  filter_name_ = "CropBox";
217  }
218 
222  inline void
223  setMin (const Eigen::Vector4f& min_pt)
224  {
225  min_pt_ = min_pt;
226  }
227 
231  inline Eigen::Vector4f
232  getMin () const
233  {
234  return (min_pt_);
235  }
236 
240  inline void
241  setMax (const Eigen::Vector4f &max_pt)
242  {
243  max_pt_ = max_pt;
244  }
245 
249  inline Eigen::Vector4f
250  getMax () const
251  {
252  return (max_pt_);
253  }
254 
258  inline void
259  setTranslation (const Eigen::Vector3f &translation)
260  {
261  translation_ = translation;
262  }
263 
265  inline Eigen::Vector3f
266  getTranslation () const
267  {
268  return (translation_);
269  }
270 
274  inline void
275  setRotation (const Eigen::Vector3f &rotation)
276  {
277  rotation_ = rotation;
278  }
279 
281  inline Eigen::Vector3f
282  getRotation () const
283  {
284  return (rotation_);
285  }
286 
290  inline void
291  setTransform (const Eigen::Affine3f &transform)
292  {
293  transform_ = transform;
294  }
295 
297  inline Eigen::Affine3f
298  getTransform () const
299  {
300  return (transform_);
301  }
302 
303  protected:
307  void
308  applyFilter (PointCloud2 &output);
309 
313  void
314  applyFilter (std::vector<int> &indices);
315 
317  Eigen::Vector4f min_pt_;
319  Eigen::Vector4f max_pt_;
321  Eigen::Vector3f translation_;
323  Eigen::Vector3f rotation_;
325  Eigen::Affine3f transform_;
326  };
327 }
328 
329 #endif // PCL_FILTERS_CROP_BOX_H_