Point Cloud Library (PCL)  1.14.0-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/common/pcl_filesystem.h>
44 
45 #include <pcl/io/obj_io.h>
46 #include <pcl/io/pcd_io.h>
47 #include <pcl/io/ply_io.h>
48 #include <pcl/io/ifs_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  pcl_fs::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 if (extension == ".obj")
67  result = pcl::io::loadOBJFile (file_name, cloud);
68  else
69  {
70  PCL_ERROR ("[pcl::io::load] Don't know how to handle file with extension %s\n", extension.c_str ());
71  result = -1;
72  }
73  return (result);
74  }
75 
76  template<typename PointT> int
77  save (const std::string& file_name, const pcl::PointCloud<PointT>& cloud)
78  {
79  pcl_fs::path p (file_name.c_str ());
80  std::string extension = p.extension ().string ();
81  int result = -1;
82  if (extension == ".pcd")
83  result = pcl::io::savePCDFile (file_name, cloud, true);
84  else if (extension == ".ply")
85  result = pcl::io::savePLYFile (file_name, cloud, true);
86  else if (extension == ".ifs")
87  result = pcl::io::saveIFSFile (file_name, cloud);
88  else
89  {
90  PCL_ERROR ("[pcl::io::save] Don't know how to handle file with extension %s\n", extension.c_str ());
91  result = -1;
92  }
93  return (result);
94  }
95  }
96 }
97 
98 #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:684
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:745
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:806
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:633