Point Cloud Library (PCL)  1.7.2
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  * \ingroup io
123  */
124  PCL_EXPORTS int
125  savePolygonFile (const std::string &file_name,
126  const pcl::PolygonMesh& mesh);
127 
128  /** \brief Load a VTK file into a \ref PolygonMesh object
129  * \param[in] file_name the name of the file that contains the data
130  * \param[out] mesh the object that we want to load the data in
131  * \ingroup io
132  */
133  PCL_EXPORTS int
134  loadPolygonFileVTK (const std::string &file_name,
135  pcl::PolygonMesh& mesh);
136 
137  /** \brief Load a PLY file into a \ref PolygonMesh object
138  * \param[in] file_name the name of the file that contains the data
139  * \param[out] mesh the object that we want to load the data in
140  * \ingroup io
141  */
142  PCL_EXPORTS int
143  loadPolygonFilePLY (const std::string &file_name,
144  pcl::PolygonMesh& mesh);
145 
146  /** \brief Load an OBJ file into a \ref PolygonMesh object
147  * \param[in] file_name the name of the file that contains the data
148  * \param[out] mesh the object that we want to load the data in
149  * \ingroup io
150  */
151  PCL_EXPORTS int
152  loadPolygonFileOBJ (const std::string &file_name,
153  pcl::PolygonMesh& mesh);
154 
155  /** \brief Load an OBJ file into a \ref TextureMesh object.
156  * \note In addition to the loadPolygonFileOBJ (const std::string, pcl::PolygonMesh&)
157  * method, this method also loads the uv-coordinates from the file. It does not
158  * load the material information.
159  * \param[in] file_name the name of the file that contains the data
160  * \param[out] mesh the object that we want to load the data in
161  * \ingroup io
162  */
163  PCL_EXPORTS int
164  loadPolygonFileOBJ (const std::string &file_name,
165  pcl::TextureMesh& mesh);
166 
167 
168  /** \brief Load an STL file into a \ref PolygonMesh object
169  * \param[in] file_name the name of the file that contains the data
170  * \param[out] mesh the object that we want to load the data in
171  * \ingroup io
172  */
173  PCL_EXPORTS int
174  loadPolygonFileSTL (const std::string &file_name,
175  pcl::PolygonMesh& mesh);
176 
177  /** \brief Save a \ref PolygonMesh object into a VTK file
178  * \param[in] file_name the name of the file to save the data to
179  * \param[in] mesh the object that contains the data
180  * \ingroup io
181  */
182  PCL_EXPORTS int
183  savePolygonFileVTK (const std::string &file_name,
184  const pcl::PolygonMesh& mesh);
185 
186  /** \brief Save a \ref PolygonMesh object into a PLY file
187  * \param[in] file_name the name of the file to save the data to
188  * \param[in] mesh the object that contains the data
189  * \ingroup io
190  */
191  PCL_EXPORTS int
192  savePolygonFilePLY (const std::string &file_name,
193  const pcl::PolygonMesh& mesh);
194 
195  /** \brief Save a \ref PolygonMesh object into an STL file
196  * \param[in] file_name the name of the file to save the data to
197  * \param[in] mesh the object that contains the data
198  * \ingroup io
199  */
200  PCL_EXPORTS int
201  savePolygonFileSTL (const std::string &file_name,
202  const pcl::PolygonMesh& mesh);
203 
204  /** \brief Write a \ref RangeImagePlanar object to a PNG file
205  * \param[in] file_name the name of the file to save the data to
206  * \param[in] range_image the object that contains the data
207  * \ingroup io
208  */
209  PCL_EXPORTS void
210  saveRangeImagePlanarFilePNG (const std::string &file_name,
211  const pcl::RangeImagePlanar& range_image);
212 
213  /** \brief Convert a pcl::PointCloud object to a VTK PolyData one.
214  * \param[in] cloud the input pcl::PointCloud object
215  * \param[out] polydata the resultant VTK PolyData object
216  * \ingroup io
217  */
218  template <typename PointT> void
220  vtkPolyData* const polydata);
221 
222  /** \brief Convert a PCLPointCloud2 object to a VTK PolyData object.
223  * \param[in] cloud the input PCLPointCloud2Ptr object
224  * \param[out] poly_data the resultant VTK PolyData object
225  * \ingroup io
226  */
227  PCL_EXPORTS void
229 
230  /** \brief Convert a pcl::PointCloud object to a VTK StructuredGrid one.
231  * \param[in] cloud the input pcl::PointCloud object
232  * \param[out] structured_grid the resultant VTK StructuredGrid object
233  * \ingroup io
234  */
235  template <typename PointT> void
237  vtkStructuredGrid* const structured_grid);
238 
239  /** \brief Convert a VTK PolyData object to a pcl::PointCloud one.
240  * \param[in] polydata the input VTK PolyData object
241  * \param[out] cloud the resultant pcl::PointCloud object
242  * \ingroup io
243  */
244  template <typename PointT> void
245  vtkPolyDataToPointCloud (vtkPolyData* const polydata,
246  pcl::PointCloud<PointT>& cloud);
247 
248  /** \brief Convert a VTK StructuredGrid object to a pcl::PointCloud one.
249  * \param[in] structured_grid the input VTK StructuredGrid object
250  * \param[out] cloud the resultant pcl::PointCloud object
251  * \ingroup io
252  */
253  template <typename PointT> void
254  vtkStructuredGridToPointCloud (vtkStructuredGrid* const structured_grid,
255  pcl::PointCloud<PointT>& cloud);
256 
257  }
258 }
259 
260 #include <pcl/io/impl/vtk_lib_io.hpp>
261 
262 #endif /* PLC_IO_VTK_LIB_IO_H_ */
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_EXPORTS int loadPolygonFileSTL(const std::string &file_name, pcl::PolygonMesh &mesh)
Load an STL file into a PolygonMesh object.
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:281
PCL_EXPORTS void saveRangeImagePlanarFilePNG(const std::string &file_name, const pcl::RangeImagePlanar &range_image)
Write a RangeImagePlanar object to a PNG file.
PCL_EXPORTS int loadPolygonFilePLY(const std::string &file_name, pcl::PolygonMesh &mesh)
Load a PLY file into a PolygonMesh object.
PCL_EXPORTS int savePolygonFile(const std::string &file_name, const pcl::PolygonMesh &mesh)
Save a PolygonMesh object given an input file name, based on the file extension.
void vtkPolyDataToPointCloud(vtkPolyData *const polydata, pcl::PointCloud< PointT > &cloud)
Convert a VTK PolyData object to a pcl::PointCloud one.
Definition: vtk_lib_io.hpp:66
PCL_EXPORTS int loadPolygonFileVTK(const std::string &file_name, pcl::PolygonMesh &mesh)
Load a VTK file into a PolygonMesh object.
PCL_EXPORTS int savePolygonFileSTL(const std::string &file_name, const pcl::PolygonMesh &mesh)
Save a PolygonMesh object into an STL file.
PCL_EXPORTS int loadPolygonFileOBJ(const std::string &file_name, pcl::PolygonMesh &mesh)
Load an OBJ file into a PolygonMesh object.
PCL_EXPORTS int savePolygonFilePLY(const std::string &file_name, const pcl::PolygonMesh &mesh)
Save a PolygonMesh object into a PLY file.
boost::shared_ptr< ::pcl::PCLPointCloud2 > PCLPointCloud2Ptr
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:155
PCL_EXPORTS int mesh2vtk(const pcl::PolygonMesh &mesh, vtkSmartPointer< vtkPolyData > &poly_data)
Convert a PCL PolygonMesh to a vtkPolyData object.
PCL_EXPORTS int savePolygonFileVTK(const std::string &file_name, const pcl::PolygonMesh &mesh)
Save a PolygonMesh object into a VTK file.
PCL_EXPORTS int vtk2mesh(const vtkSmartPointer< vtkPolyData > &poly_data, pcl::PolygonMesh &mesh)
Convert vtkPolyData object to a PCL PolygonMesh.
RangeImagePlanar is derived from the original range image and differs from it because it&#39;s not a sphe...
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:393