Point Cloud Library (PCL)  1.14.1-dev
reconstruction.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2010-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_base.h>
43 #include <pcl/PolygonMesh.h>
44 #include <pcl/search/search.h> // for Search
45 
46 namespace pcl
47 {
48  /** \brief Pure abstract class. All types of meshing/reconstruction
49  * algorithms in \b libpcl_surface must inherit from this, in order to make
50  * sure we have a consistent API. The methods that we care about here are:
51  *
52  * - \b setSearchMethod(&SearchPtr): passes a search locator
53  * - \b reconstruct(&PolygonMesh): creates a PolygonMesh object from the input data
54  *
55  * \author Radu B. Rusu, Michael Dixon, Alexandru E. Ichim
56  * \ingroup surface
57  */
58  template <typename PointInT>
59  class PCLSurfaceBase: public PCLBase<PointInT>
60  {
61  public:
62  using Ptr = shared_ptr<PCLSurfaceBase<PointInT> >;
63  using ConstPtr = shared_ptr<const PCLSurfaceBase<PointInT> >;
64 
66  using KdTreePtr = typename KdTree::Ptr;
67 
68  /** \brief Empty constructor. */
69  PCLSurfaceBase () : tree_ () {}
70 
71  /** \brief Empty destructor */
72  ~PCLSurfaceBase () override = default;
73 
74  /** \brief Provide an optional pointer to a search object.
75  * \param[in] tree a pointer to the spatial search object.
76  */
77  inline void
78  setSearchMethod (const KdTreePtr &tree)
79  {
80  tree_ = tree;
81  }
82 
83  /** \brief Get a pointer to the search method used. */
84  inline KdTreePtr
85  getSearchMethod () { return (tree_); }
86 
87  /** \brief Base method for surface reconstruction for all points given in
88  * <setInputCloud (), setIndices ()>
89  * \param[out] output the resultant reconstructed surface model
90  */
91  virtual void
93 
94  protected:
95  /** \brief A pointer to the spatial search object. */
97 
98  /** \brief Abstract class get name method. */
99  virtual std::string
100  getClassName () const { return (""); }
101  };
102 
103  /** \brief SurfaceReconstruction represents a base surface reconstruction
104  * class. All \b surface reconstruction methods take in a point cloud and
105  * generate a new surface from it, by either re-sampling the data or
106  * generating new data altogether. These methods are thus \b not preserving
107  * the topology of the original data.
108  *
109  * \note Reconstruction methods that always preserve the original input
110  * point cloud data as the surface vertices and simply construct the mesh on
111  * top should inherit from \ref MeshConstruction.
112  *
113  * \author Radu B. Rusu, Michael Dixon, Alexandru E. Ichim
114  * \ingroup surface
115  */
116  template <typename PointInT>
117  class SurfaceReconstruction: public PCLSurfaceBase<PointInT>
118  {
119  public:
120  using Ptr = shared_ptr<SurfaceReconstruction<PointInT> >;
121  using ConstPtr = shared_ptr<const SurfaceReconstruction<PointInT> >;
122 
129 
130  /** \brief Constructor. */
131  SurfaceReconstruction () = default;
132 
133  /** \brief Destructor. */
134  ~SurfaceReconstruction () override = default;
135 
136  /** \brief Base method for surface reconstruction for all points given in
137  * <setInputCloud (), setIndices ()>
138  * \param[out] output the resultant reconstructed surface model
139  */
140  void
141  reconstruct (pcl::PolygonMesh &output) override;
142 
143  /** \brief Base method for surface reconstruction for all points given in
144  * <setInputCloud (), setIndices ()>
145  * \param[out] points the resultant points lying on the new surface
146  * \param[out] polygons the resultant polygons, as a set of
147  * vertices. The Vertices structure contains an array of point indices.
148  */
149  virtual void
151  std::vector<pcl::Vertices> &polygons);
152 
153  protected:
154  /** \brief A flag specifying whether or not the derived reconstruction
155  * algorithm needs the search object \a tree.*/
156  bool check_tree_{true};
157 
158  /** \brief Abstract surface reconstruction method.
159  * \param[out] output the output polygonal mesh
160  */
161  virtual void
163 
164  /** \brief Abstract surface reconstruction method.
165  * \param[out] points the resultant points lying on the surface
166  * \param[out] polygons the resultant polygons, as a set of vertices. The Vertices structure contains an array of point indices.
167  */
168  virtual void
170  std::vector<pcl::Vertices> &polygons) = 0;
171  };
172 
173  /** \brief MeshConstruction represents a base surface reconstruction
174  * class. All \b mesh constructing methods that take in a point cloud and
175  * generate a surface that uses the original data as vertices should inherit
176  * from this class.
177  *
178  * \note Reconstruction methods that generate a new surface or create new
179  * vertices in locations different than the input data should inherit from
180  * \ref SurfaceReconstruction.
181  *
182  * \author Radu B. Rusu, Michael Dixon, Alexandru E. Ichim
183  * \ingroup surface
184  */
185  template <typename PointInT>
186  class MeshConstruction: public PCLSurfaceBase<PointInT>
187  {
188  public:
189  using Ptr = shared_ptr<MeshConstruction<PointInT> >;
190  using ConstPtr = shared_ptr<const MeshConstruction<PointInT> >;
191 
198 
199  /** \brief Constructor. */
200  MeshConstruction () = default;
201 
202  /** \brief Destructor. */
203  ~MeshConstruction () override = default;
204 
205  /** \brief Base method for surface reconstruction for all points given in
206  * <setInputCloud (), setIndices ()>
207  * \param[out] output the resultant reconstructed surface model
208  *
209  * \note This method copies the input point cloud data from
210  * PointCloud<T> to PCLPointCloud2, and is implemented here for backwards
211  * compatibility only!
212  *
213  */
214  void
215  reconstruct (pcl::PolygonMesh &output) override;
216 
217  /** \brief Base method for mesh construction for all points given in
218  * <setInputCloud (), setIndices ()>
219  * \param[out] polygons the resultant polygons, as a set of
220  * vertices. The Vertices structure contains an array of point indices.
221  */
222  virtual void
223  reconstruct (std::vector<pcl::Vertices> &polygons);
224 
225  protected:
226  /** \brief A flag specifying whether or not the derived reconstruction
227  * algorithm needs the search object \a tree.*/
228  bool check_tree_{true};
229 
230  /** \brief Abstract surface reconstruction method.
231  * \param[out] output the output polygonal mesh
232  */
233  virtual void
235 
236  /** \brief Abstract surface reconstruction method.
237  * \param[out] polygons the resultant polygons, as a set of vertices. The Vertices structure contains an array of point indices.
238  */
239  virtual void
240  performReconstruction (std::vector<pcl::Vertices> &polygons) = 0;
241  };
242 }
243 
244 #include <pcl/surface/impl/reconstruction.hpp>
MeshConstruction represents a base surface reconstruction class.
~MeshConstruction() override=default
Destructor.
MeshConstruction()=default
Constructor.
virtual void performReconstruction(pcl::PolygonMesh &output)=0
Abstract surface reconstruction method.
void reconstruct(pcl::PolygonMesh &output) override
Base method for surface reconstruction for all points given in <setInputCloud (), setIndices ()>
virtual void performReconstruction(std::vector< pcl::Vertices > &polygons)=0
Abstract surface reconstruction method.
bool check_tree_
A flag specifying whether or not the derived reconstruction algorithm needs the search object tree.
PCL base class.
Definition: pcl_base.h:70
Pure abstract class.
shared_ptr< const PCLSurfaceBase< PointInT > > ConstPtr
typename KdTree::Ptr KdTreePtr
KdTreePtr getSearchMethod()
Get a pointer to the search method used.
KdTreePtr tree_
A pointer to the spatial search object.
virtual std::string getClassName() const
Abstract class get name method.
shared_ptr< PCLSurfaceBase< PointInT > > Ptr
PCLSurfaceBase()
Empty constructor.
virtual void reconstruct(pcl::PolygonMesh &output)=0
Base method for surface reconstruction for all points given in <setInputCloud (), setIndices ()>
~PCLSurfaceBase() override=default
Empty destructor.
void setSearchMethod(const KdTreePtr &tree)
Provide an optional pointer to a search object.
SurfaceReconstruction represents a base surface reconstruction class.
virtual void performReconstruction(pcl::PolygonMesh &output)=0
Abstract surface reconstruction method.
bool check_tree_
A flag specifying whether or not the derived reconstruction algorithm needs the search object tree.
void reconstruct(pcl::PolygonMesh &output) override
Base method for surface reconstruction for all points given in <setInputCloud (), setIndices ()>
SurfaceReconstruction()=default
Constructor.
~SurfaceReconstruction() override=default
Destructor.
virtual void performReconstruction(pcl::PointCloud< PointInT > &points, std::vector< pcl::Vertices > &polygons)=0
Abstract surface reconstruction method.
shared_ptr< pcl::search::Search< PointInT > > Ptr
Definition: search.h:81