Point Cloud Library (PCL)  1.6.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
crop_hull.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) 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  */
37 
38 #ifndef PCL_FILTERS_CROP_HULL_H_
39 #define PCL_FILTERS_CROP_HULL_H_
40 
41 #include <pcl/point_types.h>
42 #include <pcl/Vertices.h>
44 
45 namespace pcl
46 {
52  template<typename PointT>
53  class CropHull: public FilterIndices<PointT>
54  {
58 
59  typedef typename Filter<PointT>::PointCloud PointCloud;
60  typedef typename PointCloud::Ptr PointCloudPtr;
62 
63  public:
65  CropHull () :
66  hull_polygons_(),
67  hull_cloud_(),
68  dim_(3),
69  crop_outside_(true)
70  {
71  filter_name_ = "CropHull";
72  }
73 
78  inline void
79  setHullIndices (const std::vector<Vertices>& polygons)
80  {
81  hull_polygons_ = polygons;
82  }
83 
86  std::vector<Vertices>
87  getHullIndices () const
88  {
89  return (hull_polygons_);
90  }
91 
95  inline void
97  {
98  hull_cloud_ = points;
99  }
100 
103  getHullCloud () const
104  {
105  return (hull_cloud_);
106  }
107 
114  inline void
115  setDim (int dim)
116  {
117  dim_ = dim;
118  }
119 
124  inline void
125  setCropOutside(bool crop_outside)
126  {
127  crop_outside_ = crop_outside;
128  }
129 
130  protected:
134  void
135  applyFilter (PointCloud &output);
136 
140  void
141  applyFilter (std::vector<int> &indices);
142 
143  private:
148  Eigen::Vector3f
149  getHullCloudRange ();
150 
157  template<unsigned PlaneDim1, unsigned PlaneDim2> void
158  applyFilter2D (PointCloud &output);
159 
167  template<unsigned PlaneDim1, unsigned PlaneDim2> void
168  applyFilter2D (std::vector<int> &indices);
169 
178  void
179  applyFilter3D (PointCloud &output);
180 
189  void
190  applyFilter3D (std::vector<int> &indices);
191 
198  template<unsigned PlaneDim1, unsigned PlaneDim2> inline static bool
199  isPointIn2DPolyWithVertIndices (const PointT& point,
200  const Vertices& verts,
201  const PointCloud& cloud);
202 
211  inline static bool
212  rayTriangleIntersect (const PointT& point,
213  const Eigen::Vector3f& ray,
214  const Vertices& verts,
215  const PointCloud& cloud);
216 
217 
219  std::vector<pcl::Vertices> hull_polygons_;
220 
222  PointCloudPtr hull_cloud_;
223 
225  int dim_;
226 
230  bool crop_outside_;
231  };
232 
233 } // namespace pcl
234 
235 #endif // ndef PCL_FILTERS_CROP_HULL_H_