Point Cloud Library (PCL) 1.12.1
crop_hull.h
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 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 */
37
38#pragma once
39
40#include <pcl/Vertices.h>
41#include <pcl/filters/filter_indices.h>
42
43namespace pcl
44{
45 /** \brief Filter points that lie inside or outside a 3D closed surface or 2D
46 * closed polygon, as generated by the ConvexHull or ConcaveHull classes.
47 * \author James Crosby
48 * \ingroup filters
49 */
50 template<typename PointT>
51 class CropHull: public FilterIndices<PointT>
52 {
57
59 using PointCloudPtr = typename PointCloud::Ptr;
61
62 public:
63
64 using Ptr = shared_ptr<CropHull<PointT> >;
65 using ConstPtr = shared_ptr<const CropHull<PointT> >;
66
67 /** \brief Empty Constructor. */
69 hull_cloud_(),
70 dim_(3),
71 crop_outside_(true)
72 {
73 filter_name_ = "CropHull";
74 }
75
76 /** \brief Set the vertices of the hull used to filter points.
77 * \param[in] polygons Vector of polygons (Vertices structures) forming
78 * the hull used for filtering points.
79 */
80 inline void
81 setHullIndices (const std::vector<Vertices>& polygons)
82 {
83 hull_polygons_ = polygons;
84 }
85
86 /** \brief Get the vertices of the hull used to filter points.
87 */
88 std::vector<Vertices>
90 {
91 return (hull_polygons_);
92 }
93
94 /** \brief Set the point cloud that the hull indices refer to
95 * \param[in] points the point cloud that the hull indices refer to
96 */
97 inline void
99 {
100 hull_cloud_ = points;
101 }
102
103 /** \brief Get the point cloud that the hull indices refer to. */
104 PointCloudPtr
106 {
107 return (hull_cloud_);
108 }
109
110 /** \brief Set the dimensionality of the hull to be used.
111 * This should be set to correspond to the dimensionality of the
112 * convex/concave hull produced by the pcl::ConvexHull and
113 * pcl::ConcaveHull classes.
114 * \param[in] dim Dimensionailty of the hull used to filter points.
115 */
116 inline void
117 setDim (int dim)
118 {
119 dim_ = dim;
120 }
121
122 /** \brief Remove points outside the hull (default), or those inside the hull.
123 * \param[in] crop_outside If true, the filter will remove points
124 * outside the hull. If false, those inside will be removed.
125 */
126 inline void
127 setCropOutside(bool crop_outside)
128 {
129 crop_outside_ = crop_outside;
130 }
131
132 protected:
133 /** \brief Filter the input points using the 2D or 3D polygon hull.
134 * \param[out] output The set of points that passed the filter
135 */
136 void
137 applyFilter (PointCloud &output) override;
138
139 /** \brief Filter the input points using the 2D or 3D polygon hull.
140 * \param[out] indices the indices of the set of points that passed the filter.
141 */
142 void
143 applyFilter (Indices &indices) override;
144
145 private:
146 /** \brief Return the size of the hull point cloud in line with coordinate axes.
147 * This is used to choose the 2D projection to use when cropping to a 2d
148 * polygon.
149 */
150 Eigen::Vector3f
151 getHullCloudRange ();
152
153 /** \brief Apply the two-dimensional hull filter.
154 * All points are assumed to lie in the same plane as the 2D hull, an
155 * axis-aligned 2D coordinate system using the two dimensions specified
156 * (PlaneDim1, PlaneDim2) is used for calculations.
157 * \param[out] indices The indices of the set of points that pass the
158 * 2D polygon filter.
159 */
160 template<unsigned PlaneDim1, unsigned PlaneDim2> void
161 applyFilter2D (Indices &indices);
162
163 /** \brief Apply the three-dimensional hull filter.
164 * Polygon-ray crossings are used for three rays cast from each point
165 * being tested, and a majority vote of the resulting
166 * polygon-crossings is used to decide whether the point lies inside
167 * or outside the hull.
168 * \param[out] indices The indices of the set of points that pass the 3D
169 * polygon hull filter.
170 */
171 void
172 applyFilter3D (Indices &indices);
173
174 /** \brief Test an individual point against a 2D polygon.
175 * PlaneDim1 and PlaneDim2 specify the x/y/z coordinate axes to use.
176 * \param[in] point Point to test against the polygon.
177 * \param[in] verts Vertex indices of polygon.
178 * \param[in] cloud Cloud from which the vertex indices are drawn.
179 */
180 template<unsigned PlaneDim1, unsigned PlaneDim2> inline static bool
181 isPointIn2DPolyWithVertIndices (const PointT& point,
182 const Vertices& verts,
183 const PointCloud& cloud);
184
185 /** \brief Does a ray cast from a point intersect with an arbitrary
186 * triangle in 3D?
187 * See: http://softsurfer.com/Archive/algorithm_0105/algorithm_0105.htm#intersect_RayTriangle()
188 * \param[in] point Point from which the ray is cast.
189 * \param[in] ray Vector in direction of ray.
190 * \param[in] verts Indices of vertices making the polygon.
191 * \param[in] cloud Cloud from which the vertex indices are drawn.
192 */
193 inline static bool
194 rayTriangleIntersect (const PointT& point,
195 const Eigen::Vector3f& ray,
196 const Vertices& verts,
197 const PointCloud& cloud);
198
199
200 /** \brief The vertices of the hull used to filter points. */
201 std::vector<pcl::Vertices> hull_polygons_;
202
203 /** \brief The point cloud that the hull indices refer to. */
204 PointCloudPtr hull_cloud_;
205
206 /** \brief The dimensionality of the hull to be used. */
207 int dim_;
208
209 /** \brief If true, the filter will remove points outside the hull. If
210 * false, those inside will be removed.
211 */
212 bool crop_outside_;
213 };
214
215} // namespace pcl
216
217#ifdef PCL_NO_PRECOMPILE
218#include <pcl/filters/impl/crop_hull.hpp>
219#endif
Filter points that lie inside or outside a 3D closed surface or 2D closed polygon,...
Definition: crop_hull.h:52
void setHullIndices(const std::vector< Vertices > &polygons)
Set the vertices of the hull used to filter points.
Definition: crop_hull.h:81
std::vector< Vertices > getHullIndices() const
Get the vertices of the hull used to filter points.
Definition: crop_hull.h:89
void applyFilter(PointCloud &output) override
Filter the input points using the 2D or 3D polygon hull.
Definition: crop_hull.hpp:48
void setCropOutside(bool crop_outside)
Remove points outside the hull (default), or those inside the hull.
Definition: crop_hull.h:127
CropHull()
Empty Constructor.
Definition: crop_hull.h:68
void setDim(int dim)
Set the dimensionality of the hull to be used.
Definition: crop_hull.h:117
shared_ptr< CropHull< PointT > > Ptr
Definition: crop_hull.h:64
shared_ptr< const CropHull< PointT > > ConstPtr
Definition: crop_hull.h:65
void setHullCloud(PointCloudPtr points)
Set the point cloud that the hull indices refer to.
Definition: crop_hull.h:98
PointCloudPtr getHullCloud() const
Get the point cloud that the hull indices refer to.
Definition: crop_hull.h:105
Filter represents the base filter class.
Definition: filter.h:81
std::string filter_name_
The filter name.
Definition: filter.h:158
IndicesPtr removed_indices_
Indices of the points that are removed.
Definition: filter.h:155
FilterIndices represents the base class for filters that are about binary point removal.
PointCloudConstPtr input_
The input point cloud dataset.
Definition: pcl_base.h:147
typename PointCloud::Ptr PointCloudPtr
Definition: pcl_base.h:73
typename PointCloud::ConstPtr PointCloudConstPtr
Definition: pcl_base.h:74
IndicesPtr indices_
A pointer to the vector of point indices to use.
Definition: pcl_base.h:150
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
IndicesAllocator<> Indices
Type used for indices in PCL.
Definition: types.h:133
A point structure representing Euclidean xyz coordinates, and the RGB color.
Describes a set of vertices in a polygon mesh, by basically storing an array of indices.
Definition: Vertices.h:15