Point Cloud Library (PCL)  1.7.0
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 (int getDim () const, "[pcl::ConcaveHull::getDim] This method is deprecated. Please use getDimension () instead.");
138 
139  /** \brief Returns the dimensionality (2 or 3) of the calculated hull. */
140  inline int
141  getDimension () const
142  {
143  return (dim_);
144  }
145 
146  /** \brief Sets the dimension on the input data, 2D or 3D.
147  * \param[in] dimension The dimension of the input data. If not set, this will be determined automatically.
148  */
149  void
150  setDimension (int dimension)
151  {
152  if ((dimension == 2) || (dimension == 3))
153  dim_ = dimension;
154  else
155  PCL_ERROR ("[pcl::%s::setDimension] Invalid input dimension specified!\n", getClassName ().c_str ());
156  }
157 
158  protected:
159  /** \brief Class get name method. */
160  std::string
161  getClassName () const
162  {
163  return ("ConcaveHull");
164  }
165 
166  protected:
167  /** \brief The actual reconstruction method.
168  *
169  * \param points the resultant points lying on the concave hull
170  * \param polygons the resultant concave hull polygons, as a set of
171  * vertices. The Vertices structure contains an array of point indices.
172  */
173  void
175  std::vector<pcl::Vertices> &polygons);
176 
177  virtual void
179 
180  virtual void
181  performReconstruction (std::vector<pcl::Vertices> &polygons);
182 
183  /** \brief The method accepts facets only if the distance from any vertex to the facet->center
184  * (center of the voronoi cell) is smaller than alpha
185  */
186  double alpha_;
187 
188  /** \brief If set to true, the reconstructed point cloud describing the hull is obtained from
189  * the original input cloud by performing a nearest neighbor search from Qhull output.
190  */
192 
193  /** \brief the centers of the voronoi cells */
195 
196  /** \brief the dimensionality of the concave hull */
197  int dim_;
198  };
199 }
200 
201 #ifdef PCL_NO_PRECOMPILE
202 #include <pcl/surface/impl/concave_hull.hpp>
203 #endif
204 
205 #endif //#ifndef PCL_CONCAVE_HULL
206 #endif
PointCloud::ConstPtr PointCloudConstPtr
Definition: concave_hull.h:72
boost::shared_ptr< const PointCloud< PointT > > ConstPtr
Definition: point_cloud.h:429
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
boost::shared_ptr< PointCloud< PointT > > Ptr
Definition: point_cloud.h:428
ConcaveHull()
Empty constructor.
Definition: concave_hull.h:75
int getDimension() const
Returns the dimensionality (2 or 3) of the calculated hull.
Definition: concave_hull.h:141
void setVoronoiCenters(PointCloudPtr voronoi_centers)
If set, the voronoi cells center will be saved in voronoi_centers
Definition: concave_hull.h:121
PCL_DEPRECATED(int getDim() const,"[pcl::ConcaveHull::getDim] This method is deprecated. Please use getDimension () instead.")
Returns the dimensionality (2 or 3) of the calculated hull.
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:150
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:194
std::string getClassName() const
Class get name method.
Definition: concave_hull.h:161
MeshConstruction represents a base surface reconstruction class.
double alpha_
The method accepts facets only if the distance from any vertex to the facet-&gt;center (center of the vo...
Definition: concave_hull.h:186
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:191
void performReconstruction(PointCloud &points, std::vector< pcl::Vertices > &polygons)
The actual reconstruction method.
virtual ~ConcaveHull()
Empty destructor.
Definition: concave_hull.h:80
ConcaveHull (alpha shapes) using libqhull library.
Definition: concave_hull.h:56
int dim_
the dimensionality of the concave hull
Definition: concave_hull.h:197
PointCloud::Ptr PointCloudPtr
Definition: concave_hull.h:71