Point Cloud Library (PCL)  1.9.1
vtk_lib_io.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2011, Dirk Holz, University of Bonn.
6  * Copyright (c) 2012-, Open Perception, Inc.
7  *
8  * All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  *
14  * * Redistributions of source code must retain the above copyright
15  * notice, this list of conditions and the following disclaimer.
16  * * Redistributions in binary form must reproduce the above
17  * copyright notice, this list of conditions and the following
18  * disclaimer in the documentation and/or other materials provided
19  * with the distribution.
20  * * Neither the name of the copyright holder(s) nor the names of its
21  * contributors may be used to endorse or promote products derived
22  * from this software without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35  * POSSIBILITY OF SUCH DAMAGE.
36  *
37  * $Id$
38  *
39  */
40 
41 #ifndef PCL_IO_VTK_LIB_IO_H_
42 #define PCL_IO_VTK_LIB_IO_H_
43 
44 #include <pcl/point_types.h>
45 #include <pcl/point_cloud.h>
46 #include <pcl/PolygonMesh.h>
47 #include <pcl/TextureMesh.h>
48 #include <pcl/pcl_macros.h>
49 #include <pcl/conversions.h>
50 #include <pcl/io/pcd_io.h>
51 #include <pcl/range_image/range_image_planar.h>
52 
53 // Ignore warnings in the above headers
54 #ifdef __GNUC__
55 #pragma GCC system_header
56 #endif
57 #include <vtkVersion.h>
58 #include <vtkSmartPointer.h>
59 #include <vtkStructuredGrid.h>
60 #include <vtkPoints.h>
61 #include <vtkPointData.h>
62 #include <vtkCellArray.h>
63 #include <vtkUnsignedCharArray.h>
64 #include <vtkFloatArray.h>
65 #include <vtkPolyDataReader.h>
66 #include <vtkPolyDataWriter.h>
67 #include <vtkPLYReader.h>
68 #include <vtkPLYWriter.h>
69 #include <vtkOBJReader.h>
70 #include <vtkSTLReader.h>
71 #include <vtkSTLWriter.h>
72 #include <vtkPNGReader.h>
73 #include <vtkImageData.h>
74 #include <vtkPolyDataNormals.h>
75 
76 namespace pcl
77 {
78  namespace io
79  {
80  /** \brief Convert vtkPolyData object to a PCL PolygonMesh
81  * \param[in] poly_data Pointer (vtkSmartPointer) to a vtkPolyData object
82  * \param[out] mesh PCL Polygon Mesh to fill
83  * \return Number of points in the point cloud of mesh.
84  */
85  PCL_EXPORTS int
86  vtk2mesh (const vtkSmartPointer<vtkPolyData>& poly_data,
87  pcl::PolygonMesh& mesh);
88 
89  /** \brief Convert vtkPolyData object to a PCL TextureMesh
90  * \note In addition to the vtk2mesh (const vtkSmartPointer<vtkPolyData>&, pcl::PolygonMesh&)
91  * method, it fills the mesh with the uv-coordinates.
92  * \param[in] poly_data Pointer (vtkSmartPointer) to a vtkPolyData object
93  * \param[out] mesh PCL TextureMesh to fill
94  * \return Number of points in the point cloud of mesh.
95  */
96  PCL_EXPORTS int
97  vtk2mesh (const vtkSmartPointer<vtkPolyData>& poly_data,
98  pcl::TextureMesh& mesh);
99 
100 
101  /** \brief Convert a PCL PolygonMesh to a vtkPolyData object
102  * \param[in] mesh Reference to PCL Polygon Mesh
103  * \param[out] poly_data Pointer (vtkSmartPointer) to a vtkPolyData object
104  * \return Number of points in the point cloud of mesh.
105  */
106  PCL_EXPORTS int
107  mesh2vtk (const pcl::PolygonMesh& mesh,
108  vtkSmartPointer<vtkPolyData>& poly_data);
109 
110  /** \brief Load a \ref PolygonMesh object given an input file name, based on the file extension
111  * \param[in] file_name the name of the file containing the polygon data
112  * \param[out] mesh the object that we want to load the data in
113  * \ingroup io
114  */
115  PCL_EXPORTS int
116  loadPolygonFile (const std::string &file_name,
117  pcl::PolygonMesh& mesh);
118 
119  /** \brief Save a \ref PolygonMesh object given an input file name, based on the file extension
120  * \param[in] file_name the name of the file to save the data to
121  * \param[in] mesh the object that contains the data
122  * \param[in] binary_format if true, exported file is in binary format
123  * \return True if successful, false otherwise
124  * \ingroup io
125  */
126  PCL_EXPORTS bool
127  savePolygonFile (const std::string &file_name,
128  const pcl::PolygonMesh& mesh,
129  const bool binary_format = true);
130 
131  /** \brief Load a VTK file into a \ref PolygonMesh object
132  * \param[in] file_name the name of the file that contains the data
133  * \param[out] mesh the object that we want to load the data in
134  * \ingroup io
135  */
136  PCL_EXPORTS int
137  loadPolygonFileVTK (const std::string &file_name,
138  pcl::PolygonMesh& mesh);
139 
140  /** \brief Load a PLY file into a \ref PolygonMesh object
141  * \param[in] file_name the name of the file that contains the data
142  * \param[out] mesh the object that we want to load the data in
143  * \ingroup io
144  */
145  PCL_EXPORTS int
146  loadPolygonFilePLY (const std::string &file_name,
147  pcl::PolygonMesh& mesh);
148 
149  /** \brief Load an OBJ file into a \ref PolygonMesh object
150  * \param[in] file_name the name of the file that contains the data
151  * \param[out] mesh the object that we want to load the data in
152  * \ingroup io
153  */
154  PCL_EXPORTS int
155  loadPolygonFileOBJ (const std::string &file_name,
156  pcl::PolygonMesh& mesh);
157 
158  /** \brief Load an OBJ file into a \ref TextureMesh object.
159  * \note In addition to the loadPolygonFileOBJ (const std::string, pcl::PolygonMesh&)
160  * method, this method also loads the uv-coordinates from the file. It does not
161  * load the material information.
162  * \param[in] file_name the name of the file that contains the data
163  * \param[out] mesh the object that we want to load the data in
164  * \ingroup io
165  */
166  PCL_EXPORTS int
167  loadPolygonFileOBJ (const std::string &file_name,
168  pcl::TextureMesh& mesh);
169 
170 
171  /** \brief Load an STL file into a \ref PolygonMesh object
172  * \param[in] file_name the name of the file that contains the data
173  * \param[out] mesh the object that we want to load the data in
174  * \ingroup io
175  */
176  PCL_EXPORTS int
177  loadPolygonFileSTL (const std::string &file_name,
178  pcl::PolygonMesh& mesh);
179 
180  /** \brief Save a \ref PolygonMesh object into a VTK file
181  * \param[in] file_name the name of the file to save the data to
182  * \param[in] mesh the object that contains the data
183  * \param[in] binary_format if true, exported file is in binary format
184  * \return True if successful, false otherwise
185  * \ingroup io
186  */
187  PCL_EXPORTS bool
188  savePolygonFileVTK (const std::string &file_name,
189  const pcl::PolygonMesh& mesh,
190  const bool binary_format = true);
191 
192  /** \brief Save a \ref PolygonMesh object into a PLY file
193  * \param[in] file_name the name of the file to save the data to
194  * \param[in] mesh the object that contains the data
195  * \param[in] binary_format if true, exported file is in binary format
196  * \return True if successful, false otherwise
197  * \ingroup io
198  */
199  PCL_EXPORTS bool
200  savePolygonFilePLY (const std::string &file_name,
201  const pcl::PolygonMesh& mesh,
202  const bool binary_format = true);
203 
204  /** \brief Save a \ref PolygonMesh object into an STL file
205  * \param[in] file_name the name of the file to save the data to
206  * \param[in] mesh the object that contains the data
207  * \param[in] binary_format if true, exported file is in binary format
208  * \return True if successful, false otherwise
209  * \ingroup io
210  */
211  PCL_EXPORTS bool
212  savePolygonFileSTL (const std::string &file_name,
213  const pcl::PolygonMesh& mesh,
214  const bool binary_format = true);
215 
216  /** \brief Write a \ref RangeImagePlanar object to a PNG file
217  * \param[in] file_name the name of the file to save the data to
218  * \param[in] range_image the object that contains the data
219  * \ingroup io
220  */
221  PCL_EXPORTS void
222  saveRangeImagePlanarFilePNG (const std::string &file_name,
223  const pcl::RangeImagePlanar& range_image);
224 
225  /** \brief Convert a pcl::PointCloud object to a VTK PolyData one.
226  * \param[in] cloud the input pcl::PointCloud object
227  * \param[out] polydata the resultant VTK PolyData object
228  * \ingroup io
229  */
230  template <typename PointT> void
232  vtkPolyData* const polydata);
233 
234  /** \brief Convert a PCLPointCloud2 object to a VTK PolyData object.
235  * \param[in] cloud the input PCLPointCloud2Ptr object
236  * \param[out] poly_data the resultant VTK PolyData object
237  * \ingroup io
238  */
239  PCL_EXPORTS void
241 
242  /** \brief Convert a pcl::PointCloud object to a VTK StructuredGrid one.
243  * \param[in] cloud the input pcl::PointCloud object
244  * \param[out] structured_grid the resultant VTK StructuredGrid object
245  * \ingroup io
246  */
247  template <typename PointT> void
249  vtkStructuredGrid* const structured_grid);
250 
251  /** \brief Convert a VTK PolyData object to a pcl::PointCloud one.
252  * \param[in] polydata the input VTK PolyData object
253  * \param[out] cloud the resultant pcl::PointCloud object
254  * \ingroup io
255  */
256  template <typename PointT> void
257  vtkPolyDataToPointCloud (vtkPolyData* const polydata,
258  pcl::PointCloud<PointT>& cloud);
259 
260  /** \brief Convert a VTK StructuredGrid object to a pcl::PointCloud one.
261  * \param[in] structured_grid the input VTK StructuredGrid object
262  * \param[out] cloud the resultant pcl::PointCloud object
263  * \ingroup io
264  */
265  template <typename PointT> void
266  vtkStructuredGridToPointCloud (vtkStructuredGrid* const structured_grid,
267  pcl::PointCloud<PointT>& cloud);
268 
269  }
270 }
271 
272 #include <pcl/io/impl/vtk_lib_io.hpp>
273 
274 #endif /* PLC_IO_VTK_LIB_IO_H_ */
pcl
This file defines compatibility wrappers for low level I/O functions.
Definition: convolution.h:45
point_types.h
pcl::io::pointCloudTovtkPolyData
void pointCloudTovtkPolyData(const pcl::PointCloud< PointT > &cloud, vtkPolyData *const polydata)
Convert a pcl::PointCloud object to a VTK PolyData one.
Definition: vtk_lib_io.hpp:288
pcl::io::loadPolygonFile
PCL_EXPORTS int loadPolygonFile(const std::string &file_name, pcl::PolygonMesh &mesh)
Load a PolygonMesh object given an input file name, based on the file extension.
pcl::io::loadPolygonFileSTL
PCL_EXPORTS int loadPolygonFileSTL(const std::string &file_name, pcl::PolygonMesh &mesh)
Load an STL file into a PolygonMesh object.
pcl::io::loadPolygonFilePLY
PCL_EXPORTS int loadPolygonFilePLY(const std::string &file_name, pcl::PolygonMesh &mesh)
Load a PLY file into a PolygonMesh object.
pcl::PointCloud
PointCloud represents the base class in PCL for storing collections of 3D points.
Definition: projection_matrix.h:53
pcl::io::mesh2vtk
PCL_EXPORTS int mesh2vtk(const pcl::PolygonMesh &mesh, vtkSmartPointer< vtkPolyData > &poly_data)
Convert a PCL PolygonMesh to a vtkPolyData object.
pcl::io::saveRangeImagePlanarFilePNG
PCL_EXPORTS void saveRangeImagePlanarFilePNG(const std::string &file_name, const pcl::RangeImagePlanar &range_image)
Write a RangeImagePlanar object to a PNG file.
pcl::io::loadPolygonFileVTK
PCL_EXPORTS int loadPolygonFileVTK(const std::string &file_name, pcl::PolygonMesh &mesh)
Load a VTK file into a PolygonMesh object.
pcl::io::loadPolygonFileOBJ
PCL_EXPORTS int loadPolygonFileOBJ(const std::string &file_name, pcl::PolygonMesh &mesh)
Load an OBJ file into a PolygonMesh object.
pcl::PolygonMesh
Definition: PolygonMesh.h:15
pcl::io::savePolygonFileSTL
PCL_EXPORTS bool savePolygonFileSTL(const std::string &file_name, const pcl::PolygonMesh &mesh, const bool binary_format=true)
Save a PolygonMesh object into an STL file.
pcl::io::vtkPolyDataToPointCloud
void vtkPolyDataToPointCloud(vtkPolyData *const polydata, pcl::PointCloud< PointT > &cloud)
Convert a VTK PolyData object to a pcl::PointCloud one.
Definition: vtk_lib_io.hpp:73
pcl::io::savePolygonFileVTK
PCL_EXPORTS bool savePolygonFileVTK(const std::string &file_name, const pcl::PolygonMesh &mesh, const bool binary_format=true)
Save a PolygonMesh object into a VTK file.
pcl::io::savePolygonFilePLY
PCL_EXPORTS bool savePolygonFilePLY(const std::string &file_name, const pcl::PolygonMesh &mesh, const bool binary_format=true)
Save a PolygonMesh object into a PLY file.
pcl::io::vtk2mesh
PCL_EXPORTS int vtk2mesh(const vtkSmartPointer< vtkPolyData > &poly_data, pcl::PolygonMesh &mesh)
Convert vtkPolyData object to a PCL PolygonMesh.
pcl::PCLPointCloud2Ptr
boost::shared_ptr< ::pcl::PCLPointCloud2 > PCLPointCloud2Ptr
Definition: PCLPointCloud2.h:55
pcl::io::vtkStructuredGridToPointCloud
void vtkStructuredGridToPointCloud(vtkStructuredGrid *const structured_grid, pcl::PointCloud< PointT > &cloud)
Convert a VTK StructuredGrid object to a pcl::PointCloud one.
Definition: vtk_lib_io.hpp:162
pcl::io::savePolygonFile
PCL_EXPORTS bool savePolygonFile(const std::string &file_name, const pcl::PolygonMesh &mesh, const bool binary_format=true)
Save a PolygonMesh object given an input file name, based on the file extension.
pcl::TextureMesh
Definition: TextureMesh.h:91
pcl::RangeImagePlanar
RangeImagePlanar is derived from the original range image and differs from it because it's not a sphe...
Definition: range_image_planar.h:52
pcl::io::pointCloudTovtkStructuredGrid
void pointCloudTovtkStructuredGrid(const pcl::PointCloud< PointT > &cloud, vtkStructuredGrid *const structured_grid)
Convert a pcl::PointCloud object to a VTK StructuredGrid one.
Definition: vtk_lib_io.hpp:400
vtkSmartPointer< vtkPolyData >