Point Cloud Library (PCL)  1.8.1
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 #include <pcl/pcl_config.h>
41 #ifdef HAVE_QHULL
42 
43 #ifndef PCL_CONCAVE_HULL_H
44 #define PCL_CONCAVE_HULL_H
45 
46 #include <pcl/surface/convex_hull.h>
47 
48 namespace pcl
49 {
50  ////////////////////////////////////////////////////////////////////////////////////////////
51  /** \brief @b ConcaveHull (alpha shapes) using libqhull library.
52  * \author Aitor Aldoma
53  * \ingroup surface
54  */
55  template<typename PointInT>
56  class ConcaveHull : public MeshConstruction<PointInT>
57  {
58  protected:
59  typedef boost::shared_ptr<ConcaveHull<PointInT> > Ptr;
60  typedef boost::shared_ptr<const ConcaveHull<PointInT> > ConstPtr;
61 
66 
67  public:
69 
71  typedef typename PointCloud::Ptr PointCloudPtr;
73 
74  /** \brief Empty constructor. */
76  {
77  };
78 
79  /** \brief Empty destructor */
80  virtual ~ConcaveHull () {}
81 
82  /** \brief Compute a concave hull for all points given
83  *
84  * \param points the resultant points lying on the concave hull
85  * \param polygons the resultant concave hull polygons, as a set of
86  * vertices. The Vertices structure contains an array of point indices.
87  */
88  void
89  reconstruct (PointCloud &points,
90  std::vector<pcl::Vertices> &polygons);
91 
92  /** \brief Compute a concave hull for all points given
93  * \param output the resultant concave hull vertices
94  */
95  void
96  reconstruct (PointCloud &output);
97 
98  /** \brief Set the alpha value, which limits the size of the resultant
99  * hull segments (the smaller the more detailed the hull).
100  *
101  * \param alpha positive, non-zero value, defining the maximum length
102  * from a vertex to the facet center (center of the voronoi cell).
103  */
104  inline void
105  setAlpha (double alpha)
106  {
107  alpha_ = alpha;
108  }
109 
110  /** \brief Returns the alpha parameter, see setAlpha(). */
111  inline double
113  {
114  return (alpha_);
115  }
116 
117  /** \brief If set, the voronoi cells center will be saved in _voronoi_centers_
118  * \param voronoi_centers
119  */
120  inline void
122  {
123  voronoi_centers_ = voronoi_centers;
124  }
125 
126  /** \brief If keep_information_is set to true the convex hull
127  * points keep other information like rgb, normals, ...
128  * \param value where to keep the information or not, default is false
129  */
130  void
131  setKeepInformation (bool value)
132  {
133  keep_information_ = value;
134  }
135 
136  /** \brief Returns the dimensionality (2 or 3) of the calculated hull. */
137  PCL_DEPRECATED ("[pcl::ConcaveHull::getDim] This method is deprecated. Please use getDimension () instead.")
138  int
139  getDim () const;
140 
141  /** \brief Returns the dimensionality (2 or 3) of the calculated hull. */
142  inline int
143  getDimension () const
144  {
145  return (dim_);
146  }
147 
148  /** \brief Sets the dimension on the input data, 2D or 3D.
149  * \param[in] dimension The dimension of the input data. If not set, this will be determined automatically.
150  */
151  void
152  setDimension (int dimension)
153  {
154  if ((dimension == 2) || (dimension == 3))
155  dim_ = dimension;
156  else
157  PCL_ERROR ("[pcl::%s::setDimension] Invalid input dimension specified!\n", getClassName ().c_str ());
158  }
159 
160  /** \brief Retrieve the indices of the input point cloud that for the convex hull.
161  *
162  * \note Should only be called after reconstruction was performed and if the ConcaveHull is
163  * set to preserve information via setKeepInformation ().
164  *
165  * \param[out] hull_point_indices The indices of the points forming the point cloud
166  */
167  void
168  getHullPointIndices (pcl::PointIndices &hull_point_indices) const;
169 
170  protected:
171  /** \brief Class get name method. */
172  std::string
173  getClassName () const
174  {
175  return ("ConcaveHull");
176  }
177 
178  protected:
179  /** \brief The actual reconstruction method.
180  *
181  * \param points the resultant points lying on the concave hull
182  * \param polygons the resultant concave hull polygons, as a set of
183  * vertices. The Vertices structure contains an array of point indices.
184  */
185  void
187  std::vector<pcl::Vertices> &polygons);
188 
189  virtual void
191 
192  virtual void
193  performReconstruction (std::vector<pcl::Vertices> &polygons);
194 
195  /** \brief The method accepts facets only if the distance from any vertex to the facet->center
196  * (center of the voronoi cell) is smaller than alpha
197  */
198  double alpha_;
199 
200  /** \brief If set to true, the reconstructed point cloud describing the hull is obtained from
201  * the original input cloud by performing a nearest neighbor search from Qhull output.
202  */
204 
205  /** \brief the centers of the voronoi cells */
207 
208  /** \brief the dimensionality of the concave hull */
209  int dim_;
210 
211  /** \brief vector containing the point cloud indices of the convex hull points. */
213  };
214 }
215 
216 #ifdef PCL_NO_PRECOMPILE
217 #include <pcl/surface/impl/concave_hull.hpp>
218 #endif
219 
220 #endif //#ifndef PCL_CONCAVE_HULL
221 #endif
PointCloud::ConstPtr PointCloudConstPtr
Definition: concave_hull.h:72
pcl::PointIndices hull_indices_
vector containing the point cloud indices of the convex hull points.
Definition: concave_hull.h:212
boost::shared_ptr< const ConcaveHull< PointInT > > ConstPtr
Definition: concave_hull.h:60
void setKeepInformation(bool value)
If keep_information_is set to true the convex hull points keep other information like rgb...
Definition: concave_hull.h:131
ConcaveHull()
Empty constructor.
Definition: concave_hull.h:75
void setVoronoiCenters(PointCloudPtr voronoi_centers)
If set, the voronoi cells center will be saved in voronoi_centers
Definition: concave_hull.h:121
pcl::PointCloud< PointInT > PointCloud
Definition: concave_hull.h:70
void setDimension(int dimension)
Sets the dimension on the input data, 2D or 3D.
Definition: concave_hull.h:152
boost::shared_ptr< PointCloud< PointT > > Ptr
Definition: point_cloud.h:428
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:105
void reconstruct(PointCloud &points, std::vector< pcl::Vertices > &polygons)
Compute a concave hull for all points given.
boost::shared_ptr< ConcaveHull< PointInT > > Ptr
Definition: concave_hull.h:59
PCL base class.
Definition: pcl_base.h:68
PointCloudPtr voronoi_centers_
the centers of the voronoi cells
Definition: concave_hull.h:206
void getHullPointIndices(pcl::PointIndices &hull_point_indices) const
Retrieve the indices of the input point cloud that for the convex hull.
boost::shared_ptr< const PointCloud< PointInT > > ConstPtr
Definition: point_cloud.h:429
MeshConstruction represents a base surface reconstruction class.
int getDimension() const
Returns the dimensionality (2 or 3) of the calculated hull.
Definition: concave_hull.h:143
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:198
double getAlpha()
Returns the alpha parameter, see setAlpha().
Definition: concave_hull.h:112
bool keep_information_
If set to true, the reconstructed point cloud describing the hull is obtained from the original input...
Definition: concave_hull.h:203
void performReconstruction(PointCloud &points, std::vector< pcl::Vertices > &polygons)
The actual reconstruction method.
std::string getClassName() const
Class get name method.
Definition: concave_hull.h:173
virtual ~ConcaveHull()
Empty destructor.
Definition: concave_hull.h:80
ConcaveHull (alpha shapes) using libqhull library.
Definition: concave_hull.h:56
int getDim() const
Returns the dimensionality (2 or 3) of the calculated hull.
int dim_
the dimensionality of the concave hull
Definition: concave_hull.h:209
PointCloud::Ptr PointCloudPtr
Definition: concave_hull.h:71