Point Cloud Library (PCL)  1.9.1-dev
auto_io.hpp
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2010-2011, Willow Garage, Inc.
6  *
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * * Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  * * Redistributions in binary form must reproduce the above
16  * copyright notice, this list of conditions and the following
17  * disclaimer in the documentation and/or other materials provided
18  * with the distribution.
19  * * Neither the name of Willow Garage, Inc. nor the names of its
20  * contributors may be used to endorse or promote products derived
21  * from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  * POSSIBILITY OF SUCH DAMAGE.
35  *
36  * $Id$
37  *
38  */
39 
40 #ifndef PCL_IO_AUTO_IO_IMPL_H_
41 #define PCL_IO_AUTO_IO_IMPL_H_
42 
43 // #include <pcl/io/file_io.h>
44 // #include <pcl/io/boost.h>
45 #include <pcl/io/pcd_io.h>
46 #include <pcl/io/ply_io.h>
47 #include <pcl/io/ifs_io.h>
48 // #include <pcl/io/vtk_io.h>
49 
50 namespace pcl
51 {
52  namespace io
53  {
54  template<typename PointT> int
55  load (const std::string& file_name, pcl::PointCloud<PointT>& cloud)
56  {
57  boost::filesystem::path p (file_name.c_str ());
58  std::string extension = p.extension ().string ();
59  int result = -1;
60  if (extension == ".pcd")
61  result = pcl::io::loadPCDFile (file_name, cloud);
62  else if (extension == ".ply")
63  result = pcl::io::loadPLYFile (file_name, cloud);
64  else if (extension == ".ifs")
65  result = pcl::io::loadIFSFile (file_name, cloud);
66  else
67  {
68  PCL_ERROR ("[pcl::io::load] Don't know how to handle file with extension %s", extension.c_str ());
69  result = -1;
70  }
71  return (result);
72  }
73 
74  template<typename PointT> int
75  save (const std::string& file_name, const pcl::PointCloud<PointT>& cloud)
76  {
77  boost::filesystem::path p (file_name.c_str ());
78  std::string extension = p.extension ().string ();
79  int result = -1;
80  if (extension == ".pcd")
81  result = pcl::io::savePCDFile (file_name, cloud, true);
82  else if (extension == ".ply")
83  result = pcl::io::savePLYFile (file_name, cloud, true);
84  else if (extension == ".ifs")
85  result = pcl::io::saveIFSFile (file_name, cloud);
86  else
87  {
88  PCL_ERROR ("[pcl::io::save] Don't know how to handle file with extension %s", extension.c_str ());
89  result = -1;
90  }
91  return (result);
92  }
93  }
94 }
95 
96 #endif //PCL_IO_AUTO_IO_IMPL_H_
int loadIFSFile(const std::string &file_name, pcl::PCLPointCloud2 &cloud)
Load an IFS file into a PCLPointCloud2 blob type.
Definition: ifs_io.h:191
PCL_EXPORTS int load(const std::string &file_name, pcl::PCLPointCloud2 &blob)
Load a file into a PointCloud2 according to extension.
This file defines compatibility wrappers for low level I/O functions.
Definition: convolution.h:44
int savePLYFile(const std::string &file_name, const pcl::PCLPointCloud2 &cloud, const Eigen::Vector4f &origin=Eigen::Vector4f::Zero(), const Eigen::Quaternionf &orientation=Eigen::Quaternionf::Identity(), bool binary_mode=false, bool use_camera=true)
Save point cloud data to a PLY file containing n-D points.
Definition: ply_io.h:809
int savePCDFile(const std::string &file_name, const pcl::PCLPointCloud2 &cloud, const Eigen::Vector4f &origin=Eigen::Vector4f::Zero(), const Eigen::Quaternionf &orientation=Eigen::Quaternionf::Identity(), const bool binary_mode=false)
Save point cloud data to a PCD file containing n-D points.
Definition: pcd_io.h:673
int loadPLYFile(const std::string &file_name, pcl::PCLPointCloud2 &cloud)
Load a PLY v.6 file into a templated PointCloud type.
Definition: ply_io.h:748
PointCloud represents the base class in PCL for storing collections of 3D points. ...
int loadPCDFile(const std::string &file_name, pcl::PCLPointCloud2 &cloud)
Load a PCD v.6 file into a templated PointCloud type.
Definition: pcd_io.h:622
int saveIFSFile(const std::string &file_name, const pcl::PCLPointCloud2 &cloud)
Save point cloud data to an IFS file containing 3D points.
Definition: ifs_io.h:235
PCL_EXPORTS int save(const std::string &file_name, const pcl::PCLPointCloud2 &blob, unsigned precision=5)
Save point cloud data to a binary file when available else to ASCII.