Point Cloud Library (PCL)  1.7.0
/tmp/buildd/pcl-1.7-1.7.0/surface/include/pcl/surface/reconstruction.h
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Point Cloud Library (PCL) - www.pointclouds.org
00005  *  Copyright (c) 2010-2012, Willow Garage, Inc.
00006  *
00007  *  All rights reserved.
00008  *
00009  *  Redistribution and use in source and binary forms, with or without
00010  *  modification, are permitted provided that the following conditions
00011  *  are met:
00012  *
00013  *   * Redistributions of source code must retain the above copyright
00014  *     notice, this list of conditions and the following disclaimer.
00015  *   * Redistributions in binary form must reproduce the above
00016  *     copyright notice, this list of conditions and the following
00017  *     disclaimer in the documentation and/or other materials provided
00018  *     with the distribution.
00019  *   * Neither the name of Willow Garage, Inc. nor the names of its
00020  *     contributors may be used to endorse or promote products derived
00021  *     from this software without specific prior written permission.
00022  *
00023  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00024  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00025  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00026  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00027  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00028  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00029  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00030  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00031  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00032  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00033  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00034  *  POSSIBILITY OF SUCH DAMAGE.
00035  *
00036  * $Id$
00037  *
00038  */
00039 
00040 #ifndef PCL_SURFACE_RECONSTRUCTION_H_
00041 #define PCL_SURFACE_RECONSTRUCTION_H_
00042 
00043 #include <pcl/pcl_base.h>
00044 #include <pcl/PolygonMesh.h>
00045 #include <pcl/search/pcl_search.h>
00046 #include <pcl/conversions.h>
00047 #include <pcl/surface/boost.h>
00048 
00049 namespace pcl
00050 {
00051   /** \brief Pure abstract class. All types of meshing/reconstruction
00052     * algorithms in \b libpcl_surface must inherit from this, in order to make
00053     * sure we have a consistent API. The methods that we care about here are:
00054     *
00055     *  - \b setSearchMethod(&SearchPtr): passes a search locator
00056     *  - \b reconstruct(&PolygonMesh): creates a PolygonMesh object from the input data
00057     *
00058     * \author Radu B. Rusu, Michael Dixon, Alexandru E. Ichim
00059     */
00060   template <typename PointInT>
00061   class PCLSurfaceBase: public PCLBase<PointInT>
00062   {
00063     public:
00064       typedef boost::shared_ptr<PCLSurfaceBase<PointInT> > Ptr;
00065       typedef boost::shared_ptr<const PCLSurfaceBase<PointInT> > ConstPtr;
00066 
00067       typedef typename pcl::search::Search<PointInT> KdTree;
00068       typedef typename pcl::search::Search<PointInT>::Ptr KdTreePtr;
00069 
00070       /** \brief Empty constructor. */
00071       PCLSurfaceBase () : tree_ () {}
00072       
00073       /** \brief Empty destructor */
00074       virtual ~PCLSurfaceBase () {}
00075 
00076       /** \brief Provide an optional pointer to a search object.
00077         * \param[in] tree a pointer to the spatial search object.
00078         */
00079       inline void
00080       setSearchMethod (const KdTreePtr &tree)
00081       {
00082         tree_ = tree;
00083       }
00084 
00085       /** \brief Get a pointer to the search method used. */
00086       inline KdTreePtr 
00087       getSearchMethod () { return (tree_); }
00088 
00089       /** \brief Base method for surface reconstruction for all points given in
00090         * <setInputCloud (), setIndices ()> 
00091         * \param[out] output the resultant reconstructed surface model
00092         */
00093       virtual void 
00094       reconstruct (pcl::PolygonMesh &output) = 0;
00095 
00096     protected:
00097       /** \brief A pointer to the spatial search object. */
00098       KdTreePtr tree_;
00099 
00100       /** \brief Abstract class get name method. */
00101       virtual std::string 
00102       getClassName () const { return (""); }
00103   };
00104 
00105   /** \brief SurfaceReconstruction represents a base surface reconstruction
00106     * class. All \b surface reconstruction methods take in a point cloud and
00107     * generate a new surface from it, by either re-sampling the data or
00108     * generating new data altogether. These methods are thus \b not preserving
00109     * the topology of the original data.
00110     *
00111     * \note Reconstruction methods that always preserve the original input
00112     * point cloud data as the surface vertices and simply construct the mesh on
00113     * top should inherit from \ref MeshConstruction.
00114     *
00115     * \author Radu B. Rusu, Michael Dixon, Alexandru E. Ichim
00116     * \ingroup surface
00117     */
00118   template <typename PointInT>
00119   class SurfaceReconstruction: public PCLSurfaceBase<PointInT>
00120   {
00121     public:
00122       typedef boost::shared_ptr<SurfaceReconstruction<PointInT> > Ptr;
00123       typedef boost::shared_ptr<const SurfaceReconstruction<PointInT> > ConstPtr;
00124 
00125       using PCLSurfaceBase<PointInT>::input_;
00126       using PCLSurfaceBase<PointInT>::indices_;
00127       using PCLSurfaceBase<PointInT>::initCompute;
00128       using PCLSurfaceBase<PointInT>::deinitCompute;
00129       using PCLSurfaceBase<PointInT>::tree_;
00130       using PCLSurfaceBase<PointInT>::getClassName;
00131 
00132       /** \brief Constructor. */
00133       SurfaceReconstruction () : check_tree_ (true) {}
00134 
00135       /** \brief Destructor. */
00136       virtual ~SurfaceReconstruction () {}
00137 
00138        /** \brief Base method for surface reconstruction for all points given in
00139         * <setInputCloud (), setIndices ()> 
00140         * \param[out] output the resultant reconstructed surface model
00141         */
00142       virtual void 
00143       reconstruct (pcl::PolygonMesh &output);
00144 
00145       /** \brief Base method for surface reconstruction for all points given in
00146         * <setInputCloud (), setIndices ()> 
00147         * \param[out] points the resultant points lying on the new surface
00148         * \param[out] polygons the resultant polygons, as a set of
00149         * vertices. The Vertices structure contains an array of point indices.
00150         */
00151       virtual void 
00152       reconstruct (pcl::PointCloud<PointInT> &points,
00153                    std::vector<pcl::Vertices> &polygons);
00154 
00155     protected:
00156       /** \brief A flag specifying whether or not the derived reconstruction
00157         * algorithm needs the search object \a tree.*/
00158       bool check_tree_;
00159 
00160       /** \brief Abstract surface reconstruction method. 
00161         * \param[out] output the output polygonal mesh 
00162         */
00163       virtual void 
00164       performReconstruction (pcl::PolygonMesh &output) = 0;
00165 
00166       /** \brief Abstract surface reconstruction method. 
00167         * \param[out] points the resultant points lying on the surface
00168         * \param[out] polygons the resultant polygons, as a set of vertices. The Vertices structure contains an array of point indices.
00169         */
00170       virtual void 
00171       performReconstruction (pcl::PointCloud<PointInT> &points, 
00172                              std::vector<pcl::Vertices> &polygons) = 0;
00173   };
00174 
00175   /** \brief MeshConstruction represents a base surface reconstruction
00176     * class. All \b mesh constructing methods that take in a point cloud and
00177     * generate a surface that uses the original data as vertices should inherit
00178     * from this class.
00179     *
00180     * \note Reconstruction methods that generate a new surface or create new
00181     * vertices in locations different than the input data should inherit from
00182     * \ref SurfaceReconstruction.
00183     *
00184     * \author Radu B. Rusu, Michael Dixon, Alexandru E. Ichim
00185     * \ingroup surface
00186     */
00187   template <typename PointInT>
00188   class MeshConstruction: public PCLSurfaceBase<PointInT>
00189   {
00190     public:
00191       typedef boost::shared_ptr<MeshConstruction<PointInT> > Ptr;
00192       typedef boost::shared_ptr<const MeshConstruction<PointInT> > ConstPtr;
00193 
00194       using PCLSurfaceBase<PointInT>::input_;
00195       using PCLSurfaceBase<PointInT>::indices_;
00196       using PCLSurfaceBase<PointInT>::initCompute;
00197       using PCLSurfaceBase<PointInT>::deinitCompute;
00198       using PCLSurfaceBase<PointInT>::tree_;
00199       using PCLSurfaceBase<PointInT>::getClassName;
00200 
00201       /** \brief Constructor. */
00202       MeshConstruction () : check_tree_ (true) {}
00203 
00204       /** \brief Destructor. */
00205       virtual ~MeshConstruction () {}
00206 
00207       /** \brief Base method for surface reconstruction for all points given in
00208         * <setInputCloud (), setIndices ()> 
00209         * \param[out] output the resultant reconstructed surface model
00210         *
00211         * \note This method copies the input point cloud data from
00212         * PointCloud<T> to PCLPointCloud2, and is implemented here for backwards
00213         * compatibility only!
00214         *
00215         */
00216       virtual void 
00217       reconstruct (pcl::PolygonMesh &output);
00218 
00219       /** \brief Base method for mesh construction for all points given in
00220         * <setInputCloud (), setIndices ()> 
00221         * \param[out] polygons the resultant polygons, as a set of
00222         * vertices. The Vertices structure contains an array of point indices.
00223         */
00224       virtual void 
00225       reconstruct (std::vector<pcl::Vertices> &polygons);
00226 
00227     protected:
00228       /** \brief A flag specifying whether or not the derived reconstruction
00229         * algorithm needs the search object \a tree.*/
00230       bool check_tree_;
00231 
00232       /** \brief Abstract surface reconstruction method. 
00233         * \param[out] output the output polygonal mesh 
00234         */
00235       virtual void 
00236       performReconstruction (pcl::PolygonMesh &output) = 0;
00237 
00238       /** \brief Abstract surface reconstruction method. 
00239         * \param[out] polygons the resultant polygons, as a set of vertices. The Vertices structure contains an array of point indices.
00240         */
00241       virtual void 
00242       performReconstruction (std::vector<pcl::Vertices> &polygons) = 0;
00243   };
00244 }
00245 
00246 #include <pcl/surface/impl/reconstruction.hpp>
00247 
00248 #endif  // PCL_SURFACE_RECONSTRUCTION_H_
00249