Point Cloud Library (PCL) 1.12.0
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/pcd_io.h>
44#include <pcl/io/ply_io.h>
45#include <pcl/io/ifs_io.h>
46#include <boost/filesystem.hpp> // for path
47
48namespace pcl
49{
50 namespace io
51 {
52 template<typename PointT> int
53 load (const std::string& file_name, pcl::PointCloud<PointT>& cloud)
54 {
55 boost::filesystem::path p (file_name.c_str ());
56 std::string extension = p.extension ().string ();
57 int result = -1;
58 if (extension == ".pcd")
59 result = pcl::io::loadPCDFile (file_name, cloud);
60 else if (extension == ".ply")
61 result = pcl::io::loadPLYFile (file_name, cloud);
62 else if (extension == ".ifs")
63 result = pcl::io::loadIFSFile (file_name, cloud);
64 else
65 {
66 PCL_ERROR ("[pcl::io::load] Don't know how to handle file with extension %s\n", extension.c_str ());
67 result = -1;
68 }
69 return (result);
70 }
71
72 template<typename PointT> int
73 save (const std::string& file_name, const pcl::PointCloud<PointT>& cloud)
74 {
75 boost::filesystem::path p (file_name.c_str ());
76 std::string extension = p.extension ().string ();
77 int result = -1;
78 if (extension == ".pcd")
79 result = pcl::io::savePCDFile (file_name, cloud, true);
80 else if (extension == ".ply")
81 result = pcl::io::savePLYFile (file_name, cloud, true);
82 else if (extension == ".ifs")
83 result = pcl::io::saveIFSFile (file_name, cloud);
84 else
85 {
86 PCL_ERROR ("[pcl::io::save] Don't know how to handle file with extension %s\n", extension.c_str ());
87 result = -1;
88 }
89 return (result);
90 }
91 }
92}
93
94#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 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 templated PointCloud type.
Definition: ply_io.h:749
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:810
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