Skip to content

Commit

Permalink
Merge pull request #1986 from mattgruenke/master
Browse files Browse the repository at this point in the history
Adds in-memory PCD serialization/deserialization; de-duplicates PCDReader::readHeader().
  • Loading branch information
SergioRAgostinho authored Sep 22, 2017
2 parents fa9b816 + e8d92d6 commit 660601a
Show file tree
Hide file tree
Showing 4 changed files with 549 additions and 580 deletions.
2 changes: 2 additions & 0 deletions io/include/pcl/io/impl/pcd_io.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,13 @@
# define pcl_open _open
# define pcl_close(fd) _close(fd)
# define pcl_lseek(fd,offset,origin) _lseek(fd,offset,origin)
# define pcl_read(fd,dest,size) _read(fd,dest,size)
#else
# include <sys/mman.h>
# define pcl_open open
# define pcl_close(fd) close(fd)
# define pcl_lseek(fd,offset,origin) lseek(fd,offset,origin)
# define pcl_read(fd,dest,size) ::read(fd,dest,size)
#endif

#include <pcl/io/lzf.h>
Expand Down
103 changes: 101 additions & 2 deletions io/include/pcl/io/pcd_io.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,34 @@ namespace pcl
PCD_V7 = 1
};

/** \brief Read a point cloud data header from a PCD-formatted, binary istream.
*
* Load only the meta information (number of points, their types, etc),
* and not the points themselves, from a given PCD stream. Useful for fast
* evaluation of the underlying data structure.
*
* \attention The PCD data is \b always stored in ROW major format! The
* read/write PCD methods will detect column major input and automatically convert it.
*
* \param[in] binary_istream a std::istream with openmode set to std::ios::binary.
* \param[out] cloud the resultant point cloud dataset (only these
* members will be filled: width, height, point_step,
* row_step, fields[]; data is resized but not written)
* \param[out] origin the sensor acquisition origin (only for > PCD_V7 - null if not present)
* \param[out] orientation the sensor acquisition orientation (only for > PCD_V7 - identity if not present)
* \param[out] pcd_version the PCD version of the file (i.e., PCD_V6, PCD_V7)
* \param[out] data_type the type of data (0 = ASCII, 1 = Binary, 2 = Binary compressed)
* \param[out] data_idx the offset of cloud data within the file
*
* \return
* * < 0 (-1) on error
* * == 0 on success
*/
int
readHeader (std::istream &binary_istream, pcl::PCLPointCloud2 &cloud,
Eigen::Vector4f &origin, Eigen::Quaternionf &orientation, int &pcd_version,
int &data_type, unsigned int &data_idx);

/** \brief Read a point cloud data header from a PCD file.
*
* Load only the meta information (number of points, their types, etc),
Expand All @@ -94,7 +122,9 @@ namespace pcl
* read/write PCD methods will detect column major input and automatically convert it.
*
* \param[in] file_name the name of the file to load
* \param[out] cloud the resultant point cloud dataset (only the header will be filled)
* \param[out] cloud the resultant point cloud dataset (only these
* members will be filled: width, height, point_step,
* row_step, fields[]; data is resized but not written)
* \param[out] origin the sensor acquisition origin (only for > PCD_V7 - null if not present)
* \param[out] orientation the sensor acquisition orientation (only for > PCD_V7 - identity if not present)
* \param[out] pcd_version the PCD version of the file (i.e., PCD_V6, PCD_V7)
Expand Down Expand Up @@ -127,7 +157,9 @@ namespace pcl
* read/write PCD methods will detect column major input and automatically convert it.
*
* \param[in] file_name the name of the file to load
* \param[out] cloud the resultant point cloud dataset (only the header will be filled)
* \param[out] cloud the resultant point cloud dataset (only these
* members will be filled: width, height, point_step,
* row_step, fields[]; data is resized but not written)
* \param[in] offset the offset of where to expect the PCD Header in the
* file (optional parameter). One usage example for setting the offset
* parameter is for reading data from a TAR "archive containing multiple
Expand All @@ -142,6 +174,45 @@ namespace pcl
int
readHeader (const std::string &file_name, pcl::PCLPointCloud2 &cloud, const int offset = 0);

/** \brief Read the point cloud data (body) from a PCD stream.
*
* Reads the cloud points from a text-formatted stream. For use after
* readHeader(), when the resulting data_type == 0.
*
* \attention This assumes the stream has been seeked to the position
* indicated by the data_idx result of readHeader().
*
* \param[in] stream the stream from which to read the body.
* \param[out] cloud the resultant point cloud dataset to be filled.
* \param[in] pcd_version the PCD version of the stream (from readHeader()).
*
* \return
* * < 0 (-1) on error
* * == 0 on success
*/
int
readBodyASCII (std::istream &stream, pcl::PCLPointCloud2 &cloud, int pcd_version);

/** \brief Read the point cloud data (body) from a block of memory.
*
* Reads the cloud points from a binary-formatted memory block. For use
* after readHeader(), when the resulting data_type is nonzero.
*
* \param[in] data the memory location from which to read the body.
* \param[out] cloud the resultant point cloud dataset to be filled.
* \param[in] pcd_version the PCD version of the stream (from readHeader()).
* \param[in] compressed indicates whether the PCD block contains compressed
* data. This should be true if the data_type returne by readHeader() == 2.
* \param[in] data_idx the offset of the body, as reported by readHeader().
*
* \return
* * < 0 (-1) on error
* * == 0 on success
*/
int
readBodyBinary (const unsigned char *data, pcl::PCLPointCloud2 &cloud,
int pcd_version, bool compressed, unsigned int data_idx);

/** \brief Read a point cloud data from a PCD 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
Expand Down Expand Up @@ -252,6 +323,23 @@ namespace pcl
const Eigen::Quaternionf &orientation);

/** \brief Generate the header of a BINARY_COMPRESSED PCD file format
* \param[out] os the stream into which to write the header
* \param[in] cloud the point cloud data message
* \param[in] origin the sensor acquisition origin
* \param[in] orientation the sensor acquisition orientation
*
* \return
* * < 0 (-1) on error
* * == 0 on success
*/
int
generateHeaderBinaryCompressed (std::ostream &os,
const pcl::PCLPointCloud2 &cloud,
const Eigen::Vector4f &origin,
const Eigen::Quaternionf &orientation);

/** \brief Generate the header of a BINARY_COMPRESSED PCD file format
* \param[out] os the stream into which to write the header
* \param[in] cloud the point cloud data message
* \param[in] origin the sensor acquisition origin
* \param[in] orientation the sensor acquisition orientation
Expand Down Expand Up @@ -324,6 +412,17 @@ namespace pcl
const Eigen::Vector4f &origin = Eigen::Vector4f::Zero (),
const Eigen::Quaternionf &orientation = Eigen::Quaternionf::Identity ());

/** \brief Save point cloud data to a std::ostream containing n-D points, in BINARY_COMPRESSED format
* \param[out] os the stream into which to write the data
* \param[in] cloud the point cloud data message
* \param[in] origin the sensor acquisition origin
* \param[in] orientation the sensor acquisition orientation
*/
int
writeBinaryCompressed (std::ostream &os, const pcl::PCLPointCloud2 &cloud,
const Eigen::Vector4f &origin = Eigen::Vector4f::Zero (),
const Eigen::Quaternionf &orientation = Eigen::Quaternionf::Identity ());

/** \brief Save point cloud data to a PCD file containing n-D points
* \param[in] file_name the output file name
* \param[in] cloud the point cloud data message
Expand Down
Loading

0 comments on commit 660601a

Please sign in to comment.