Skip to content

Commit 68a85e8

Browse files
committed
Merge pull request #1294 from SergioRAgostinho/io_load_template
Fix to pcl::io::load and pcl::io::save
2 parents c993e57 + 9a18eed commit 68a85e8

File tree

6 files changed

+394
-245
lines changed

6 files changed

+394
-245
lines changed

io/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ if(build)
213213
src/hdl_grabber.cpp
214214
src/robot_eye_grabber.cpp
215215
src/file_io.cpp
216+
src/auto_io.cpp
216217
src/io_exception.cpp
217218
${VTK_IO_SOURCE}
218219
${OPENNI_GRABBER_SOURCES}
@@ -242,6 +243,7 @@ if(build)
242243
"include/pcl/${SUBSYS_NAME}/eigen.h"
243244
"include/pcl/${SUBSYS_NAME}/debayer.h"
244245
"include/pcl/${SUBSYS_NAME}/file_io.h"
246+
"include/pcl/${SUBSYS_NAME}/auto_io.h"
245247
"include/pcl/${SUBSYS_NAME}/lzf.h"
246248
"include/pcl/${SUBSYS_NAME}/lzf_image_io.h"
247249
"include/pcl/${SUBSYS_NAME}/io.h"
@@ -293,6 +295,7 @@ if(build)
293295

294296
set(impl_incs
295297
"include/pcl/${SUBSYS_NAME}/impl/pcd_io.hpp"
298+
"include/pcl/${SUBSYS_NAME}/impl/auto_io.hpp"
296299
"include/pcl/${SUBSYS_NAME}/impl/lzf_image_io.hpp"
297300
"include/pcl/${SUBSYS_NAME}/impl/synchronized_queue.hpp"
298301
"include/pcl/${SUBSYS_NAME}/impl/point_cloud_image_extractors.hpp"

io/include/pcl/io/auto_io.h

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
/*
2+
* Software License Agreement (BSD License)
3+
*
4+
* Copyright (c) 2009, Willow Garage, Inc.
5+
* All rights reserved.
6+
*
7+
* Redistribution and use in source and binary forms, with or without
8+
* modification, are permitted provided that the following conditions
9+
* are met:
10+
*
11+
* * Redistributions of source code must retain the above copyright
12+
* notice, this list of conditions and the following disclaimer.
13+
* * Redistributions in binary form must reproduce the above
14+
* copyright notice, this list of conditions and the following
15+
* disclaimer in the documentation and/or other materials provided
16+
* with the distribution.
17+
* * Neither the name of the copyright holder(s) nor the names of its
18+
* contributors may be used to endorse or promote products derived
19+
* from this software without specific prior written permission.
20+
*
21+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24+
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25+
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26+
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27+
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28+
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31+
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32+
* POSSIBILITY OF SUCH DAMAGE.
33+
*
34+
* $Id$
35+
*
36+
*/
37+
38+
#ifndef PCL_IO_AUTO_IO_H_
39+
#define PCL_IO_AUTO_IO_H_
40+
41+
#include <pcl/pcl_macros.h>
42+
#include <pcl/common/io.h>
43+
#include <pcl/io/boost.h>
44+
#include <cmath>
45+
#include <sstream>
46+
#include <pcl/PolygonMesh.h>
47+
#include <pcl/TextureMesh.h>
48+
49+
namespace pcl
50+
{
51+
52+
namespace io
53+
{
54+
/** \brief Load a file into a PointCloud2 according to extension.
55+
* \param[in] file_name the name of the file to load
56+
* \param[out] blob the resultant pcl::PointCloud2 blob
57+
* \ingroup io
58+
*/
59+
PCL_EXPORTS int
60+
load (const std::string& file_name, pcl::PCLPointCloud2& blob);
61+
62+
/** \brief Load a file into a template PointCloud type according to extension.
63+
* \param[in] file_name the name of the file to load
64+
* \param[out] cloud the resultant templated point cloud
65+
* \ingroup io
66+
*/
67+
template<typename PointT> int
68+
load (const std::string& file_name, pcl::PointCloud<PointT>& cloud);
69+
70+
/** \brief Load a file into a PolygonMesh according to extension.
71+
* \param[in] file_name the name of the file to load
72+
* \param[out] mesh the resultant pcl::PolygonMesh
73+
* \ingroup io
74+
*/
75+
PCL_EXPORTS int
76+
load (const std::string& file_name, pcl::PolygonMesh& mesh);
77+
78+
/** \brief Load a file into a TextureMesh according to extension.
79+
* \param[in] file_name the name of the file to load
80+
* \param[out] mesh the resultant pcl::TextureMesh
81+
* \ingroup io
82+
*/
83+
PCL_EXPORTS int
84+
load (const std::string& file_name, pcl::TextureMesh& mesh);
85+
86+
/** \brief Save point cloud data to a binary file when available else to ASCII.
87+
* \param[in] file_name the output file name
88+
* \param[in] blob the point cloud data message
89+
* \param[in] precision float precision when saving to ASCII files
90+
* \ingroup io
91+
*/
92+
PCL_EXPORTS int
93+
save (const std::string& file_name, const pcl::PCLPointCloud2& blob, unsigned precision = 5);
94+
95+
/** \brief Save point cloud to a binary file when available else to ASCII.
96+
* \param[in] file_name the output file name
97+
* \param[in] cloud the point cloud
98+
* \param[in] precision float precision when saving to ASCII files
99+
* \ingroup io
100+
*/
101+
template<typename PointT> int
102+
save (const std::string& file_name, const pcl::PointCloud<PointT>& cloud, unsigned precision = 5);
103+
104+
/** \brief Saves a TextureMesh to a binary file when available else to ASCII.
105+
* \param[in] file_name the name of the file to write to disk
106+
* \param[in] tex_mesh the texture mesh to save
107+
* \param[in] precision float precision when saving to ASCII files
108+
* \ingroup io
109+
*/
110+
PCL_EXPORTS int
111+
save (const std::string &file_name, const pcl::TextureMesh &tex_mesh, unsigned precision = 5);
112+
113+
/** \brief Saves a PolygonMesh to a binary file when available else to ASCII.
114+
* \param[in] file_name the name of the file to write to disk
115+
* \param[in] mesh the polygonal mesh to save
116+
* \param[in] precision float precision when saving to ASCII files
117+
* \ingroup io
118+
*/
119+
PCL_EXPORTS int
120+
save (const std::string &file_name, const pcl::PolygonMesh &mesh, unsigned precision = 5);
121+
}
122+
}
123+
124+
#include <pcl/io/impl/auto_io.hpp>
125+
126+
#endif //#ifndef PCL_IO_AUTO_IO_H_

io/include/pcl/io/file_io.h

Lines changed: 0 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -390,76 +390,6 @@ namespace pcl
390390
fields_count * sizeof (uint8_t)], reinterpret_cast<char*> (&value), sizeof (uint8_t));
391391
}
392392

393-
namespace io
394-
{
395-
/** \brief Load a file into a PointCloud2 according to extension.
396-
* \param[in] file_name the name of the file to load
397-
* \param[out] blob the resultant pcl::PointCloud2 blob
398-
* \ingroup io
399-
*/
400-
PCL_EXPORTS int
401-
load (const std::string& file_name, pcl::PCLPointCloud2& blob);
402-
403-
/** \brief Load a file into a template PointCloud type according to extension.
404-
* \param[in] file_name the name of the file to load
405-
* \param[out] cloud the resultant templated point cloud
406-
* \ingroup io
407-
*/
408-
template<typename PointT> int
409-
load (const std::string& file_name, pcl::PointCloud<PointT>& cloud);
410-
411-
/** \brief Load a file into a PolygonMesh according to extension.
412-
* \param[in] file_name the name of the file to load
413-
* \param[out] mesh the resultant pcl::PolygonMesh
414-
* \ingroup io
415-
*/
416-
PCL_EXPORTS int
417-
load (const std::string& file_name, pcl::PolygonMesh& mesh);
418-
419-
/** \brief Load a file into a TextureMesh according to extension.
420-
* \param[in] file_name the name of the file to load
421-
* \param[out] mesh the resultant pcl::TextureMesh
422-
* \ingroup io
423-
*/
424-
PCL_EXPORTS int
425-
load (const std::string& file_name, pcl::TextureMesh& mesh);
426-
427-
/** \brief Save point cloud data to a binary file when available else to ASCII.
428-
* \param[in] file_name the output file name
429-
* \param[in] blob the point cloud data message
430-
* \param[in] precision float precision when saving to ASCII files
431-
* \ingroup io
432-
*/
433-
PCL_EXPORTS int
434-
save (const std::string& file_name, const pcl::PCLPointCloud2& blob, unsigned precision = 5);
435-
436-
/** \brief Save point cloud to a binary file when available else to ASCII.
437-
* \param[in] file_name the output file name
438-
* \param[in] cloud the point cloud
439-
* \param[in] precision float precision when saving to ASCII files
440-
* \ingroup io
441-
*/
442-
template<typename PointT> int
443-
save (const std::string& file_name, const pcl::PointCloud<PointT>& cloud, unsigned precision = 5);
444-
445-
/** \brief Saves a TextureMesh to a binary file when available else to ASCII.
446-
* \param[in] file_name the name of the file to write to disk
447-
* \param[in] tex_mesh the texture mesh to save
448-
* \param[in] precision float precision when saving to ASCII files
449-
* \ingroup io
450-
*/
451-
PCL_EXPORTS int
452-
save (const std::string &file_name, const pcl::TextureMesh &tex_mesh, unsigned precision = 5);
453-
454-
/** \brief Saves a PolygonMesh to a binary file when available else to ASCII.
455-
* \param[in] file_name the name of the file to write to disk
456-
* \param[in] mesh the polygonal mesh to save
457-
* \param[in] precision float precision when saving to ASCII files
458-
* \ingroup io
459-
*/
460-
PCL_EXPORTS int
461-
save (const std::string &file_name, const pcl::PolygonMesh &mesh, unsigned precision = 5);
462-
}
463393
}
464394

465395
#endif //#ifndef PCL_IO_FILE_IO_H_

io/include/pcl/io/impl/auto_io.hpp

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
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_

0 commit comments

Comments
 (0)