Point Cloud Library (PCL)  1.11.0
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 <pcl/pcl_base.h>
41 #include <pcl/sample_consensus/sac_model_plane.h>
42 
43 namespace pcl
44 {
45  /** \brief General purpose method for checking if a 3D point is inside or
46  * outside a given 2D polygon.
47  * \note this method accepts any general 3D point that is projected onto the
48  * 2D polygon, but performs an internal XY projection of both the polygon and the point.
49  * \param point a 3D point projected onto the same plane as the polygon
50  * \param polygon a polygon
51  * \ingroup segmentation
52  */
53  template <typename PointT> bool
54  isPointIn2DPolygon (const PointT &point, const pcl::PointCloud<PointT> &polygon);
55 
56  /** \brief Check if a 2d point (X and Y coordinates considered only!) is
57  * inside or outside a given polygon. This method assumes that both the point
58  * and the polygon are projected onto the XY plane.
59  *
60  * \note (This is highly optimized code taken from http://www.visibone.com/inpoly/)
61  * Copyright (c) 1995-1996 Galacticomm, Inc. Freeware source code.
62  * \param point a 2D point projected onto the same plane as the polygon
63  * \param polygon a polygon
64  * \ingroup segmentation
65  */
66  template <typename PointT> bool
67  isXYPointIn2DXYPolygon (const PointT &point, const pcl::PointCloud<PointT> &polygon);
68 
69  ////////////////////////////////////////////////////////////////////////////////////////////
70  /** \brief @b ExtractPolygonalPrismData uses a set of point indices that
71  * represent a planar model, and together with a given height, generates a 3D
72  * polygonal prism. The polygonal prism is then used to segment all points
73  * lying inside it.
74  *
75  * An example of its usage is to extract the data lying within a set of 3D
76  * boundaries (e.g., objects supported by a plane).
77  *
78  * Example usage:
79  * \code{.cpp}
80  * double z_min = 0., z_max = 0.05; // we want the points above the plane, no farther than 5 cm from the surface
81  * pcl::PointCloud<pcl::PointXYZ>::Ptr hull_points (new pcl::PointCloud<pcl::PointXYZ> ());
82  * pcl::ConvexHull<pcl::PointXYZ> hull;
83  * // hull.setDimension (2); // not necessarily needed, but we need to check the dimensionality of the output
84  * hull.setInputCloud (cloud);
85  * hull.reconstruct (hull_points);
86  * if (hull.getDimension () == 2)
87  * {
88  * pcl::ExtractPolygonalPrismData<pcl::PointXYZ> prism;
89  * prism.setInputCloud (point_cloud);
90  * prism.setInputPlanarHull (hull_points);
91  * prism.setHeightLimits (z_min, z_max);
92  * prism.segment (cloud_indices);
93  * }
94  * else
95  * PCL_ERROR ("The input cloud does not represent a planar surface.\n");
96  * \endcode
97  * \author Radu Bogdan Rusu
98  * \ingroup segmentation
99  */
100  template <typename PointT>
101  class ExtractPolygonalPrismData : public PCLBase<PointT>
102  {
107 
108  public:
110  using PointCloudPtr = typename PointCloud::Ptr;
112 
115 
116  /** \brief Empty constructor. */
118  height_limit_min_ (0), height_limit_max_ (FLT_MAX),
119  vpx_ (0), vpy_ (0), vpz_ (0)
120  {};
121 
122  /** \brief Provide a pointer to the input planar hull dataset.
123  * \note Please see the example in the class description for how to obtain this.
124  * \param[in] hull the input planar hull dataset
125  */
126  inline void
128 
129  /** \brief Get a pointer the input planar hull dataset. */
130  inline PointCloudConstPtr
131  getInputPlanarHull () const { return (planar_hull_); }
132 
133  /** \brief Set the height limits. All points having distances to the
134  * model outside this interval will be discarded.
135  *
136  * \param[in] height_min the minimum allowed distance to the plane model value
137  * \param[in] height_max the maximum allowed distance to the plane model value
138  */
139  inline void
140  setHeightLimits (double height_min, double height_max)
141  {
142  height_limit_min_ = height_min;
143  height_limit_max_ = height_max;
144  }
145 
146  /** \brief Get the height limits (min/max) as set by the user. The
147  * default values are -FLT_MAX, FLT_MAX.
148  * \param[out] height_min the resultant min height limit
149  * \param[out] height_max the resultant max height limit
150  */
151  inline void
152  getHeightLimits (double &height_min, double &height_max) const
153  {
154  height_min = height_limit_min_;
155  height_max = height_limit_max_;
156  }
157 
158  /** \brief Set the viewpoint.
159  * \param[in] vpx the X coordinate of the viewpoint
160  * \param[in] vpy the Y coordinate of the viewpoint
161  * \param[in] vpz the Z coordinate of the viewpoint
162  */
163  inline void
164  setViewPoint (float vpx, float vpy, float vpz)
165  {
166  vpx_ = vpx;
167  vpy_ = vpy;
168  vpz_ = vpz;
169  }
170 
171  /** \brief Get the viewpoint. */
172  inline void
173  getViewPoint (float &vpx, float &vpy, float &vpz) const
174  {
175  vpx = vpx_;
176  vpy = vpy_;
177  vpz = vpz_;
178  }
179 
180  /** \brief Cluster extraction in a PointCloud given by <setInputCloud (), setIndices ()>
181  * \param[out] output the resultant point indices that support the model found (inliers)
182  */
183  void
184  segment (PointIndices &output);
185 
186  protected:
187  /** \brief A pointer to the input planar hull dataset. */
189 
190  /** \brief The minimum number of points needed on the convex hull. */
192 
193  /** \brief The minimum allowed height (distance to the model) a point
194  * will be considered from.
195  */
197 
198  /** \brief The maximum allowed height (distance to the model) a point
199  * will be considered from.
200  */
202 
203  /** \brief Values describing the data acquisition viewpoint. Default: 0,0,0. */
204  float vpx_, vpy_, vpz_;
205 
206  /** \brief Class getName method. */
207  virtual std::string
208  getClassName () const { return ("ExtractPolygonalPrismData"); }
209  };
210 }
211 
212 #ifdef PCL_NO_PRECOMPILE
213 #include <pcl/segmentation/impl/extract_polygonal_prism_data.hpp>
214 #endif
pcl::ExtractPolygonalPrismData::segment
void segment(PointIndices &output)
Cluster extraction in a PointCloud given by <setInputCloud (), setIndices ()>
Definition: extract_polygonal_prism_data.hpp:148
pcl
Definition: convolution.h:46
pcl::PCLBase::PointCloudConstPtr
typename PointCloud::ConstPtr PointCloudConstPtr
Definition: pcl_base.h:74
pcl::PCLBase::PointCloudPtr
typename PointCloud::Ptr PointCloudPtr
Definition: pcl_base.h:73
pcl::ExtractPolygonalPrismData::getViewPoint
void getViewPoint(float &vpx, float &vpy, float &vpz) const
Get the viewpoint.
Definition: extract_polygonal_prism_data.h:173
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:107
pcl::PCLBase
PCL base class.
Definition: pcl_base.h:70
pcl::PCLBase::PointIndicesConstPtr
PointIndices::ConstPtr PointIndicesConstPtr
Definition: pcl_base.h:77
pcl::PointCloud
PointCloud represents the base class in PCL for storing collections of 3D points.
Definition: projection_matrix.h:52
pcl::PointXYZRGB
A point structure representing Euclidean xyz coordinates, and the RGB color.
Definition: point_types.hpp:629
pcl::ExtractPolygonalPrismData::getInputPlanarHull
PointCloudConstPtr getInputPlanarHull() const
Get a pointer the input planar hull dataset.
Definition: extract_polygonal_prism_data.h:131
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:191
pcl::ExtractPolygonalPrismData::vpx_
float vpx_
Values describing the data acquisition viewpoint.
Definition: extract_polygonal_prism_data.h:204
pcl::ExtractPolygonalPrismData::setInputPlanarHull
void setInputPlanarHull(const PointCloudConstPtr &hull)
Provide a pointer to the input planar hull dataset.
Definition: extract_polygonal_prism_data.h:127
pcl::PointIndices::ConstPtr
shared_ptr< const ::pcl::PointIndices > ConstPtr
Definition: PointIndices.h:16
pcl::ExtractPolygonalPrismData::vpy_
float vpy_
Definition: extract_polygonal_prism_data.h:204
pcl::ExtractPolygonalPrismData::ExtractPolygonalPrismData
ExtractPolygonalPrismData()
Empty constructor.
Definition: extract_polygonal_prism_data.h:117
pcl::ExtractPolygonalPrismData
ExtractPolygonalPrismData uses a set of point indices that represent a planar model,...
Definition: extract_polygonal_prism_data.h:102
pcl::ExtractPolygonalPrismData::setViewPoint
void setViewPoint(float vpx, float vpy, float vpz)
Set the viewpoint.
Definition: extract_polygonal_prism_data.h:164
pcl::PointIndices
Definition: PointIndices.h:14
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:152
pcl::PointIndices::Ptr
shared_ptr< ::pcl::PointIndices > Ptr
Definition: PointIndices.h:15
pcl::PointCloud::Ptr
shared_ptr< PointCloud< PointT > > Ptr
Definition: point_cloud.h:428
pcl::ExtractPolygonalPrismData::vpz_
float vpz_
Definition: extract_polygonal_prism_data.h:204
pcl::PointCloud::ConstPtr
shared_ptr< const PointCloud< PointT > > ConstPtr
Definition: point_cloud.h:429
pcl::PCLBase::PointIndicesPtr
PointIndices::Ptr PointIndicesPtr
Definition: pcl_base.h:76
pcl::ExtractPolygonalPrismData::setHeightLimits
void setHeightLimits(double height_min, double height_max)
Set the height limits.
Definition: extract_polygonal_prism_data.h:140
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:201
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:196
pcl::ExtractPolygonalPrismData::getClassName
virtual std::string getClassName() const
Class getName method.
Definition: extract_polygonal_prism_data.h:208
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:47
pcl::ExtractPolygonalPrismData::planar_hull_
PointCloudConstPtr planar_hull_
A pointer to the input planar hull dataset.
Definition: extract_polygonal_prism_data.h:188