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