Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add: support IFS file format #354

Merged
merged 1 commit into from
Nov 8, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions io/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ if(build)
src/lzf.cpp
src/lzf_image_io.cpp
src/obj_io.cpp
src/ifs_io.cpp
src/image_grabber.cpp
src/hdl_grabber.cpp
src/robot_eye_grabber.cpp
Expand Down Expand Up @@ -168,6 +169,7 @@ if(build)
include/pcl/${SUBSYS_NAME}/tar.h
include/pcl/${SUBSYS_NAME}/obj_io.h
include/pcl/${SUBSYS_NAME}/ascii_io.h
include/pcl/${SUBSYS_NAME}/ifs_io.h
include/pcl/${SUBSYS_NAME}/image_grabber.h
include/pcl/${SUBSYS_NAME}/hdl_grabber.h
include/pcl/${SUBSYS_NAME}/robot_eye_grabber.h
Expand Down
1 change: 1 addition & 0 deletions io/include/pcl/io/boost.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
#if BOOST_VERSION >= 104900
#include <boost/interprocess/permissions.hpp>
#endif
#include <boost/iostreams/device/mapped_file.hpp>
#define BOOST_PARAMETER_MAX_ARITY 7
#include <boost/signals2.hpp>
#include <boost/signals2/slot.hpp>
Expand Down
226 changes: 226 additions & 0 deletions io/include/pcl/io/ifs_io.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,226 @@
/*
* Software License Agreement (BSD License)
*
* Point Cloud Library (PCL) - www.pointclouds.org
* Copyright (c) 2013, Open Perception, Inc.
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of the copyright holder(s) nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
*/

#ifndef PCL_IO_IFS_IO_H_
#define PCL_IO_IFS_IO_H_

#include <pcl/point_cloud.h>
#include <pcl/PCLPointCloud2.h>
#include <pcl/conversions.h>
#include <pcl/io/boost.h>

namespace pcl
{
/** \brief Indexed Face set (IFS) file format reader. This file format is used for
* the Brown Mesh Set for instance.
* \author Nizar Sallem
* \ingroup io
*/
class PCL_EXPORTS IFSReader
{
public:
/** Empty constructor */
IFSReader () {}
/** Empty destructor */
~IFSReader () {}

/** \brief we support two versions
* 1.0 classic
* 1.1 with texture coordinates addon
*/
enum
{
IFS_V1_0 = 0,
IFS_V1_1 = 1
};

/** \brief Read a point cloud data header from a IFS file.
*
* Load only the meta information (number of points, their types, etc),
* and not the points themselves, from a given IFS file. Useful for fast
* evaluation of the underlying data structure.
*
* \param[in] file_name the name of the file to load
* \param[out] cloud the resultant point cloud dataset (only header will be filled)
* \param[out] ifs_version the IFS version of the file (IFS_V1_0 or IFS_V1_1)
* \param[out] data_idx the offset of cloud data within the file
*
* \return
* * < 0 (-1) on error
* * == 0 on success
*/
int
readHeader (const std::string &file_name, pcl::PCLPointCloud2 &cloud,
int &ifs_version, unsigned int &data_idx);

/** \brief Read a point cloud data from a IFS file and store it into a pcl/PCLPointCloud2.
* \param[in] file_name the name of the file containing the actual PointCloud data
* \param[out] cloud the resultant PointCloud message read from disk
* \param[out] ifs_version the IFS version of the file (either IFS_V6 or IFS_V7)
*
* \return
* * < 0 (-1) on error
* * == 0 on success
*/
int
read (const std::string &file_name, pcl::PCLPointCloud2 &cloud, int &ifs_version);

/** \brief Read a point cloud data from any IFS file, and convert it to the
* given template format.
* \param[in] file_name the name of the file containing the actual PointCloud data
* \param[out] cloud the resultant PointCloud message read from disk
*
* \return
* * < 0 (-1) on error
* * == 0 on success
*/
template<typename PointT> int
read (const std::string &file_name, pcl::PointCloud<PointT> &cloud)
{
pcl::PCLPointCloud2 blob;
int ifs_version;
cloud.sensor_origin_ = Eigen::Vector4f::Zero ();
cloud.sensor_orientation_ = Eigen::Quaternionf::Identity ();
int res = read (file_name, blob, ifs_version);

// If no error, convert the data
if (res == 0)
pcl::fromPCLPointCloud2 (blob, cloud);
return (res);
}
};

/** \brief Point Cloud Data (IFS) file format writer.
* \author Nizar Sallem
* \ingroup io
*/
class PCL_EXPORTS IFSWriter
{
public:
IFSWriter() {}
~IFSWriter() {}

/** \brief Save point cloud data to a IFS file containing n-D points
* \param[in] file_name the output file name
* \param[in] cloud the point cloud data message
* \param[in] cloud_name the point cloud name to be stored insude the IFS file.
* \return
* * 0 on success
* * < 0 on error
*/
int
write (const std::string &file_name, const pcl::PCLPointCloud2 &cloud,
const std::string &cloud_name = "cloud");

/** \brief Save point cloud data to a IFS file containing n-D points
* \param[in] file_name the output file name
* \param[in] cloud the point cloud
* \param[in] cloud_name the point cloud name to be stored insude the IFS file.
* \return
* * 0 on success
* * < 0 on error
*/
template<typename PointT> int
write (const std::string &file_name, const pcl::PointCloud<PointT> &cloud,
const std::string &cloud_name = "cloud")
{
pcl::PCLPointCloud2 blob;
pcl::fromPCLPointCloud2<PointT> (blob, cloud);
return (write (file_name, blob, cloud_name));
}
};

namespace io
{
/** \brief Load a IFS v.6 file into a templated PointCloud type.
*
* Any IFS files > v.6 will generate a warning as a
* pcl/PCLPointCloud2 message cannot hold the sensor origin.
*
* \param[in] file_name the name of the file to load
* \param[out] cloud the resultant templated point cloud
* \ingroup io
*/
inline int
loadIFSFile (const std::string &file_name, pcl::PCLPointCloud2 &cloud)
{
pcl::IFSReader p;
int ifs_version;
return (p.read (file_name, cloud, ifs_version));
}

/** \brief Load any IFS file into a templated PointCloud type
* \param[in] file_name the name of the file to load
* \param[out] cloud the resultant templated point cloud
* \ingroup io
*/
template<typename PointT> inline int
loadIFSFile (const std::string &file_name, pcl::PointCloud<PointT> &cloud)
{
pcl::IFSReader p;
return (p.read<PointT> (file_name, cloud));
}

/** \brief Save point cloud data to a IFS file containing n-D points
* \param[in] file_name the output file name
* \param[in] cloud the point cloud data message
*
* \ingroup io
*/
inline int
saveIFSFile (const std::string &file_name, const pcl::PCLPointCloud2 &cloud)
{
pcl::IFSWriter w;
return (w.write (file_name, cloud));
}

/** \brief Save point cloud data to a IFS file containing n-D points
* \param[in] file_name the output file name
* \param[in] cloud the point cloud
*
* \ingroup io
*/
template<typename PointT> int
saveIFSFile (const std::string &file_name, const pcl::PointCloud<PointT> &cloud)
{
pcl::IFSWriter w;
return (w.write<PointT> (file_name, cloud));
}
}
}

#endif //#ifndef PCL_IO_IFS_IO_H_
Loading