Point Cloud Library (PCL)  1.10.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 #pragma once
42 
43 #include <pcl/point_types.h>
44 #include <pcl/point_cloud.h>
45 #include <pcl/PolygonMesh.h>
46 #include <pcl/TextureMesh.h>
47 #include <pcl/pcl_macros.h>
48 #include <pcl/conversions.h>
49 #include <pcl/io/pcd_io.h>
50 #include <pcl/range_image/range_image_planar.h>
51 
52 // Ignore warnings in the above headers
53 #ifdef __GNUC__
54 #pragma GCC system_header
55 #endif
56 #include <vtkVersion.h>
57 #include <vtkSmartPointer.h>
58 #include <vtkStructuredGrid.h>
59 #include <vtkPoints.h>
60 #include <vtkPointData.h>
61 #include <vtkCellArray.h>
62 #include <vtkUnsignedCharArray.h>
63 #include <vtkFloatArray.h>
64 #include <vtkPolyDataReader.h>
65 #include <vtkPolyDataWriter.h>
66 #include <vtkPLYReader.h>
67 #include <vtkPLYWriter.h>
68 #include <vtkOBJReader.h>
69 #include <vtkSTLReader.h>
70 #include <vtkSTLWriter.h>
71 #include <vtkPNGReader.h>
72 #include <vtkImageData.h>
73 #include <vtkPolyDataNormals.h>
74 
75 namespace pcl
76 {
77  namespace io
78  {
79  /** \brief Convert vtkPolyData object to a PCL PolygonMesh
80  * \param[in] poly_data Pointer (vtkSmartPointer) to a vtkPolyData object
81  * \param[out] mesh PCL Polygon Mesh to fill
82  * \return Number of points in the point cloud of mesh.
83  */
84  PCL_EXPORTS int
85  vtk2mesh (const vtkSmartPointer<vtkPolyData>& poly_data,
86  pcl::PolygonMesh& mesh);
87 
88  /** \brief Convert vtkPolyData object to a PCL TextureMesh
89  * \note In addition to the vtk2mesh (const vtkSmartPointer<vtkPolyData>&, pcl::PolygonMesh&)
90  * method, it fills the mesh with the uv-coordinates.
91  * \param[in] poly_data Pointer (vtkSmartPointer) to a vtkPolyData object
92  * \param[out] mesh PCL TextureMesh to fill
93  * \return Number of points in the point cloud of mesh.
94  */
95  PCL_EXPORTS int
96  vtk2mesh (const vtkSmartPointer<vtkPolyData>& poly_data,
97  pcl::TextureMesh& mesh);
98 
99 
100  /** \brief Convert a PCL PolygonMesh to a vtkPolyData object
101  * \param[in] mesh Reference to PCL Polygon Mesh
102  * \param[out] poly_data Pointer (vtkSmartPointer) to a vtkPolyData object
103  * \return Number of points in the point cloud of mesh.
104  */
105  PCL_EXPORTS int
106  mesh2vtk (const pcl::PolygonMesh& mesh,
107  vtkSmartPointer<vtkPolyData>& poly_data);
108 
109  /** \brief Load a \ref PolygonMesh object given an input file name, based on the file extension
110  * \param[in] file_name the name of the file containing the polygon data
111  * \param[out] mesh the object that we want to load the data in
112  * \ingroup io
113  */
114  PCL_EXPORTS int
115  loadPolygonFile (const std::string &file_name,
116  pcl::PolygonMesh& mesh);
117 
118  /** \brief Save a \ref PolygonMesh object given an input file name, based on the file extension
119  * \param[in] file_name the name of the file to save the data to
120  * \param[in] mesh the object that contains the data
121  * \param[in] binary_format if true, exported file is in binary format
122  * \return True if successful, false otherwise
123  * \ingroup io
124  */
125  PCL_EXPORTS bool
126  savePolygonFile (const std::string &file_name,
127  const pcl::PolygonMesh& mesh,
128  const bool binary_format = true);
129 
130  /** \brief Load a VTK file into a \ref PolygonMesh object
131  * \param[in] file_name the name of the file that contains the data
132  * \param[out] mesh the object that we want to load the data in
133  * \ingroup io
134  */
135  PCL_EXPORTS int
136  loadPolygonFileVTK (const std::string &file_name,
137  pcl::PolygonMesh& mesh);
138 
139  /** \brief Load a PLY file into a \ref PolygonMesh object
140  * \param[in] file_name the name of the file that contains the data
141  * \param[out] mesh the object that we want to load the data in
142  * \ingroup io
143  */
144  PCL_EXPORTS int
145  loadPolygonFilePLY (const std::string &file_name,
146  pcl::PolygonMesh& mesh);
147 
148  /** \brief Load an OBJ file into a \ref PolygonMesh object
149  * \param[in] file_name the name of the file that contains the data
150  * \param[out] mesh the object that we want to load the data in
151  * \ingroup io
152  */
153  PCL_EXPORTS int
154  loadPolygonFileOBJ (const std::string &file_name,
155  pcl::PolygonMesh& mesh);
156 
157  /** \brief Load an OBJ file into a \ref TextureMesh object.
158  * \note In addition to the loadPolygonFileOBJ (const std::string, pcl::PolygonMesh&)
159  * method, this method also loads the uv-coordinates from the file. It does not
160  * load the material information.
161  * \param[in] file_name the name of the file that contains the data
162  * \param[out] mesh the object that we want to load the data in
163  * \ingroup io
164  */
165  PCL_EXPORTS int
166  loadPolygonFileOBJ (const std::string &file_name,
167  pcl::TextureMesh& mesh);
168 
169 
170  /** \brief Load an STL file into a \ref PolygonMesh object
171  * \param[in] file_name the name of the file that contains the data
172  * \param[out] mesh the object that we want to load the data in
173  * \ingroup io
174  */
175  PCL_EXPORTS int
176  loadPolygonFileSTL (const std::string &file_name,
177  pcl::PolygonMesh& mesh);
178 
179  /** \brief Save a \ref PolygonMesh object into a VTK file
180  * \param[in] file_name the name of the file to save the data to
181  * \param[in] mesh the object that contains the data
182  * \param[in] binary_format if true, exported file is in binary format
183  * \return True if successful, false otherwise
184  * \ingroup io
185  */
186  PCL_EXPORTS bool
187  savePolygonFileVTK (const std::string &file_name,
188  const pcl::PolygonMesh& mesh,
189  const bool binary_format = true);
190 
191  /** \brief Save a \ref PolygonMesh object into a PLY file
192  * \param[in] file_name the name of the file to save the data to
193  * \param[in] mesh the object that contains the data
194  * \param[in] binary_format if true, exported file is in binary format
195  * \return True if successful, false otherwise
196  * \ingroup io
197  */
198  PCL_EXPORTS bool
199  savePolygonFilePLY (const std::string &file_name,
200  const pcl::PolygonMesh& mesh,
201  const bool binary_format = true);
202 
203  /** \brief Save a \ref PolygonMesh object into an STL file
204  * \param[in] file_name the name of the file to save the data to
205  * \param[in] mesh the object that contains the data
206  * \param[in] binary_format if true, exported file is in binary format
207  * \return True if successful, false otherwise
208  * \ingroup io
209  */
210  PCL_EXPORTS bool
211  savePolygonFileSTL (const std::string &file_name,
212  const pcl::PolygonMesh& mesh,
213  const bool binary_format = true);
214 
215  /** \brief Write a \ref RangeImagePlanar object to a PNG file
216  * \param[in] file_name the name of the file to save the data to
217  * \param[in] range_image the object that contains the data
218  * \ingroup io
219  */
220  PCL_EXPORTS void
221  saveRangeImagePlanarFilePNG (const std::string &file_name,
222  const pcl::RangeImagePlanar& range_image);
223 
224  /** \brief Convert a pcl::PointCloud object to a VTK PolyData one.
225  * \param[in] cloud the input pcl::PointCloud object
226  * \param[out] polydata the resultant VTK PolyData object
227  * \ingroup io
228  */
229  template <typename PointT> void
231  vtkPolyData* const polydata);
232 
233  /** \brief Convert a PCLPointCloud2 object to a VTK PolyData object.
234  * \param[in] cloud the input PCLPointCloud2Ptr object
235  * \param[out] poly_data the resultant VTK PolyData object
236  * \ingroup io
237  */
238  PCL_EXPORTS void
240 
241  /** \brief Convert a pcl::PointCloud object to a VTK StructuredGrid one.
242  * \param[in] cloud the input pcl::PointCloud object
243  * \param[out] structured_grid the resultant VTK StructuredGrid object
244  * \ingroup io
245  */
246  template <typename PointT> void
248  vtkStructuredGrid* const structured_grid);
249 
250  /** \brief Convert a VTK PolyData object to a pcl::PointCloud one.
251  * \param[in] polydata the input VTK PolyData object
252  * \param[out] cloud the resultant pcl::PointCloud object
253  * \ingroup io
254  */
255  template <typename PointT> void
256  vtkPolyDataToPointCloud (vtkPolyData* const polydata,
257  pcl::PointCloud<PointT>& cloud);
258 
259  /** \brief Convert a VTK StructuredGrid object to a pcl::PointCloud one.
260  * \param[in] structured_grid the input VTK StructuredGrid object
261  * \param[out] cloud the resultant pcl::PointCloud object
262  * \ingroup io
263  */
264  template <typename PointT> void
265  vtkStructuredGridToPointCloud (vtkStructuredGrid* const structured_grid,
266  pcl::PointCloud<PointT>& cloud);
267 
268  }
269 }
270 
271 #include <pcl/io/impl/vtk_lib_io.hpp>
pcl_macros.h
Defines all the PCL and non-PCL macros used.
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:52
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::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::PCLPointCloud2Ptr
PCLPointCloud2::Ptr PCLPointCloud2Ptr
Definition: PCLPointCloud2.h:88
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:88
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:51
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:396
PCL_EXPORTS
#define PCL_EXPORTS
Definition: pcl_macros.h:271
vtkSmartPointer< vtkPolyData >