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