Point Cloud Library (PCL) 1.15.0
Loading...
Searching...
No Matches
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
47namespace 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
61 using PCLBase<PointInT>::input_;
62 using PCLBase<PointInT>::indices_;
63 using PCLBase<PointInT>::initCompute;
64 using PCLBase<PointInT>::deinitCompute;
65
66 public:
67 using MeshConstruction<PointInT>::reconstruct;
68
72
73 /** \brief Empty constructor. */
74 ConcaveHull () = default;
75
76 /** \brief Empty destructor */
77 ~ConcaveHull () override = default;
78
79 /** \brief Compute a concave hull for all points given
80 *
81 * \param points the resultant points lying on the concave hull
82 * \param polygons the resultant concave hull polygons, as a set of
83 * vertices. The Vertices structure contains an array of point indices.
84 */
85 void
86 reconstruct (PointCloud &points,
87 std::vector<pcl::Vertices> &polygons);
88
89 /** \brief Compute a concave hull for all points given
90 * \param output the resultant concave hull vertices
91 */
92 void
93 reconstruct (PointCloud &output);
94
95 /** \brief Set the alpha value, which limits the size of the resultant
96 * hull segments (the smaller the more detailed the hull).
97 *
98 * \param alpha positive, non-zero value, defining the maximum length
99 * from a vertex to the facet center (center of the voronoi cell).
100 */
101 inline void
102 setAlpha (double alpha)
103 {
104 alpha_ = alpha;
105 }
106
107 /** \brief Returns the alpha parameter, see setAlpha(). */
108 inline double
110 {
111 return (alpha_);
112 }
113
114 /** \brief If set, the voronoi cells center will be saved in _voronoi_centers_
115 * \param voronoi_centers
116 */
117 inline void
119 {
120 voronoi_centers_ = voronoi_centers;
121 }
122
123 /** \brief If keep_information_is set to true the convex hull
124 * points keep other information like rgb, normals, ...
125 * \param value where to keep the information or not, default is false
126 */
127 void
129 {
130 keep_information_ = value;
131 }
132
133 /** \brief Returns the dimensionality (2 or 3) of the calculated hull. */
134 inline int
136 {
137 return (dim_);
138 }
139
140 /** \brief Sets the dimension on the input data, 2D or 3D.
141 * \param[in] dimension The dimension of the input data. If not set, this will be determined automatically.
142 */
143 void
144 setDimension (int dimension)
145 {
146 if ((dimension == 2) || (dimension == 3))
147 dim_ = dimension;
148 else
149 PCL_ERROR ("[pcl::%s::setDimension] Invalid input dimension specified!\n", getClassName ().c_str ());
150 }
151
152 /** \brief Retrieve the indices of the input point cloud that for the convex hull.
153 *
154 * \note Should only be called after reconstruction was performed and if the ConcaveHull is
155 * set to preserve information via setKeepInformation ().
156 *
157 * \param[out] hull_point_indices The indices of the points forming the point cloud
158 */
159 void
160 getHullPointIndices (pcl::PointIndices &hull_point_indices) const;
161
162 protected:
163 /** \brief Class get name method. */
164 std::string
165 getClassName () const override
166 {
167 return ("ConcaveHull");
168 }
169
170 protected:
171 /** \brief The actual reconstruction method.
172 *
173 * \param points the resultant points lying on the concave hull
174 * \param polygons the resultant concave hull polygons, as a set of
175 * vertices. The Vertices structure contains an array of point indices.
176 */
177 void
179 std::vector<pcl::Vertices> &polygons);
180
181 void
182 performReconstruction (PolygonMesh &output) override;
183
184 void
185 performReconstruction (std::vector<pcl::Vertices> &polygons) override;
186
187 /** \brief The method accepts facets only if the distance from any vertex to the facet->center
188 * (center of the voronoi cell) is smaller than alpha
189 */
190 double alpha_{0.0};
191
192 /** \brief If set to true, the reconstructed point cloud describing the hull is obtained from
193 * the original input cloud by performing a nearest neighbor search from Qhull output.
194 */
195 bool keep_information_{false};
196
197 /** \brief the centers of the voronoi cells */
199
200 /** \brief the dimensionality of the concave hull */
201 int dim_{0};
202
203 /** \brief vector containing the point cloud indices of the convex hull points. */
205 };
206}
207
208#ifdef PCL_NO_PRECOMPILE
209#include <pcl/surface/impl/concave_hull.hpp>
210#endif
211
212#endif
ConcaveHull (alpha shapes) using libqhull library.
void setVoronoiCenters(PointCloudPtr voronoi_centers)
If set, the voronoi cells center will be saved in voronoi_centers
void setKeepInformation(bool value)
If keep_information_is set to true the convex hull points keep other information like rgb,...
pcl::PointIndices hull_indices_
vector containing the point cloud indices of the convex hull points.
double alpha_
The method accepts facets only if the distance from any vertex to the facet->center (center of the vo...
int getDimension() const
Returns the dimensionality (2 or 3) of the calculated hull.
ConcaveHull()=default
Empty constructor.
shared_ptr< ConcaveHull< PointInT > > Ptr
typename PointCloud::ConstPtr PointCloudConstPtr
~ConcaveHull() override=default
Empty destructor.
bool keep_information_
If set to true, the reconstructed point cloud describing the hull is obtained from the original input...
void reconstruct(PointCloud &points, std::vector< pcl::Vertices > &polygons)
Compute a concave hull for all points given.
PointCloudPtr voronoi_centers_
the centers of the voronoi cells
void setAlpha(double alpha)
Set the alpha value, which limits the size of the resultant hull segments (the smaller the more detai...
shared_ptr< const ConcaveHull< PointInT > > ConstPtr
int dim_
the dimensionality of the concave hull
typename PointCloud::Ptr PointCloudPtr
void getHullPointIndices(pcl::PointIndices &hull_point_indices) const
Retrieve the indices of the input point cloud that for the convex hull.
std::string getClassName() const override
Class get name method.
void performReconstruction(PointCloud &points, std::vector< pcl::Vertices > &polygons)
The actual reconstruction method.
double getAlpha()
Returns the alpha parameter, see setAlpha().
void setDimension(int dimension)
Sets the dimension on the input data, 2D or 3D.
MeshConstruction represents a base surface reconstruction class.
PCL base class.
Definition pcl_base.h:70
PointCloudConstPtr input_
The input point cloud dataset.
Definition pcl_base.h:147
IndicesPtr indices_
A pointer to the vector of point indices to use.
Definition pcl_base.h:150
bool initCompute()
This method should get called before starting the actual computation.
Definition pcl_base.hpp:138
bool deinitCompute()
This method should get called after finishing the actual computation.
Definition pcl_base.hpp:175
shared_ptr< PointCloud< PointInT > > Ptr
shared_ptr< const PointCloud< PointInT > > ConstPtr