convex_hull.h
/*
* Software License Agreement (BSD License)
*
* Point Cloud Library (PCL) - www.pointclouds.org
* Copyright (c) 2010-2012, 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 Willow Garage, Inc. 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/memory.h>
#include <pcl/pcl_macros.h>
#include <pcl/pcl_config.h>
#ifdef HAVE_QHULL
// PCL includes
#include <pcl/surface/reconstruction.h>
#include <pcl/PolygonMesh.h>
namespace pcl
{
/** \brief Sort 2D points in a vector structure
* \param p1 the first point
* \param p2 the second point
* \ingroup surface
*/
inline bool
comparePoints2D (const std::pair<int, Eigen::Vector4f> & p1, const std::pair<int, Eigen::Vector4f> & p2)
{
double angle1 = std::atan2 (p1.second[1], p1.second[0]) + M_PI;
double angle2 = std::atan2 (p2.second[1], p2.second[0]) + M_PI;
return (angle1 > angle2);
}
////////////////////////////////////////////////////////////////////////////////////////////
/** \brief @b ConvexHull using libqhull library.
* \author Aitor Aldoma, Alex Trevor
* \ingroup surface
*/
template<typename PointInT>
class ConvexHull : public MeshConstruction<PointInT>
{
protected:
using PCLBase<PointInT>::input_;
using PCLBase<PointInT>::indices_;
using PCLBase<PointInT>::initCompute;
using PCLBase<PointInT>::deinitCompute;
public:
using Ptr = shared_ptr<ConvexHull<PointInT> >;
using ConstPtr = shared_ptr<const ConvexHull<PointInT> >;
using MeshConstruction<PointInT>::reconstruct;
using PointCloud = pcl::PointCloud<PointInT>;
using PointCloudPtr = typename PointCloud::Ptr;
using PointCloudConstPtr = typename PointCloud::ConstPtr;
/** \brief Empty constructor. */
ConvexHull () : compute_area_ (false), total_area_ (0), total_volume_ (0), dimension_ (0),
projection_angle_thresh_ (std::cos (0.174532925) ), qhull_flags ("qhull "),
x_axis_ (1.0, 0.0, 0.0), y_axis_ (0.0, 1.0, 0.0), z_axis_ (0.0, 0.0, 1.0)
{
}
/** \brief Empty destructor */
~ConvexHull () {}
/** \brief Compute a convex hull for all points given.
*
* \note In 2D case (i.e. if the input points belong to one plane)
* the \a polygons vector will have a single item, whereas in 3D
* case it will contain one item for each hull facet.
*
* \param[out] points the resultant points lying on the convex hull.
* \param[out] polygons the resultant convex hull polygons, as a set of
* vertices. The Vertices structure contains an array of point indices.
*/
void
reconstruct (PointCloud &points,
std::vector<pcl::Vertices> &polygons);
/** \brief Compute a convex hull for all points given.
* \param[out] points the resultant points lying on the convex hull.
*/
void
reconstruct (PointCloud &points);
/** \brief If set to true, the qhull library is called to compute the total area and volume of the convex hull.
* NOTE: When this option is activated, the qhull library produces output to the console.
* \param[in] value whether to compute the area and the volume, default is false
*/
void
setComputeAreaVolume (bool value)
{
compute_area_ = value;
if (compute_area_)
qhull_flags = std::string ("qhull FA");
else
qhull_flags = std::string ("qhull ");
}
/** \brief Returns the total area of the convex hull. */
double
getTotalArea () const
{
return (total_area_);
}
/** \brief Returns the total volume of the convex hull. Only valid for 3-dimensional sets.
* For 2D-sets volume is zero.
*/
double
getTotalVolume () const
{
return (total_volume_);
}
/** \brief Sets the dimension on the input data, 2D or 3D.
* \param[in] dimension The dimension of the input data. If not set, this will be determined automatically.
*/
void
setDimension (int dimension)
{
if ((dimension == 2) || (dimension == 3))
dimension_ = dimension;
else
PCL_ERROR ("[pcl::%s::setDimension] Invalid input dimension specified!\n", getClassName ().c_str ());
}
/** \brief Returns the dimensionality (2 or 3) of the calculated hull. */
inline int
getDimension () const
{
return (dimension_);
}
/** \brief Retrieve the indices of the input point cloud that for the convex hull.
*
* \note Should only be called after reconstruction was performed.
* \param[out] hull_point_indices The indices of the points forming the point cloud
*/
void
getHullPointIndices (pcl::PointIndices &hull_point_indices) const;
protected:
/** \brief The actual reconstruction method.
*
* \param[out] points the resultant points lying on the convex hull
* \param[out] polygons the resultant convex hull polygons, as a set of
* vertices. The Vertices structure contains an array of point indices.
* \param[in] fill_polygon_data true if polygons should be filled, false otherwise
*/
void
performReconstruction (PointCloud &points,
std::vector<pcl::Vertices> &polygons,
bool fill_polygon_data = false);
/** \brief The reconstruction method for 2D data. Does not require dimension to be set.
*
* \param[out] points the resultant points lying on the convex hull
* \param[out] polygons the resultant convex hull polygons, as a set of
* vertices. The Vertices structure contains an array of point indices.
* \param[in] fill_polygon_data true if polygons should be filled, false otherwise
*/
void
performReconstruction2D (PointCloud &points,
std::vector<pcl::Vertices> &polygons,
bool fill_polygon_data = false);
/** \brief The reconstruction method for 3D data. Does not require dimension to be set.
*
* \param[out] points the resultant points lying on the convex hull
* \param[out] polygons the resultant convex hull polygons, as a set of
* vertices. The Vertices structure contains an array of point indices.
* \param[in] fill_polygon_data true if polygons should be filled, false otherwise
*/
void
performReconstruction3D (PointCloud &points,
std::vector<pcl::Vertices> &polygons,
bool fill_polygon_data = false);
/** \brief A reconstruction method that returns a polygonmesh.
*
* \param[out] output a PolygonMesh representing the convex hull of the input data.
*/
void
performReconstruction (PolygonMesh &output) override;
/** \brief A reconstruction method that returns the polygon of the convex hull.
*
* \param[out] polygons the polygon(s) representing the convex hull of the input data.
*/
void
performReconstruction (std::vector<pcl::Vertices> &polygons) override;
/** \brief Automatically determines the dimension of input data - 2D or 3D. */
void
calculateInputDimension ();
/** \brief Class get name method. */
std::string
getClassName () const override
{
return ("ConvexHull");
}
/* \brief True if we should compute the area and volume of the convex hull. */
bool compute_area_;
/* \brief The area of the convex hull. */
double total_area_;
/* \brief The volume of the convex hull (only for 3D hulls, zero for 2D). */
double total_volume_;
/** \brief The dimensionality of the concave hull (2D or 3D). */
int dimension_;
/** \brief How close can a 2D plane's normal be to an axis to make projection problematic. */
double projection_angle_thresh_;
/** \brief Option flag string to be used calling qhull. */
std::string qhull_flags;
/* \brief x-axis - for checking valid projections. */
const Eigen::Vector3d x_axis_;
/* \brief y-axis - for checking valid projections. */
const Eigen::Vector3d y_axis_;
/* \brief z-axis - for checking valid projections. */
const Eigen::Vector3d z_axis_;
/* \brief vector containing the point cloud indices of the convex hull points. */
pcl::PointIndices hull_indices_;
public:
PCL_MAKE_ALIGNED_OPERATOR_NEW
};
}
#ifdef PCL_NO_PRECOMPILE
#include <pcl/surface/impl/convex_hull.hpp>
#endif
#endif
pcl::ConvexHull
ConvexHull using libqhull library.
Definition: convex_hull.h:73
pcl::ConvexHull::total_volume_
double total_volume_
Definition: convex_hull.h:246
pcl::ConvexHull::getTotalArea
double getTotalArea() const
Returns the total area of the convex hull.
Definition: convex_hull.h:136
pcl::ConvexHull::ConstPtr
shared_ptr< const ConvexHull< PointInT > > ConstPtr
Definition: convex_hull.h:82
pcl::ConvexHull::getClassName
std::string getClassName() const override
Class get name method.
Definition: convex_hull.h:234
pcl::ConvexHull::setComputeAreaVolume
void setComputeAreaVolume(bool value)
If set to true, the qhull library is called to compute the total area and volume of the convex hull.
Definition: convex_hull.h:125
pcl::ConvexHull::PointCloudConstPtr
typename PointCloud::ConstPtr PointCloudConstPtr
Definition: convex_hull.h:88
pcl::ConvexHull::calculateInputDimension
void calculateInputDimension()
Automatically determines the dimension of input data - 2D or 3D.
Definition: convex_hull.hpp:57
pcl::ConvexHull::performReconstruction2D
void performReconstruction2D(PointCloud &points, std::vector< pcl::Vertices > &polygons, bool fill_polygon_data=false)
The reconstruction method for 2D data.
Definition: convex_hull.hpp:76
pcl::ConvexHull::setDimension
void setDimension(int dimension)
Sets the dimension on the input data, 2D or 3D.
Definition: convex_hull.h:154
pcl::ConvexHull::z_axis_
const Eigen::Vector3d z_axis_
Definition: convex_hull.h:264
pcl::ConvexHull::getTotalVolume
double getTotalVolume() const
Returns the total volume of the convex hull.
Definition: convex_hull.h:145
pcl::ConvexHull::qhull_flags
std::string qhull_flags
Option flag string to be used calling qhull.
Definition: convex_hull.h:255
pcl::ConvexHull::~ConvexHull
~ConvexHull()
Empty destructor.
Definition: convex_hull.h:98
pcl::ConvexHull::getHullPointIndices
void getHullPointIndices(pcl::PointIndices &hull_point_indices) const
Retrieve the indices of the input point cloud that for the convex hull.
Definition: convex_hull.hpp:503
pcl::ConvexHull::hull_indices_
pcl::PointIndices hull_indices_
Definition: convex_hull.h:267
pcl::ConvexHull::Ptr
shared_ptr< ConvexHull< PointInT > > Ptr
Definition: convex_hull.h:81
pcl::ConvexHull::performReconstruction
void performReconstruction(PointCloud &points, std::vector< pcl::Vertices > &polygons, bool fill_polygon_data=false)
The actual reconstruction method.
Definition: convex_hull.hpp:425
pcl::ConvexHull::getDimension
int getDimension() const
Returns the dimensionality (2 or 3) of the calculated hull.
Definition: convex_hull.h:164
pcl::ConvexHull::projection_angle_thresh_
double projection_angle_thresh_
How close can a 2D plane's normal be to an axis to make projection problematic.
Definition: convex_hull.h:252
pcl::ConvexHull::total_area_
double total_area_
Definition: convex_hull.h:243
pcl::ConvexHull::PointCloudPtr
typename PointCloud::Ptr PointCloudPtr
Definition: convex_hull.h:87
pcl::ConvexHull::compute_area_
bool compute_area_
Definition: convex_hull.h:240
pcl::ConvexHull::ConvexHull
ConvexHull()
Empty constructor.
Definition: convex_hull.h:91
pcl::ConvexHull::reconstruct
void reconstruct(PointCloud &points, std::vector< pcl::Vertices > &polygons)
Compute a convex hull for all points given.
Definition: convex_hull.hpp:483
pcl::ConvexHull::y_axis_
const Eigen::Vector3d y_axis_
Definition: convex_hull.h:261
pcl::ConvexHull::x_axis_
const Eigen::Vector3d x_axis_
Definition: convex_hull.h:258
pcl::ConvexHull::performReconstruction3D
void performReconstruction3D(PointCloud &points, std::vector< pcl::Vertices > &polygons, bool fill_polygon_data=false)
The reconstruction method for 3D data.
Definition: convex_hull.hpp:292
pcl::ConvexHull::dimension_
int dimension_
The dimensionality of the concave hull (2D or 3D).
Definition: convex_hull.h:249
pcl::MeshConstruction
MeshConstruction represents a base surface reconstruction class.
Definition: reconstruction.h:187
pcl::PCLBase
PCL base class.
Definition: pcl_base.h:70
pcl::PointCloud< PointInT >
pcl::PointCloud< PointInT >::Ptr
shared_ptr< PointCloud< PointInT > > Ptr
Definition: point_cloud.h:413
pcl::PointCloud< PointInT >::ConstPtr
shared_ptr< const PointCloud< PointInT > > ConstPtr
Definition: point_cloud.h:414
PCL_MAKE_ALIGNED_OPERATOR_NEW
#define PCL_MAKE_ALIGNED_OPERATOR_NEW
Macro to signal a class requires a custom allocator.
Definition: memory.h:63
pcl::comparePoints2D
bool comparePoints2D(const std::pair< int, Eigen::Vector4f > &p1, const std::pair< int, Eigen::Vector4f > &p2)
Sort 2D points in a vector structure.
Definition: convex_hull.h:59
memory.h
Defines functions, macros and traits for allocating and using memory.
pcl
Definition: convolution.h:46
pcl_macros.h
Defines all the PCL and non-PCL macros used.
M_PI
#define M_PI
Definition: pcl_macros.h:201
pcl::PointIndices
Definition: PointIndices.h:12
pcl::PolygonMesh
Definition: PolygonMesh.h:15