Point Cloud Library (PCL)  1.12.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/obj_io.h>
44 #include <pcl/io/pcd_io.h>
45 #include <pcl/io/ply_io.h>
46 #include <pcl/io/ifs_io.h>
47 #include <boost/filesystem.hpp> // for path
48 
49 namespace pcl
50 {
51  namespace io
52  {
53  template<typename PointT> int
54  load (const std::string& file_name, pcl::PointCloud<PointT>& cloud)
55  {
56  boost::filesystem::path p (file_name.c_str ());
57  std::string extension = p.extension ().string ();
58  int result = -1;
59  if (extension == ".pcd")
60  result = pcl::io::loadPCDFile (file_name, cloud);
61  else if (extension == ".ply")
62  result = pcl::io::loadPLYFile (file_name, cloud);
63  else if (extension == ".ifs")
64  result = pcl::io::loadIFSFile (file_name, cloud);
65  else if (extension == ".obj")
66  result = pcl::io::loadOBJFile (file_name, cloud);
67  else
68  {
69  PCL_ERROR ("[pcl::io::load] Don't know how to handle file with extension %s\n", extension.c_str ());
70  result = -1;
71  }
72  return (result);
73  }
74 
75  template<typename PointT> int
76  save (const std::string& file_name, const pcl::PointCloud<PointT>& cloud)
77  {
78  boost::filesystem::path p (file_name.c_str ());
79  std::string extension = p.extension ().string ();
80  int result = -1;
81  if (extension == ".pcd")
82  result = pcl::io::savePCDFile (file_name, cloud, true);
83  else if (extension == ".ply")
84  result = pcl::io::savePLYFile (file_name, cloud, true);
85  else if (extension == ".ifs")
86  result = pcl::io::saveIFSFile (file_name, cloud);
87  else
88  {
89  PCL_ERROR ("[pcl::io::save] Don't know how to handle file with extension %s\n", extension.c_str ());
90  result = -1;
91  }
92  return (result);
93  }
94  }
95 }
96 
97 #endif //PCL_IO_AUTO_IO_IMPL_H_
PointCloud represents the base class in PCL for storing collections of 3D points.
Definition: point_cloud.h:173
int loadIFSFile(const std::string &file_name, pcl::PCLPointCloud2 &cloud)
Load an IFS file into a PCLPointCloud2 blob type.
Definition: ifs_io.h:190
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:234
PCL_EXPORTS int load(const std::string &file_name, pcl::PCLPointCloud2 &blob)
Load a file into a PointCloud2 according to extension.
int loadOBJFile(const std::string &file_name, pcl::PCLPointCloud2 &cloud, Eigen::Vector4f &origin, Eigen::Quaternionf &orientation)
Load any OBJ file into a templated PointCloud type.
Definition: obj_io.h:261
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:672
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.
int loadPLYFile(const std::string &file_name, pcl::PCLPointCloud2 &cloud)
Load a PLY v.6 file into a PCLPointCloud2 type.
Definition: ply_io.h:751
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:812
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:621