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