Point Cloud Library (PCL)  1.7.0
/tmp/buildd/pcl-1.7-1.7.0/io/include/pcl/io/vtk_lib_io.h
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Point Cloud Library (PCL) - www.pointclouds.org
00005  *  Copyright (c) 2011, Dirk Holz, University of Bonn.
00006  *  Copyright (c) 2012-, Open Perception, Inc.
00007  *
00008  *  All rights reserved.
00009  *
00010  *  Redistribution and use in source and binary forms, with or without
00011  *  modification, are permitted provided that the following conditions
00012  *  are met:
00013  *
00014  *   * Redistributions of source code must retain the above copyright
00015  *     notice, this list of conditions and the following disclaimer.
00016  *   * Redistributions in binary form must reproduce the above
00017  *     copyright notice, this list of conditions and the following
00018  *     disclaimer in the documentation and/or other materials provided
00019  *     with the distribution.
00020  *   * Neither the name of the copyright holder(s) nor the names of its
00021  *     contributors may be used to endorse or promote products derived
00022  *     from this software without specific prior written permission.
00023  *
00024  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00025  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00026  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00027  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00028  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00029  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00030  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00031  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00032  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00033  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00034  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00035  *  POSSIBILITY OF SUCH DAMAGE.
00036  *
00037  * $Id$
00038  *
00039  */
00040 
00041 #ifndef PCL_IO_VTK_LIB_IO_H_
00042 #define PCL_IO_VTK_LIB_IO_H_
00043 
00044 #include <pcl/point_types.h>
00045 #include <pcl/point_cloud.h>
00046 #include <pcl/PolygonMesh.h>
00047 #include <pcl/TextureMesh.h>
00048 #include <pcl/pcl_macros.h>
00049 #include <pcl/conversions.h>
00050 #include <pcl/io/pcd_io.h>
00051 #include <pcl/range_image/range_image_planar.h>
00052 
00053 // Ignore warnings in the above headers
00054 #ifdef __GNUC__
00055 #pragma GCC system_header 
00056 #endif
00057 #include <vtkSmartPointer.h>
00058 #include <vtkStructuredGrid.h>
00059 #include <vtkPoints.h>
00060 #include <vtkPointData.h>
00061 #include <vtkCellArray.h>
00062 #include <vtkUnsignedCharArray.h>
00063 #include <vtkFloatArray.h>
00064 #include <vtkPolyDataReader.h>
00065 #include <vtkPolyDataWriter.h>
00066 #include <vtkPLYReader.h>
00067 #include <vtkPLYWriter.h>
00068 #include <vtkOBJReader.h>
00069 #include <vtkSTLReader.h>
00070 #include <vtkSTLWriter.h>
00071 #include <vtkPNGReader.h>
00072 #include <vtkImageData.h>
00073 #include <vtkPolyDataNormals.h>
00074 
00075 namespace pcl
00076 {
00077   namespace io
00078   {
00079     /** \brief Convert vtkPolyData object to a PCL PolygonMesh
00080       * \param[in] poly_data Pointer (vtkSmartPointer) to a vtkPolyData object
00081       * \param[out] mesh PCL Polygon Mesh to fill
00082       * \return Number of points in the point cloud of mesh.
00083       */
00084     PCL_EXPORTS int
00085     vtk2mesh (const vtkSmartPointer<vtkPolyData>& poly_data, 
00086               pcl::PolygonMesh& mesh);
00087 
00088     /** \brief Convert vtkPolyData object to a PCL TextureMesh
00089       * \note In addition to the vtk2mesh (const vtkSmartPointer<vtkPolyData>&, pcl::PolygonMesh&)
00090       * method, it fills the mesh with the uv-coordinates.
00091       * \param[in] poly_data Pointer (vtkSmartPointer) to a vtkPolyData object
00092       * \param[out] mesh PCL TextureMesh to fill
00093       * \return Number of points in the point cloud of mesh.
00094       */
00095     PCL_EXPORTS int
00096     vtk2mesh (const vtkSmartPointer<vtkPolyData>& poly_data,
00097               pcl::TextureMesh& mesh);
00098 
00099 
00100     /** \brief Convert a PCL PolygonMesh to a vtkPolyData object
00101       * \param[in] mesh Reference to PCL Polygon Mesh
00102       * \param[out] poly_data Pointer (vtkSmartPointer) to a vtkPolyData object
00103       * \return Number of points in the point cloud of mesh.
00104       */
00105     PCL_EXPORTS int
00106     mesh2vtk (const pcl::PolygonMesh& mesh, 
00107               vtkSmartPointer<vtkPolyData>& poly_data);
00108 
00109     /** \brief Load a \ref PolygonMesh object given an input file name, based on the file extension
00110       * \param[in] file_name the name of the file containing the polygon data
00111       * \param[out] mesh the object that we want to load the data in 
00112       * \ingroup io
00113       */ 
00114     PCL_EXPORTS int
00115     loadPolygonFile (const std::string &file_name, 
00116                      pcl::PolygonMesh& mesh);
00117 
00118     /** \brief Save a \ref PolygonMesh object given an input file name, based on the file extension
00119       * \param[in] file_name the name of the file to save the data to
00120       * \param[in] mesh the object that contains the data
00121       * \ingroup io
00122       */
00123     PCL_EXPORTS int
00124     savePolygonFile (const std::string &file_name, 
00125                      const pcl::PolygonMesh& mesh);
00126 
00127     /** \brief Load a VTK file into a \ref PolygonMesh object
00128       * \param[in] file_name the name of the file that contains the data
00129       * \param[out] mesh the object that we want to load the data in 
00130       * \ingroup io
00131       */
00132     PCL_EXPORTS int
00133     loadPolygonFileVTK (const std::string &file_name, 
00134                         pcl::PolygonMesh& mesh);
00135 
00136     /** \brief Load a PLY file into a \ref PolygonMesh object
00137       * \param[in] file_name the name of the file that contains the data
00138       * \param[out] mesh the object that we want to load the data in 
00139       * \ingroup io
00140       */
00141     PCL_EXPORTS int
00142     loadPolygonFilePLY (const std::string &file_name, 
00143                         pcl::PolygonMesh& mesh);
00144 
00145     /** \brief Load an OBJ file into a \ref PolygonMesh object
00146       * \param[in] file_name the name of the file that contains the data
00147       * \param[out] mesh the object that we want to load the data in 
00148       * \ingroup io
00149       */
00150     PCL_EXPORTS int
00151     loadPolygonFileOBJ (const std::string &file_name, 
00152                         pcl::PolygonMesh& mesh);
00153 
00154     /** \brief Load an OBJ file into a \ref TextureMesh object.
00155       * \note In addition to the loadPolygonFileOBJ (const std::string, pcl::PolygonMesh&)
00156       * method, this method also loads the uv-coordinates from the file. It does not
00157       * load the material information.
00158       * \param[in] file_name the name of the file that contains the data
00159       * \param[out] mesh the object that we want to load the data in
00160       * \ingroup io
00161       */
00162     PCL_EXPORTS int
00163     loadPolygonFileOBJ (const std::string &file_name,
00164                         pcl::TextureMesh& mesh);
00165 
00166 
00167     /** \brief Load an STL file into a \ref PolygonMesh object
00168       * \param[in] file_name the name of the file that contains the data
00169       * \param[out] mesh the object that we want to load the data in 
00170       * \ingroup io
00171       */
00172     PCL_EXPORTS int
00173     loadPolygonFileSTL (const std::string &file_name, 
00174                         pcl::PolygonMesh& mesh);
00175 
00176     /** \brief Save a \ref PolygonMesh object into a VTK file
00177       * \param[in] file_name the name of the file to save the data to
00178       * \param[in] mesh the object that contains the data
00179       * \ingroup io
00180       */
00181     PCL_EXPORTS int
00182     savePolygonFileVTK (const std::string &file_name, 
00183                         const pcl::PolygonMesh& mesh);
00184 
00185     /** \brief Save a \ref PolygonMesh object into a PLY file
00186       * \param[in] file_name the name of the file to save the data to
00187       * \param[in] mesh the object that contains the data
00188       * \ingroup io
00189       */
00190     PCL_EXPORTS int
00191     savePolygonFilePLY (const std::string &file_name, 
00192                         const pcl::PolygonMesh& mesh);
00193 
00194     /** \brief Save a \ref PolygonMesh object into an STL file
00195       * \param[in] file_name the name of the file to save the data to
00196       * \param[in] mesh the object that contains the data
00197       * \ingroup io
00198       */
00199     PCL_EXPORTS int
00200     savePolygonFileSTL (const std::string &file_name, 
00201                         const pcl::PolygonMesh& mesh);
00202 
00203     /** \brief Write a \ref RangeImagePlanar object to a PNG file
00204       * \param[in] file_name the name of the file to save the data to
00205       * \param[in] range_image the object that contains the data
00206       * \ingroup io
00207       */
00208     PCL_EXPORTS void
00209     saveRangeImagePlanarFilePNG (const std::string &file_name,
00210                                  const pcl::RangeImagePlanar& range_image);
00211 
00212     /** \brief Convert a pcl::PointCloud object to a VTK PolyData one.
00213       * \param[in] cloud the input pcl::PointCloud object
00214       * \param[out] polydata the resultant VTK PolyData object
00215       * \ingroup io
00216       */
00217     template <typename PointT> void
00218     pointCloudTovtkPolyData (const pcl::PointCloud<PointT>& cloud, 
00219                              vtkPolyData* const polydata);
00220 
00221     /** \brief Convert a PCLPointCloud2 object to a VTK PolyData object.
00222       * \param[in] cloud the input PCLPointCloud2Ptr object
00223       * \param[out] poly_data the resultant VTK PolyData object
00224       * \ingroup io
00225       */
00226     PCL_EXPORTS void
00227     pointCloudTovtkPolyData(const pcl::PCLPointCloud2Ptr& cloud, vtkSmartPointer<vtkPolyData>& poly_data);
00228 
00229     /** \brief Convert a pcl::PointCloud object to a VTK StructuredGrid one.
00230       * \param[in] cloud the input pcl::PointCloud object
00231       * \param[out] structured_grid the resultant VTK StructuredGrid object
00232       * \ingroup io
00233       */
00234     template <typename PointT> void
00235     pointCloudTovtkStructuredGrid (const pcl::PointCloud<PointT>& cloud, 
00236                                    vtkStructuredGrid* const structured_grid);
00237 
00238     /** \brief Convert a VTK PolyData object to a pcl::PointCloud one.
00239       * \param[in] polydata the input VTK PolyData object
00240       * \param[out] cloud the resultant pcl::PointCloud object
00241       * \ingroup io
00242       */
00243     template <typename PointT> void
00244     vtkPolyDataToPointCloud (vtkPolyData* const polydata, 
00245                              pcl::PointCloud<PointT>& cloud);
00246 
00247     /** \brief Convert a VTK StructuredGrid object to a pcl::PointCloud one.
00248       * \param[in] structured_grid the input VTK StructuredGrid object
00249       * \param[out] cloud the resultant pcl::PointCloud object
00250       * \ingroup io
00251       */
00252     template <typename PointT> void
00253     vtkStructuredGridToPointCloud (vtkStructuredGrid* const structured_grid, 
00254                                    pcl::PointCloud<PointT>& cloud);
00255 
00256   }
00257 }
00258 
00259 #include <pcl/io/impl/vtk_lib_io.hpp>
00260 
00261 #endif /* PLC_IO_VTK_LIB_IO_H_ */