Point Cloud Library (PCL) 1.13.0
Loading...
Searching...
No Matches
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
58 using PointCloud = typename Filter<PointT>::PointCloud;
59 using PointCloudPtr = typename PointCloud::Ptr;
60 using PointCloudConstPtr = typename PointCloud::ConstPtr;
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
98 setHullCloud (PointCloudPtr points)
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
134 /** \brief Filter the input points using the 2D or 3D polygon hull.
135 * \param[out] indices the indices of the set of points that passed the filter.
136 */
137 void
138 applyFilter (Indices &indices) override;
139
140 private:
141 /** \brief Return the size of the hull point cloud in line with coordinate axes.
142 * This is used to choose the 2D projection to use when cropping to a 2d
143 * polygon.
144 */
145 Eigen::Vector3f
146 getHullCloudRange ();
147
148 /** \brief Apply the two-dimensional hull filter.
149 * All points are assumed to lie in the same plane as the 2D hull, an
150 * axis-aligned 2D coordinate system using the two dimensions specified
151 * (PlaneDim1, PlaneDim2) is used for calculations.
152 * \param[out] indices The indices of the set of points that pass the
153 * 2D polygon filter.
154 */
155 template<unsigned PlaneDim1, unsigned PlaneDim2> void
156 applyFilter2D (Indices &indices);
157
158 /** \brief Apply the three-dimensional hull filter.
159 * Polygon-ray crossings are used for three rays cast from each point
160 * being tested, and a majority vote of the resulting
161 * polygon-crossings is used to decide whether the point lies inside
162 * or outside the hull.
163 * \param[out] indices The indices of the set of points that pass the 3D
164 * polygon hull filter.
165 */
166 void
167 applyFilter3D (Indices &indices);
168
169 /** \brief Test an individual point against a 2D polygon.
170 * PlaneDim1 and PlaneDim2 specify the x/y/z coordinate axes to use.
171 * \param[in] point Point to test against the polygon.
172 * \param[in] verts Vertex indices of polygon.
173 * \param[in] cloud Cloud from which the vertex indices are drawn.
174 */
175 template<unsigned PlaneDim1, unsigned PlaneDim2> inline static bool
176 isPointIn2DPolyWithVertIndices (const PointT& point,
177 const Vertices& verts,
178 const PointCloud& cloud);
179
180 /** \brief Does a ray cast from a point intersect with an arbitrary
181 * triangle in 3D?
182 * See: http://softsurfer.com/Archive/algorithm_0105/algorithm_0105.htm#intersect_RayTriangle()
183 * \param[in] point Point from which the ray is cast.
184 * \param[in] ray Vector in direction of ray.
185 * \param[in] verts Indices of vertices making the polygon.
186 * \param[in] cloud Cloud from which the vertex indices are drawn.
187 */
188 inline static bool
189 rayTriangleIntersect (const PointT& point,
190 const Eigen::Vector3f& ray,
191 const Vertices& verts,
192 const PointCloud& cloud);
193
194
195 /** \brief The vertices of the hull used to filter points. */
196 std::vector<pcl::Vertices> hull_polygons_;
197
198 /** \brief The point cloud that the hull indices refer to. */
199 PointCloudPtr hull_cloud_;
200
201 /** \brief The dimensionality of the hull to be used. */
202 int dim_;
203
204 /** \brief If true, the filter will remove points outside the hull. If
205 * false, those inside will be removed.
206 */
207 bool crop_outside_;
208 };
209
210} // namespace pcl
211
212#ifdef PCL_NO_PRECOMPILE
213#include <pcl/filters/impl/crop_hull.hpp>
214#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 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 applyFilter(Indices &indices) override
Filter the input points using the 2D or 3D polygon hull.
Definition crop_hull.hpp:46
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
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.
shared_ptr< PointCloud< PointT > > Ptr
shared_ptr< const PointCloud< PointT > > ConstPtr
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