extract_polygonal_prism_data.h
/*
* Software License Agreement (BSD License)
*
* Copyright (c) 2010, Willow Garage, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of the copyright holder(s) nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
* $Id$
*
*/
#pragma once
#include <pcl/pcl_base.h>
#include <pcl/sample_consensus/sac_model_plane.h>
namespace pcl
{
/** \brief General purpose method for checking if a 3D point is inside or
* outside a given 2D polygon.
* \note this method accepts any general 3D point that is projected onto the
* 2D polygon, but performs an internal XY projection of both the polygon and the point.
* \param point a 3D point projected onto the same plane as the polygon
* \param polygon a polygon
* \ingroup segmentation
*/
template <typename PointT> bool
isPointIn2DPolygon (const PointT &point, const pcl::PointCloud<PointT> &polygon);
/** \brief Check if a 2d point (X and Y coordinates considered only!) is
* inside or outside a given polygon. This method assumes that both the point
* and the polygon are projected onto the XY plane.
*
* \note (This is highly optimized code taken from http://www.visibone.com/inpoly/)
* Copyright (c) 1995-1996 Galacticomm, Inc. Freeware source code.
* \param point a 2D point projected onto the same plane as the polygon
* \param polygon a polygon
* \ingroup segmentation
*/
template <typename PointT> bool
isXYPointIn2DXYPolygon (const PointT &point, const pcl::PointCloud<PointT> &polygon);
////////////////////////////////////////////////////////////////////////////////////////////
/** \brief @b ExtractPolygonalPrismData uses a set of point indices that
* represent a planar model, and together with a given height, generates a 3D
* polygonal prism. The polygonal prism is then used to segment all points
* lying inside it.
*
* An example of its usage is to extract the data lying within a set of 3D
* boundaries (e.g., objects supported by a plane).
*
* Example usage:
* \code{.cpp}
* double z_min = 0., z_max = 0.05; // we want the points above the plane, no farther than 5 cm from the surface
* pcl::PointCloud<pcl::PointXYZ>::Ptr hull_points (new pcl::PointCloud<pcl::PointXYZ> ());
* pcl::ConvexHull<pcl::PointXYZ> hull;
* // hull.setDimension (2); // not necessarily needed, but we need to check the dimensionality of the output
* hull.setInputCloud (cloud);
* hull.reconstruct (hull_points);
* if (hull.getDimension () == 2)
* {
* pcl::ExtractPolygonalPrismData<pcl::PointXYZ> prism;
* prism.setInputCloud (point_cloud);
* prism.setInputPlanarHull (hull_points);
* prism.setHeightLimits (z_min, z_max);
* prism.segment (cloud_indices);
* }
* else
* PCL_ERROR ("The input cloud does not represent a planar surface.\n");
* \endcode
* \author Radu Bogdan Rusu
* \ingroup segmentation
*/
template <typename PointT>
class ExtractPolygonalPrismData : public PCLBase<PointT>
{
using PCLBase<PointT>::input_;
using PCLBase<PointT>::indices_;
using PCLBase<PointT>::initCompute;
using PCLBase<PointT>::deinitCompute;
public:
using PointCloud = pcl::PointCloud<PointT>;
using PointCloudPtr = typename PointCloud::Ptr;
using PointCloudConstPtr = typename PointCloud::ConstPtr;
using PointIndicesPtr = PointIndices::Ptr;
using PointIndicesConstPtr = PointIndices::ConstPtr;
/** \brief Empty constructor. */
ExtractPolygonalPrismData () : planar_hull_ (), min_pts_hull_ (3),
height_limit_min_ (0), height_limit_max_ (FLT_MAX),
vpx_ (0), vpy_ (0), vpz_ (0)
{};
/** \brief Provide a pointer to the input planar hull dataset.
* \note Please see the example in the class description for how to obtain this.
* \param[in] hull the input planar hull dataset
*/
inline void
setInputPlanarHull (const PointCloudConstPtr &hull) { planar_hull_ = hull; }
/** \brief Get a pointer the input planar hull dataset. */
inline PointCloudConstPtr
getInputPlanarHull () const { return (planar_hull_); }
/** \brief Set the height limits. All points having distances to the
* model outside this interval will be discarded.
*
* \param[in] height_min the minimum allowed distance to the plane model value
* \param[in] height_max the maximum allowed distance to the plane model value
*/
inline void
setHeightLimits (double height_min, double height_max)
{
height_limit_min_ = height_min;
height_limit_max_ = height_max;
}
/** \brief Get the height limits (min/max) as set by the user. The
* default values are -FLT_MAX, FLT_MAX.
* \param[out] height_min the resultant min height limit
* \param[out] height_max the resultant max height limit
*/
inline void
getHeightLimits (double &height_min, double &height_max) const
{
height_min = height_limit_min_;
height_max = height_limit_max_;
}
/** \brief Set the viewpoint.
* \param[in] vpx the X coordinate of the viewpoint
* \param[in] vpy the Y coordinate of the viewpoint
* \param[in] vpz the Z coordinate of the viewpoint
*/
inline void
setViewPoint (float vpx, float vpy, float vpz)
{
vpx_ = vpx;
vpy_ = vpy;
vpz_ = vpz;
}
/** \brief Get the viewpoint. */
inline void
getViewPoint (float &vpx, float &vpy, float &vpz) const
{
vpx = vpx_;
vpy = vpy_;
vpz = vpz_;
}
/** \brief Cluster extraction in a PointCloud given by <setInputCloud (), setIndices ()>
* \param[out] output the resultant point indices that support the model found (inliers)
*/
void
segment (PointIndices &output);
protected:
/** \brief A pointer to the input planar hull dataset. */
PointCloudConstPtr planar_hull_;
/** \brief The minimum number of points needed on the convex hull. */
int min_pts_hull_;
/** \brief The minimum allowed height (distance to the model) a point
* will be considered from.
*/
double height_limit_min_;
/** \brief The maximum allowed height (distance to the model) a point
* will be considered from.
*/
double height_limit_max_;
/** \brief Values describing the data acquisition viewpoint. Default: 0,0,0. */
float vpx_, vpy_, vpz_;
/** \brief Class getName method. */
virtual std::string
getClassName () const { return ("ExtractPolygonalPrismData"); }
};
}
#ifdef PCL_NO_PRECOMPILE
#include <pcl/segmentation/impl/extract_polygonal_prism_data.hpp>
#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
This file defines compatibility wrappers for low level I/O functions.
Definition: convolution.h:45
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: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: projection_matrix.h:52
pcl::PointXYZRGB
A point structure representing Euclidean xyz coordinates, and the RGB color.
Definition: point_types.hpp:623
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:23
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:101
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:12
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:22
pcl::PointCloud::Ptr
shared_ptr< PointCloud< PointT > > Ptr
Definition: point_cloud.h:415
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:416
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