1 /*
2 * Software License Agreement (BSD License)
3 *
4 * Point Cloud Library (PCL) - www.pointclouds.org
5 * Copyright (c) 2013-, Open Perception, 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 the copyright holder(s) 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 */
37
38 #include <pcl/io/auto_io.h>
39 #include <pcl/io/pcd_io.h>
40 #include <pcl/io/ply_io.h>
41 #include <pcl/io/ifs_io.h>
42 #include <pcl/io/obj_io.h>
43 #include <pcl/io/vtk_io.h>
44
45
46 int
load(const std::string & file_name,pcl::PCLPointCloud2 & blob)47 pcl::io::load (const std::string& file_name, pcl::PCLPointCloud2& blob)
48 {
49 boost::filesystem::path p (file_name.c_str ());
50 std::string extension = p.extension ().string ();
51 int result = -1;
52 if (extension == ".pcd")
53 result = pcl::io::loadPCDFile (file_name, blob);
54 else if (extension == ".ply")
55 result = pcl::io::loadPLYFile (file_name, blob);
56 else if (extension == ".ifs")
57 result = pcl::io::loadIFSFile (file_name, blob);
58 else if (extension == ".obj")
59 result = pcl::io::loadOBJFile (file_name, blob);
60 else
61 {
62 PCL_ERROR ("[pcl::io::load] Don't know how to handle file with extension %s\n", extension.c_str ());
63 result = -1;
64 }
65 return (result);
66 }
67
68 int
load(const std::string & file_name,pcl::PolygonMesh & mesh)69 pcl::io::load (const std::string& file_name, pcl::PolygonMesh& mesh)
70 {
71 boost::filesystem::path p (file_name.c_str ());
72 std::string extension = p.extension ().string ();
73 int result = -1;
74 if (extension == ".ply")
75 result = pcl::io::loadPLYFile (file_name, mesh);
76 else if (extension == ".ifs")
77 result = pcl::io::loadIFSFile (file_name, mesh);
78 else if (extension == ".obj")
79 result = pcl::io::loadOBJFile (file_name, mesh);
80 else
81 {
82 PCL_ERROR ("[pcl::io::load] Don't know how to handle file with extension %s\n", extension.c_str ());
83 result = -1;
84 }
85 return (result);
86 }
87
88 int
load(const std::string & file_name,pcl::TextureMesh & mesh)89 pcl::io::load (const std::string& file_name, pcl::TextureMesh& mesh)
90 {
91 boost::filesystem::path p (file_name.c_str ());
92 std::string extension = p.extension ().string ();
93 int result = -1;
94 if (extension == ".obj")
95 result = pcl::io::loadOBJFile (file_name, mesh);
96 else
97 {
98 PCL_ERROR ("[pcl::io::load] Don't know how to handle file with extension %s\n", extension.c_str ());
99 result = -1;
100 }
101 return (result);
102 }
103
104 int
save(const std::string & file_name,const pcl::PCLPointCloud2 & blob,unsigned precision)105 pcl::io::save (const std::string& file_name, const pcl::PCLPointCloud2& blob, unsigned precision)
106 {
107 boost::filesystem::path p (file_name.c_str ());
108 std::string extension = p.extension ().string ();
109 int result = -1;
110 if (extension == ".pcd")
111 {
112 Eigen::Vector4f origin = Eigen::Vector4f::Zero ();
113 Eigen::Quaternionf orientation = Eigen::Quaternionf::Identity ();
114 result = pcl::io::savePCDFile (file_name, blob, origin, orientation, true);
115 }
116 else if (extension == ".ply")
117 {
118 Eigen::Vector4f origin = Eigen::Vector4f::Zero ();
119 Eigen::Quaternionf orientation = Eigen::Quaternionf::Identity ();
120 result = pcl::io::savePLYFile (file_name, blob, origin, orientation, true);
121 }
122 else if (extension == ".ifs")
123 result = pcl::io::saveIFSFile (file_name, blob);
124 else if (extension == ".vtk")
125 result = pcl::io::saveVTKFile (file_name, blob, precision);
126 else
127 {
128 PCL_ERROR ("[pcl::io::save] Don't know how to handle file with extension %s\n", extension.c_str ());
129 result = -1;
130 }
131 return (result);
132 }
133
134 int
save(const std::string & file_name,const pcl::TextureMesh & tex_mesh,unsigned precision)135 pcl::io::save (const std::string &file_name, const pcl::TextureMesh &tex_mesh, unsigned precision)
136 {
137 boost::filesystem::path p (file_name.c_str ());
138 std::string extension = p.extension ().string ();
139 int result = -1;
140 if (extension == ".obj")
141 result = pcl::io::saveOBJFile (file_name, tex_mesh, precision);
142 else
143 {
144 PCL_ERROR ("[pcl::io::save] Don't know how to handle file with extension %s\n", extension.c_str ());
145 result = -1;
146 }
147 return (result);
148 }
149
150 int
save(const std::string & file_name,const pcl::PolygonMesh & poly_mesh,unsigned precision)151 pcl::io::save (const std::string &file_name, const pcl::PolygonMesh &poly_mesh, unsigned precision)
152 {
153 boost::filesystem::path p (file_name.c_str ());
154 std::string extension = p.extension ().string ();
155 int result = -1;
156 if (extension == ".ply")
157 result = pcl::io::savePLYFileBinary (file_name, poly_mesh);
158 else if (extension == ".obj")
159 result = pcl::io::saveOBJFile (file_name, poly_mesh, precision);
160 else if (extension == ".vtk")
161 result = pcl::io::saveVTKFile (file_name, poly_mesh, precision);
162 else
163 {
164 PCL_ERROR ("[pcl::io::save] Don't know how to handle file with extension %s\n", extension.c_str ());
165 result = -1;
166 }
167 return (result);
168 }
169