Point Cloud Library (PCL)
1.15.1
Toggle main menu visibility
Loading...
Searching...
No Matches
pcl
segmentation
extract_polygonal_prism_data.h
1
/*
2
* Software License Agreement (BSD License)
3
*
4
* Copyright (c) 2010, Willow Garage, Inc.
5
* All rights reserved.
6
*
7
* Redistribution and use in source and binary forms, with or without
8
* modification, are permitted provided that the following conditions
9
* are met:
10
*
11
* * Redistributions of source code must retain the above copyright
12
* notice, this list of conditions and the following disclaimer.
13
* * Redistributions in binary form must reproduce the above
14
* copyright notice, this list of conditions and the following
15
* disclaimer in the documentation and/or other materials provided
16
* with the distribution.
17
* * Neither the name of the copyright holder(s) nor the names of its
18
* contributors may be used to endorse or promote products derived
19
* from this software without specific prior written permission.
20
*
21
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32
* POSSIBILITY OF SUCH DAMAGE.
33
*
34
* $Id$
35
*
36
*/
37
38
#pragma once
39
40
#include <limits>
41
42
#include <pcl/pcl_base.h>
43
#include <pcl/Vertices.h>
// for Vertices
44
45
namespace
pcl
46
{
47
/** \brief General purpose method for checking if a 3D point is inside or
48
* outside a given 2D polygon.
49
* \note this method accepts any general 3D point that is projected onto the
50
* 2D polygon, but performs an internal XY projection of both the polygon and the point.
51
* \param point a 3D point projected onto the same plane as the polygon
52
* \param polygon a polygon
53
* \ingroup segmentation
54
*/
55
template
<
typename
Po
int
T>
bool
56
isPointIn2DPolygon
(
const
PointT &point,
const
pcl::PointCloud<PointT> &polygon);
57
58
/** \brief Check if a 2d point (X and Y coordinates considered only!) is
59
* inside or outside a given polygon. This method assumes that both the point
60
* and the polygon are projected onto the XY plane.
61
*
62
* \note (This is highly optimized code taken from http://www.visibone.com/inpoly/)
63
* Copyright (c) 1995-1996 Galacticomm, Inc. Freeware source code.
64
* \param point a 2D point projected onto the same plane as the polygon
65
* \param polygon a polygon
66
* \ingroup segmentation
67
*/
68
template
<
typename
Po
int
T>
bool
69
isXYPointIn2DXYPolygon
(
const
PointT &point,
const
pcl::PointCloud<PointT> &polygon);
70
71
////////////////////////////////////////////////////////////////////////////////////////////
72
/** \brief @b ExtractPolygonalPrismData uses a set of point indices that
73
* represent a planar model, and together with a given height, generates a 3D
74
* polygonal prism. The polygonal prism is then used to segment all points
75
* lying inside it.
76
*
77
* An example of its usage is to extract the data lying within a set of 3D
78
* boundaries (e.g., objects supported by a plane).
79
*
80
* Example usage:
81
* \code{.cpp}
82
* double z_min = 0., z_max = 0.05; // we want the points above the plane, no farther than 5 cm from the surface
83
* pcl::PointCloud<pcl::PointXYZ>::Ptr hull_points (new pcl::PointCloud<pcl::PointXYZ> ());
84
* pcl::ConvexHull<pcl::PointXYZ> hull;
85
* // hull.setDimension (2); // not necessarily needed, but we need to check the dimensionality of the output
86
* hull.setInputCloud (cloud);
87
* hull.reconstruct (hull_points);
88
* if (hull.getDimension () == 2)
89
* {
90
* pcl::ExtractPolygonalPrismData<pcl::PointXYZ> prism;
91
* prism.setInputCloud (point_cloud);
92
* prism.setInputPlanarHull (hull_points);
93
* prism.setHeightLimits (z_min, z_max);
94
* prism.segment (cloud_indices);
95
* }
96
* else
97
* PCL_ERROR ("The input cloud does not represent a planar surface.\n");
98
* \endcode
99
* \author Radu Bogdan Rusu
100
* \ingroup segmentation
101
*/
102
template
<
typename
Po
int
T>
103
class
ExtractPolygonalPrismData
:
public
PCLBase
<PointT>
104
{
105
using
PCLBase
<PointT>
::input_
;
106
using
PCLBase
<PointT>
::indices_
;
107
using
PCLBase
<PointT>
::initCompute
;
108
using
PCLBase
<PointT>
::deinitCompute
;
109
110
public
:
111
using
PointCloud
=
pcl::PointCloud<PointT>
;
112
using
PointCloudPtr
=
typename
PointCloud::Ptr
;
113
using
PointCloudConstPtr
=
typename
PointCloud::ConstPtr
;
114
115
using
PointIndicesPtr
=
PointIndices::Ptr
;
116
using
PointIndicesConstPtr
=
PointIndices::ConstPtr
;
117
118
/** \brief Empty constructor. */
119
ExtractPolygonalPrismData
() =
default
;
120
121
/** \brief Provide a pointer to the input planar hull dataset.
122
* \note Please see the example in the class description for how to obtain this.
123
* \param[in] hull the input planar hull dataset
124
*/
125
inline
void
126
setInputPlanarHull
(
const
PointCloudConstPtr
&hull) {
planar_hull_
= hull; }
127
128
/** \brief Provide a vector of the concave polygons indices, as recieved from ConcaveHull::polygons.
129
* \note This is only needed when using ConcaveHull that has more than one polygon.
130
* \param[in] polygons - see ConcaveHull::polygons
131
*/
132
inline
void
133
setPolygons
(
const
std::vector<pcl::Vertices>& polygons)
134
{
135
polygons_
= polygons;
136
}
137
138
/** \brief Get a pointer the input planar hull dataset. */
139
inline
PointCloudConstPtr
140
getInputPlanarHull
()
const
{
return
(
planar_hull_
); }
141
142
/** \brief Set the height limits. All points having distances to the
143
* model outside this interval will be discarded.
144
*
145
* \param[in] height_min the minimum allowed distance to the plane model value
146
* \param[in] height_max the maximum allowed distance to the plane model value
147
*/
148
inline
void
149
setHeightLimits
(
double
height_min,
double
height_max)
150
{
151
height_limit_min_
= height_min;
152
height_limit_max_
= height_max;
153
}
154
155
/** \brief Get the height limits (min/max) as set by the user. The
156
* default values are 0, std::numeric_limits<float>::max().
157
* \param[out] height_min the resultant min height limit
158
* \param[out] height_max the resultant max height limit
159
*/
160
inline
void
161
getHeightLimits
(
double
&height_min,
double
&height_max)
const
162
{
163
height_min =
height_limit_min_
;
164
height_max =
height_limit_max_
;
165
}
166
167
/** \brief Set the viewpoint.
168
* \param[in] vpx the X coordinate of the viewpoint
169
* \param[in] vpy the Y coordinate of the viewpoint
170
* \param[in] vpz the Z coordinate of the viewpoint
171
*/
172
inline
void
173
setViewPoint
(
float
vpx,
float
vpy,
float
vpz)
174
{
175
vpx_
= vpx;
176
vpy_
= vpy;
177
vpz_
= vpz;
178
}
179
180
/** \brief Get the viewpoint. */
181
inline
void
182
getViewPoint
(
float
&vpx,
float
&vpy,
float
&vpz)
const
183
{
184
vpx =
vpx_
;
185
vpy =
vpy_
;
186
vpz =
vpz_
;
187
}
188
189
/** \brief Cluster extraction in a PointCloud given by <setInputCloud (), setIndices ()>
190
* \param[out] output the resultant point indices that support the model found (inliers)
191
*/
192
void
193
segment
(
PointIndices
&output);
194
195
protected
:
196
/** \brief A pointer to the input planar hull dataset. */
197
PointCloudConstPtr
planar_hull_
{
nullptr
};
198
199
/** \brief polygons indices vectors, as recieved from ConcaveHull */
200
std::vector<pcl::Vertices>
polygons_
;
201
202
/** \brief The minimum number of points needed on the convex hull. */
203
int
min_pts_hull_
{3};
204
205
/** \brief The minimum allowed height (distance to the model) a point
206
* will be considered from.
207
*/
208
double
height_limit_min_
{0.0};
209
210
/** \brief The maximum allowed height (distance to the model) a point
211
* will be considered from.
212
*/
213
double
height_limit_max_
{std::numeric_limits<float>::max()};
214
215
/** \brief Values describing the data acquisition viewpoint. Default: 0,0,0. */
216
float
vpx_
{0.0f},
vpy_
{0.0f},
vpz_
{0.0f};
217
218
/** \brief Class getName method. */
219
virtual
std::string
220
getClassName
()
const
{
return
(
"ExtractPolygonalPrismData"
); }
221
};
222
}
223
224
#ifdef PCL_NO_PRECOMPILE
225
#include <pcl/segmentation/impl/extract_polygonal_prism_data.hpp>
226
#endif
pcl::ExtractPolygonalPrismData::vpy_
float vpy_
Definition
extract_polygonal_prism_data.h:216
pcl::ExtractPolygonalPrismData::getInputPlanarHull
PointCloudConstPtr getInputPlanarHull() const
Get a pointer the input planar hull dataset.
Definition
extract_polygonal_prism_data.h:140
pcl::ExtractPolygonalPrismData::PointCloudConstPtr
typename PointCloud::ConstPtr PointCloudConstPtr
Definition
extract_polygonal_prism_data.h:113
pcl::ExtractPolygonalPrismData::setHeightLimits
void setHeightLimits(double height_min, double height_max)
Set the height limits.
Definition
extract_polygonal_prism_data.h:149
pcl::ExtractPolygonalPrismData::setInputPlanarHull
void setInputPlanarHull(const PointCloudConstPtr &hull)
Provide a pointer to the input planar hull dataset.
Definition
extract_polygonal_prism_data.h:126
pcl::ExtractPolygonalPrismData::PointIndicesConstPtr
PointIndices::ConstPtr PointIndicesConstPtr
Definition
extract_polygonal_prism_data.h:116
pcl::ExtractPolygonalPrismData::getHeightLimits
void getHeightLimits(double &height_min, double &height_max) const
Get the height limits (min/max) as set by the user.
Definition
extract_polygonal_prism_data.h:161
pcl::ExtractPolygonalPrismData::getViewPoint
void getViewPoint(float &vpx, float &vpy, float &vpz) const
Get the viewpoint.
Definition
extract_polygonal_prism_data.h:182
pcl::ExtractPolygonalPrismData::min_pts_hull_
int min_pts_hull_
The minimum number of points needed on the convex hull.
Definition
extract_polygonal_prism_data.h:203
pcl::ExtractPolygonalPrismData::PointCloudPtr
typename PointCloud::Ptr PointCloudPtr
Definition
extract_polygonal_prism_data.h:112
pcl::ExtractPolygonalPrismData::height_limit_min_
double height_limit_min_
The minimum allowed height (distance to the model) a point will be considered from.
Definition
extract_polygonal_prism_data.h:208
pcl::ExtractPolygonalPrismData::getClassName
virtual std::string getClassName() const
Class getName method.
Definition
extract_polygonal_prism_data.h:220
pcl::ExtractPolygonalPrismData::polygons_
std::vector< pcl::Vertices > polygons_
polygons indices vectors, as recieved from ConcaveHull
Definition
extract_polygonal_prism_data.h:200
pcl::ExtractPolygonalPrismData::PointIndicesPtr
PointIndices::Ptr PointIndicesPtr
Definition
extract_polygonal_prism_data.h:115
pcl::ExtractPolygonalPrismData::vpx_
float vpx_
Values describing the data acquisition viewpoint.
Definition
extract_polygonal_prism_data.h:216
pcl::ExtractPolygonalPrismData::setViewPoint
void setViewPoint(float vpx, float vpy, float vpz)
Set the viewpoint.
Definition
extract_polygonal_prism_data.h:173
pcl::ExtractPolygonalPrismData::ExtractPolygonalPrismData
ExtractPolygonalPrismData()=default
Empty constructor.
pcl::ExtractPolygonalPrismData::vpz_
float vpz_
Definition
extract_polygonal_prism_data.h:216
pcl::ExtractPolygonalPrismData::setPolygons
void setPolygons(const std::vector< pcl::Vertices > &polygons)
Provide a vector of the concave polygons indices, as recieved from ConcaveHull::polygons.
Definition
extract_polygonal_prism_data.h:133
pcl::ExtractPolygonalPrismData::height_limit_max_
double height_limit_max_
The maximum allowed height (distance to the model) a point will be considered from.
Definition
extract_polygonal_prism_data.h:213
pcl::ExtractPolygonalPrismData::PointCloud
pcl::PointCloud< PointT > PointCloud
Definition
extract_polygonal_prism_data.h:111
pcl::ExtractPolygonalPrismData::planar_hull_
PointCloudConstPtr planar_hull_
A pointer to the input planar hull dataset.
Definition
extract_polygonal_prism_data.h:197
pcl::ExtractPolygonalPrismData::segment
void segment(PointIndices &output)
Cluster extraction in a PointCloud given by <setInputCloud (), setIndices ()>.
Definition
extract_polygonal_prism_data.hpp:149
pcl::PCLBase::input_
PointCloudConstPtr input_
The input point cloud dataset.
Definition
pcl_base.h:147
pcl::PCLBase::indices_
IndicesPtr indices_
A pointer to the vector of point indices to use.
Definition
pcl_base.h:150
pcl::PCLBase::initCompute
bool initCompute()
This method should get called before starting the actual computation.
Definition
pcl_base.hpp:138
pcl::PCLBase::PCLBase
PCLBase()
Empty constructor.
Definition
pcl_base.hpp:46
pcl::PCLBase::deinitCompute
bool deinitCompute()
This method should get called after finishing the actual computation.
Definition
pcl_base.hpp:175
pcl::PointCloud
PointCloud represents the base class in PCL for storing collections of 3D points.
Definition
point_cloud.h:174
pcl::PointCloud::Ptr
shared_ptr< PointCloud< PointT > > Ptr
Definition
point_cloud.h:414
pcl::PointCloud::ConstPtr
shared_ptr< const PointCloud< PointT > > ConstPtr
Definition
point_cloud.h:415
pcl::isPointIn2DPolygon
bool isPointIn2DPolygon(const PointT &point, const pcl::PointCloud< PointT > &polygon)
General purpose method for checking if a 3D point is inside or outside a given 2D polygon.
Definition
extract_polygonal_prism_data.hpp:48
pcl::isXYPointIn2DXYPolygon
bool isXYPointIn2DXYPolygon(const PointT &point, const pcl::PointCloud< PointT > &polygon)
Check if a 2d point (X and Y coordinates considered only!) is inside or outside a given polygon.
Definition
extract_polygonal_prism_data.hpp:108
pcl
Definition
convolution.h:46
pcl::PointIndices
Definition
PointIndices.h:12
pcl::PointIndices::Ptr
shared_ptr< ::pcl::PointIndices > Ptr
Definition
PointIndices.h:13
pcl::PointIndices::ConstPtr
shared_ptr< const ::pcl::PointIndices > ConstPtr
Definition
PointIndices.h:14