Point Cloud Library (PCL)  1.11.1-dev
concave_hull.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2009-2012, Willow Garage, Inc.
6  *
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * * Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  * * Redistributions in binary form must reproduce the above
16  * copyright notice, this list of conditions and the following
17  * disclaimer in the documentation and/or other materials provided
18  * with the distribution.
19  * * Neither the name of Willow Garage, Inc. nor the names of its
20  * contributors may be used to endorse or promote products derived
21  * from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  * POSSIBILITY OF SUCH DAMAGE.
35  *
36  * $Id$
37  *
38  */
39 
40 #pragma once
41 
42 #include <pcl/pcl_config.h>
43 #ifdef HAVE_QHULL
44 
45 #include <pcl/surface/reconstruction.h> // for MeshConstruction
46 
47 namespace pcl
48 {
49  ////////////////////////////////////////////////////////////////////////////////////////////
50  /** \brief @b ConcaveHull (alpha shapes) using libqhull library.
51  * \author Aitor Aldoma
52  * \ingroup surface
53  */
54  template<typename PointInT>
55  class ConcaveHull : public MeshConstruction<PointInT>
56  {
57  protected:
58  using Ptr = shared_ptr<ConcaveHull<PointInT> >;
59  using ConstPtr = shared_ptr<const ConcaveHull<PointInT> >;
60 
65 
66  public:
68 
70  using PointCloudPtr = typename PointCloud::Ptr;
72 
73  /** \brief Empty constructor. */
75  {
76  };
77 
78  /** \brief Empty destructor */
80 
81  /** \brief Compute a concave hull for all points given
82  *
83  * \param points the resultant points lying on the concave hull
84  * \param polygons the resultant concave hull polygons, as a set of
85  * vertices. The Vertices structure contains an array of point indices.
86  */
87  void
88  reconstruct (PointCloud &points,
89  std::vector<pcl::Vertices> &polygons);
90 
91  /** \brief Compute a concave hull for all points given
92  * \param output the resultant concave hull vertices
93  */
94  void
95  reconstruct (PointCloud &output);
96 
97  /** \brief Set the alpha value, which limits the size of the resultant
98  * hull segments (the smaller the more detailed the hull).
99  *
100  * \param alpha positive, non-zero value, defining the maximum length
101  * from a vertex to the facet center (center of the voronoi cell).
102  */
103  inline void
104  setAlpha (double alpha)
105  {
106  alpha_ = alpha;
107  }
108 
109  /** \brief Returns the alpha parameter, see setAlpha(). */
110  inline double
112  {
113  return (alpha_);
114  }
115 
116  /** \brief If set, the voronoi cells center will be saved in _voronoi_centers_
117  * \param voronoi_centers
118  */
119  inline void
121  {
122  voronoi_centers_ = voronoi_centers;
123  }
124 
125  /** \brief If keep_information_is set to true the convex hull
126  * points keep other information like rgb, normals, ...
127  * \param value where to keep the information or not, default is false
128  */
129  void
130  setKeepInformation (bool value)
131  {
132  keep_information_ = value;
133  }
134 
135  /** \brief Returns the dimensionality (2 or 3) of the calculated hull. */
136  inline int
137  getDimension () const
138  {
139  return (dim_);
140  }
141 
142  /** \brief Sets the dimension on the input data, 2D or 3D.
143  * \param[in] dimension The dimension of the input data. If not set, this will be determined automatically.
144  */
145  void
146  setDimension (int dimension)
147  {
148  if ((dimension == 2) || (dimension == 3))
149  dim_ = dimension;
150  else
151  PCL_ERROR ("[pcl::%s::setDimension] Invalid input dimension specified!\n", getClassName ().c_str ());
152  }
153 
154  /** \brief Retrieve the indices of the input point cloud that for the convex hull.
155  *
156  * \note Should only be called after reconstruction was performed and if the ConcaveHull is
157  * set to preserve information via setKeepInformation ().
158  *
159  * \param[out] hull_point_indices The indices of the points forming the point cloud
160  */
161  void
162  getHullPointIndices (pcl::PointIndices &hull_point_indices) const;
163 
164  protected:
165  /** \brief Class get name method. */
166  std::string
167  getClassName () const override
168  {
169  return ("ConcaveHull");
170  }
171 
172  protected:
173  /** \brief The actual reconstruction method.
174  *
175  * \param points the resultant points lying on the concave hull
176  * \param polygons the resultant concave hull polygons, as a set of
177  * vertices. The Vertices structure contains an array of point indices.
178  */
179  void
181  std::vector<pcl::Vertices> &polygons);
182 
183  void
184  performReconstruction (PolygonMesh &output) override;
185 
186  void
187  performReconstruction (std::vector<pcl::Vertices> &polygons) override;
188 
189  /** \brief The method accepts facets only if the distance from any vertex to the facet->center
190  * (center of the voronoi cell) is smaller than alpha
191  */
192  double alpha_;
193 
194  /** \brief If set to true, the reconstructed point cloud describing the hull is obtained from
195  * the original input cloud by performing a nearest neighbor search from Qhull output.
196  */
198 
199  /** \brief the centers of the voronoi cells */
201 
202  /** \brief the dimensionality of the concave hull */
203  int dim_;
204 
205  /** \brief vector containing the point cloud indices of the convex hull points. */
207  };
208 }
209 
210 #ifdef PCL_NO_PRECOMPILE
211 #include <pcl/surface/impl/concave_hull.hpp>
212 #endif
213 
214 #endif
pcl::ConcaveHull::getClassName
std::string getClassName() const override
Class get name method.
Definition: concave_hull.h:167
pcl::ConcaveHull::PointCloudConstPtr
typename PointCloud::ConstPtr PointCloudConstPtr
Definition: concave_hull.h:71
pcl::ConcaveHull::alpha_
double alpha_
The method accepts facets only if the distance from any vertex to the facet->center (center of the vo...
Definition: concave_hull.h:192
pcl
Definition: convolution.h:46
pcl::ConcaveHull::ConcaveHull
ConcaveHull()
Empty constructor.
Definition: concave_hull.h:74
pcl::ConcaveHull::reconstruct
void reconstruct(PointCloud &points, std::vector< pcl::Vertices > &polygons)
Compute a concave hull for all points given.
Definition: concave_hull.hpp:88
pcl::ConcaveHull::setAlpha
void setAlpha(double alpha)
Set the alpha value, which limits the size of the resultant hull segments (the smaller the more detai...
Definition: concave_hull.h:104
pcl::ConcaveHull::~ConcaveHull
~ConcaveHull()
Empty destructor.
Definition: concave_hull.h:79
pcl::ConcaveHull::PointCloudPtr
typename PointCloud::Ptr PointCloudPtr
Definition: concave_hull.h:70
pcl::PCLBase
PCL base class.
Definition: pcl_base.h:69
pcl::PointCloud< PointInT >
pcl::ConcaveHull::getHullPointIndices
void getHullPointIndices(pcl::PointIndices &hull_point_indices) const
Retrieve the indices of the input point cloud that for the convex hull.
Definition: concave_hull.hpp:613
pcl::ConcaveHull::Ptr
shared_ptr< ConcaveHull< PointInT > > Ptr
Definition: concave_hull.h:58
pcl::ConcaveHull::getAlpha
double getAlpha()
Returns the alpha parameter, see setAlpha().
Definition: concave_hull.h:111
pcl::ConcaveHull::getDimension
int getDimension() const
Returns the dimensionality (2 or 3) of the calculated hull.
Definition: concave_hull.h:137
pcl::ConcaveHull::keep_information_
bool keep_information_
If set to true, the reconstructed point cloud describing the hull is obtained from the original input...
Definition: concave_hull.h:197
pcl::ConcaveHull::dim_
int dim_
the dimensionality of the concave hull
Definition: concave_hull.h:203
pcl::PolygonMesh
Definition: PolygonMesh.h:14
pcl::ConcaveHull::setVoronoiCenters
void setVoronoiCenters(PointCloudPtr voronoi_centers)
If set, the voronoi cells center will be saved in voronoi_centers
Definition: concave_hull.h:120
pcl::PointIndices
Definition: PointIndices.h:11
pcl::ConcaveHull::voronoi_centers_
PointCloudPtr voronoi_centers_
the centers of the voronoi cells
Definition: concave_hull.h:200
pcl::ConcaveHull::ConstPtr
shared_ptr< const ConcaveHull< PointInT > > ConstPtr
Definition: concave_hull.h:59
pcl::PointCloud< PointInT >::Ptr
shared_ptr< PointCloud< PointInT > > Ptr
Definition: point_cloud.h:406
pcl::ConcaveHull::hull_indices_
pcl::PointIndices hull_indices_
vector containing the point cloud indices of the convex hull points.
Definition: concave_hull.h:206
pcl::PointCloud< PointInT >::ConstPtr
shared_ptr< const PointCloud< PointInT > > ConstPtr
Definition: point_cloud.h:407
pcl::ConcaveHull::setDimension
void setDimension(int dimension)
Sets the dimension on the input data, 2D or 3D.
Definition: concave_hull.h:146
pcl::ConcaveHull::performReconstruction
void performReconstruction(PointCloud &points, std::vector< pcl::Vertices > &polygons)
The actual reconstruction method.
Definition: concave_hull.hpp:119
pcl::ConcaveHull
ConcaveHull (alpha shapes) using libqhull library.
Definition: concave_hull.h:55
pcl::ConcaveHull::setKeepInformation
void setKeepInformation(bool value)
If keep_information_is set to true the convex hull points keep other information like rgb,...
Definition: concave_hull.h:130
pcl::MeshConstruction
MeshConstruction represents a base surface reconstruction class.
Definition: reconstruction.h:185