Point Cloud Library (PCL)  1.14.1-dev
List of all members | Public Member Functions | Static Public Member Functions | Protected Member Functions
pcl::PCDWriter Class Reference

Point Cloud Data (PCD) file format writer. More...

#include <pcl/io/pcd_io.h>

+ Inheritance diagram for pcl::PCDWriter:
+ Collaboration diagram for pcl::PCDWriter:

Public Member Functions

 PCDWriter ()=default
 
 ~PCDWriter () override=default
 
void setMapSynchronization (bool sync)
 Set whether mmap() synchornization via msync() is desired before munmap() calls. More...
 
std::string generateHeaderBinary (const pcl::PCLPointCloud2 &cloud, const Eigen::Vector4f &origin, const Eigen::Quaternionf &orientation)
 Generate the header of a PCD file format. More...
 
int generateHeaderBinaryCompressed (std::ostream &os, const pcl::PCLPointCloud2 &cloud, const Eigen::Vector4f &origin, const Eigen::Quaternionf &orientation)
 Generate the header of a BINARY_COMPRESSED PCD file format. More...
 
std::string generateHeaderBinaryCompressed (const pcl::PCLPointCloud2 &cloud, const Eigen::Vector4f &origin, const Eigen::Quaternionf &orientation)
 Generate the header of a BINARY_COMPRESSED PCD file format. More...
 
std::string generateHeaderASCII (const pcl::PCLPointCloud2 &cloud, const Eigen::Vector4f &origin, const Eigen::Quaternionf &orientation)
 Generate the header of a PCD file format. More...
 
int writeASCII (const std::string &file_name, const pcl::PCLPointCloud2 &cloud, const Eigen::Vector4f &origin=Eigen::Vector4f::Zero(), const Eigen::Quaternionf &orientation=Eigen::Quaternionf::Identity(), const int precision=8)
 Save point cloud data to a PCD file containing n-D points, in ASCII format. More...
 
int writeBinary (const std::string &file_name, const pcl::PCLPointCloud2 &cloud, const Eigen::Vector4f &origin=Eigen::Vector4f::Zero(), const Eigen::Quaternionf &orientation=Eigen::Quaternionf::Identity())
 Save point cloud data to a PCD file containing n-D points, in BINARY format. More...
 
int writeBinary (std::ostream &os, const pcl::PCLPointCloud2 &cloud, const Eigen::Vector4f &origin=Eigen::Vector4f::Zero(), const Eigen::Quaternionf &orientation=Eigen::Quaternionf::Identity())
 Save point cloud data to a std::ostream containing n-D points, in BINARY format. More...
 
int writeBinaryCompressed (const std::string &file_name, const pcl::PCLPointCloud2 &cloud, const Eigen::Vector4f &origin=Eigen::Vector4f::Zero(), const Eigen::Quaternionf &orientation=Eigen::Quaternionf::Identity())
 Save point cloud data to a PCD file containing n-D points, in BINARY_COMPRESSED format. More...
 
int writeBinaryCompressed (std::ostream &os, const pcl::PCLPointCloud2 &cloud, const Eigen::Vector4f &origin=Eigen::Vector4f::Zero(), const Eigen::Quaternionf &orientation=Eigen::Quaternionf::Identity())
 Save point cloud data to a std::ostream containing n-D points, in BINARY_COMPRESSED format. More...
 
int write (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=false) override
 Save point cloud data to a PCD file containing n-D points. More...
 
int write (const std::string &file_name, const pcl::PCLPointCloud2::ConstPtr &cloud, const Eigen::Vector4f &origin=Eigen::Vector4f::Zero(), const Eigen::Quaternionf &orientation=Eigen::Quaternionf::Identity(), const bool binary=false)
 Save point cloud data to a PCD file containing n-D points. More...
 
template<typename PointT >
int writeBinary (const std::string &file_name, const pcl::PointCloud< PointT > &cloud)
 Save point cloud data to a PCD file containing n-D points, in BINARY format. More...
 
template<typename PointT >
int writeBinaryCompressed (const std::string &file_name, const pcl::PointCloud< PointT > &cloud)
 Save point cloud data to a binary comprssed PCD file. More...
 
template<typename PointT >
int writeBinary (const std::string &file_name, const pcl::PointCloud< PointT > &cloud, const pcl::Indices &indices)
 Save point cloud data to a PCD file containing n-D points, in BINARY format. More...
 
template<typename PointT >
int writeASCII (const std::string &file_name, const pcl::PointCloud< PointT > &cloud, const int precision=8)
 Save point cloud data to a PCD file containing n-D points, in ASCII format. More...
 
template<typename PointT >
int writeASCII (const std::string &file_name, const pcl::PointCloud< PointT > &cloud, const pcl::Indices &indices, const int precision=8)
 Save point cloud data to a PCD file containing n-D points, in ASCII format. More...
 
template<typename PointT >
int write (const std::string &file_name, const pcl::PointCloud< PointT > &cloud, const bool binary=false)
 Save point cloud data to a PCD file containing n-D points. More...
 
template<typename PointT >
int write (const std::string &file_name, const pcl::PointCloud< PointT > &cloud, const pcl::Indices &indices, bool binary=false)
 Save point cloud data to a PCD file containing n-D points. More...
 
- Public Member Functions inherited from pcl::FileWriter
 FileWriter ()=default
 Empty constructor. More...
 
virtual ~FileWriter ()=default
 Empty destructor. More...
 
int write (const std::string &file_name, const pcl::PCLPointCloud2::ConstPtr &cloud, const Eigen::Vector4f &origin=Eigen::Vector4f::Zero(), const Eigen::Quaternionf &orientation=Eigen::Quaternionf::Identity(), const bool binary=false)
 Save point cloud data to a FILE file containing n-D points. More...
 
template<typename PointT >
int write (const std::string &file_name, const pcl::PointCloud< PointT > &cloud, const bool binary=false)
 Save point cloud data to a FILE file containing n-D points. More...
 

Static Public Member Functions

template<typename PointT >
static std::string generateHeader (const pcl::PointCloud< PointT > &cloud, const int nr_points=std::numeric_limits< int >::max())
 Generate the header of a PCD file format. More...
 

Protected Member Functions

void setLockingPermissions (const std::string &file_name, boost::interprocess::file_lock &lock)
 Set permissions for file locking (Boost 1.49+). More...
 
void resetLockingPermissions (const std::string &file_name, boost::interprocess::file_lock &lock)
 Reset permissions for file locking (Boost 1.49+). More...
 

Detailed Description

Point Cloud Data (PCD) file format writer.

Author
Radu Bogdan Rusu

Definition at line 298 of file pcd_io.h.

Constructor & Destructor Documentation

◆ PCDWriter()

pcl::PCDWriter::PCDWriter ( )
default

◆ ~PCDWriter()

pcl::PCDWriter::~PCDWriter ( )
overridedefault

Member Function Documentation

◆ generateHeader()

template<typename PointT >
std::string pcl::PCDWriter::generateHeader ( const pcl::PointCloud< PointT > &  cloud,
const int  nr_points = std::numeric_limits<int>::max () 
)
static

Generate the header of a PCD file format.

Parameters
[in]cloudthe point cloud data message
[in]nr_pointsif given, use this to fill in WIDTH, HEIGHT (=1), and POINTS in the header By default, nr_points is set to INTMAX, and the data in the header is used instead.

Definition at line 57 of file pcd_io.hpp.

References pcl::getFieldSize(), pcl::getFieldType(), pcl::PointCloud< PointT >::height, pcl::PointCloud< PointT >::sensor_orientation_, pcl::PointCloud< PointT >::sensor_origin_, pcl::PointCloud< PointT >::size(), and pcl::PointCloud< PointT >::width.

◆ generateHeaderASCII()

std::string pcl::PCDWriter::generateHeaderASCII ( const pcl::PCLPointCloud2 cloud,
const Eigen::Vector4f &  origin,
const Eigen::Quaternionf &  orientation 
)

Generate the header of a PCD file format.

Parameters
[in]cloudthe point cloud data message
[in]originthe sensor acquisition origin
[in]orientationthe sensor acquisition orientation

◆ generateHeaderBinary()

std::string pcl::PCDWriter::generateHeaderBinary ( const pcl::PCLPointCloud2 cloud,
const Eigen::Vector4f &  origin,
const Eigen::Quaternionf &  orientation 
)

Generate the header of a PCD file format.

Parameters
[in]cloudthe point cloud data message
[in]originthe sensor acquisition origin
[in]orientationthe sensor acquisition orientation

◆ generateHeaderBinaryCompressed() [1/2]

std::string pcl::PCDWriter::generateHeaderBinaryCompressed ( const pcl::PCLPointCloud2 cloud,
const Eigen::Vector4f &  origin,
const Eigen::Quaternionf &  orientation 
)

Generate the header of a BINARY_COMPRESSED PCD file format.

Parameters
[in]cloudthe point cloud data message
[in]originthe sensor acquisition origin
[in]orientationthe sensor acquisition orientation

◆ generateHeaderBinaryCompressed() [2/2]

int pcl::PCDWriter::generateHeaderBinaryCompressed ( std::ostream &  os,
const pcl::PCLPointCloud2 cloud,
const Eigen::Vector4f &  origin,
const Eigen::Quaternionf &  orientation 
)

Generate the header of a BINARY_COMPRESSED PCD file format.

Parameters
[out]osthe stream into which to write the header
[in]cloudthe point cloud data message
[in]originthe sensor acquisition origin
[in]orientationthe sensor acquisition orientation
Returns
  • < 0 (-1) on error
  • == 0 on success

◆ resetLockingPermissions()

void pcl::PCDWriter::resetLockingPermissions ( const std::string &  file_name,
boost::interprocess::file_lock &  lock 
)
protected

Reset permissions for file locking (Boost 1.49+).

Parameters
[in]file_namethe file name to reset permission for file locking
[in,out]lockthe file lock

◆ setLockingPermissions()

void pcl::PCDWriter::setLockingPermissions ( const std::string &  file_name,
boost::interprocess::file_lock &  lock 
)
protected

Set permissions for file locking (Boost 1.49+).

Parameters
[in]file_namethe file name to set permission for file locking
[in,out]lockthe file lock

◆ setMapSynchronization()

void pcl::PCDWriter::setMapSynchronization ( bool  sync)
inline

Set whether mmap() synchornization via msync() is desired before munmap() calls.

Setting this to true could prevent NFS data loss (see http://www.pcl-developers.org/PCD-IO-consistency-on-NFS-msync-needed-td4885942.html). Default: false

Note
This option should be used by advanced users only!
Please note that using msync() on certain systems can reduce the I/O performance by up to 80%!
Parameters
[in]syncset to true if msync() should be called before munmap()

Definition at line 313 of file pcd_io.h.

◆ write() [1/4]

int pcl::PCDWriter::write ( 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 = false 
)
inlineoverridevirtual

Save point cloud data to a PCD file containing n-D points.

Parameters
[in]file_namethe output file name
[in]cloudthe point cloud data message
[in]originthe sensor acquisition origin
[in]orientationthe sensor acquisition orientation
[in]binaryset to true if the file is to be written in a binary PCD format, false (default) for ASCII

Caution: PointCloud structures containing an RGB field have traditionally used packed float values to store RGB data. Storing a float as ASCII can introduce variations to the smallest bits, and thus significantly alter the data. This is a known issue, and the fix involves switching RGB data to be stored as a packed integer in future versions of PCL.

As an intermediary solution, precision 8 is used, which guarantees lossless storage for RGB.

Implements pcl::FileWriter.

Definition at line 465 of file pcd_io.h.

Referenced by pcl::io::savePCDFile(), pcl::io::savePCDFileASCII(), and pcl::io::savePCDFileBinary().

◆ write() [2/4]

int pcl::PCDWriter::write ( const std::string &  file_name,
const pcl::PCLPointCloud2::ConstPtr cloud,
const Eigen::Vector4f &  origin = Eigen::Vector4f::Zero (),
const Eigen::Quaternionf &  orientation = Eigen::Quaternionf::Identity (),
const bool  binary = false 
)
inline

Save point cloud data to a PCD file containing n-D points.

Parameters
[in]file_namethe output file name
[in]cloudthe point cloud data message (boost shared pointer)
[in]binaryset to true if the file is to be written in a binary PCD format, false (default) for ASCII
[in]originthe sensor acquisition origin
[in]orientationthe sensor acquisition orientation

Caution: PointCloud structures containing an RGB field have traditionally used packed float values to store RGB data. Storing a float as ASCII can introduce variations to the smallest bits, and thus significantly alter the data. This is a known issue, and the fix involves switching RGB data to be stored as a packed integer in future versions of PCL.

Definition at line 491 of file pcd_io.h.

References pcl::write().

◆ write() [3/4]

template<typename PointT >
int pcl::PCDWriter::write ( const std::string &  file_name,
const pcl::PointCloud< PointT > &  cloud,
const bool  binary = false 
)
inline

Save point cloud data to a PCD file containing n-D points.

Parameters
[in]file_namethe output file name
[in]cloudthe pcl::PointCloud data
[in]binaryset to true if the file is to be written in a binary PCD format, false (default) for ASCII

Caution: PointCloud structures containing an RGB field have traditionally used packed float values to store RGB data. Storing a float as ASCII can introduce variations to the smallest bits, and thus significantly alter the data. This is a known issue, and the fix involves switching RGB data to be stored as a packed integer in future versions of PCL.

Definition at line 565 of file pcd_io.h.

◆ write() [4/4]

template<typename PointT >
int pcl::PCDWriter::write ( const std::string &  file_name,
const pcl::PointCloud< PointT > &  cloud,
const pcl::Indices indices,
bool  binary = false 
)
inline

Save point cloud data to a PCD file containing n-D points.

Parameters
[in]file_namethe output file name
[in]cloudthe pcl::PointCloud data
[in]indicesthe set of point indices that we want written to disk
[in]binaryset to true if the file is to be written in a binary PCD format, false (default) for ASCII

Caution: PointCloud structures containing an RGB field have traditionally used packed float values to store RGB data. Storing a float as ASCII can introduce variations to the smallest bits, and thus significantly alter the data. This is a known issue, and the fix involves switching RGB data to be stored as a packed integer in future versions of PCL.

Definition at line 589 of file pcd_io.h.

◆ writeASCII() [1/3]

int pcl::PCDWriter::writeASCII ( const std::string &  file_name,
const pcl::PCLPointCloud2 cloud,
const Eigen::Vector4f &  origin = Eigen::Vector4f::Zero(),
const Eigen::Quaternionf &  orientation = Eigen::Quaternionf::Identity(),
const int  precision = 8 
)

Save point cloud data to a PCD file containing n-D points, in ASCII format.

Parameters
[in]file_namethe output file name
[in]cloudthe point cloud data message
[in]originthe sensor acquisition origin
[in]orientationthe sensor acquisition orientation
[in]precisionthe specified output numeric stream precision (default: 8)

Caution: PointCloud structures containing an RGB field have traditionally used packed float values to store RGB data. Storing a float as ASCII can introduce variations to the smallest bits, and thus significantly alter the data. This is a known issue, and the fix involves switching RGB data to be stored as a packed integer in future versions of PCL.

As an intermediary solution, precision 8 is used, which guarantees lossless storage for RGB.

◆ writeASCII() [2/3]

template<typename PointT >
int pcl::PCDWriter::writeASCII ( const std::string &  file_name,
const pcl::PointCloud< PointT > &  cloud,
const int  precision = 8 
)

Save point cloud data to a PCD file containing n-D points, in ASCII format.

Parameters
[in]file_namethe output file name
[in]cloudthe point cloud data message
[in]precisionthe specified output numeric stream precision (default: 8)

Definition at line 439 of file pcd_io.hpp.

References pcl::PCLPointField::BOOL, pcl::PointCloud< PointT >::empty(), pcl::PCLPointField::FLOAT32, pcl::PCLPointField::FLOAT64, pcl::PointCloud< PointT >::height, pcl::PCLPointField::INT16, pcl::PCLPointField::INT32, pcl::PCLPointField::INT64, pcl::PCLPointField::INT8, pcl::PointCloud< PointT >::size(), pcl::PCLPointField::UINT16, pcl::PCLPointField::UINT32, pcl::PCLPointField::UINT64, pcl::PCLPointField::UINT8, and pcl::PointCloud< PointT >::width.

◆ writeASCII() [3/3]

template<typename PointT >
int pcl::PCDWriter::writeASCII ( const std::string &  file_name,
const pcl::PointCloud< PointT > &  cloud,
const pcl::Indices indices,
const int  precision = 8 
)

Save point cloud data to a PCD file containing n-D points, in ASCII format.

Parameters
[in]file_namethe output file name
[in]cloudthe point cloud data message
[in]indicesthe set of point indices that we want written to disk
[in]precisionthe specified output numeric stream precision (default: 8)

Definition at line 733 of file pcd_io.hpp.

References pcl::PCLPointField::BOOL, pcl::PointCloud< PointT >::empty(), pcl::PCLPointField::FLOAT32, pcl::PCLPointField::FLOAT64, pcl::PointCloud< PointT >::height, pcl::PCLPointField::INT16, pcl::PCLPointField::INT32, pcl::PCLPointField::INT64, pcl::PCLPointField::INT8, pcl::PointCloud< PointT >::points, pcl::PointCloud< PointT >::size(), pcl::PCLPointField::UINT16, pcl::PCLPointField::UINT32, pcl::PCLPointField::UINT64, pcl::PCLPointField::UINT8, and pcl::PointCloud< PointT >::width.

◆ writeBinary() [1/4]

int pcl::PCDWriter::writeBinary ( const std::string &  file_name,
const pcl::PCLPointCloud2 cloud,
const Eigen::Vector4f &  origin = Eigen::Vector4f::Zero(),
const Eigen::Quaternionf &  orientation = Eigen::Quaternionf::Identity() 
)

Save point cloud data to a PCD file containing n-D points, in BINARY format.

Parameters
[in]file_namethe output file name
[in]cloudthe point cloud data message
[in]originthe sensor acquisition origin
[in]orientationthe sensor acquisition orientation

◆ writeBinary() [2/4]

template<typename PointT >
int pcl::PCDWriter::writeBinary ( const std::string &  file_name,
const pcl::PointCloud< PointT > &  cloud 
)

Save point cloud data to a PCD file containing n-D points, in BINARY format.

Parameters
[in]file_namethe output file name
[in]cloudthe point cloud data message

Definition at line 111 of file pcd_io.hpp.

References pcl::PointCloud< PointT >::empty(), pcl::getFieldSize(), pcl::io::raw_close(), pcl::io::raw_fallocate(), pcl::io::raw_open(), and pcl::PointCloud< PointT >::size().

◆ writeBinary() [3/4]

template<typename PointT >
int pcl::PCDWriter::writeBinary ( const std::string &  file_name,
const pcl::PointCloud< PointT > &  cloud,
const pcl::Indices indices 
)

Save point cloud data to a PCD file containing n-D points, in BINARY format.

Parameters
[in]file_namethe output file name
[in]cloudthe point cloud data message
[in]indicesthe set of point indices that we want written to disk

Definition at line 610 of file pcd_io.hpp.

References pcl::PointCloud< PointT >::empty(), pcl::getFieldSize(), pcl::io::raw_close(), pcl::io::raw_fallocate(), and pcl::io::raw_open().

◆ writeBinary() [4/4]

int pcl::PCDWriter::writeBinary ( std::ostream &  os,
const pcl::PCLPointCloud2 cloud,
const Eigen::Vector4f &  origin = Eigen::Vector4f::Zero(),
const Eigen::Quaternionf &  orientation = Eigen::Quaternionf::Identity() 
)

Save point cloud data to a std::ostream containing n-D points, in BINARY format.

Parameters
[out]osthe stream into which to write the data
[in]cloudthe point cloud data message
[in]originthe sensor acquisition origin
[in]orientationthe sensor acquisition orientation

◆ writeBinaryCompressed() [1/3]

int pcl::PCDWriter::writeBinaryCompressed ( const std::string &  file_name,
const pcl::PCLPointCloud2 cloud,
const Eigen::Vector4f &  origin = Eigen::Vector4f::Zero(),
const Eigen::Quaternionf &  orientation = Eigen::Quaternionf::Identity() 
)

Save point cloud data to a PCD file containing n-D points, in BINARY_COMPRESSED format.

Parameters
[in]file_namethe output file name
[in]cloudthe point cloud data message
[in]originthe sensor acquisition origin
[in]orientationthe sensor acquisition orientation
Returns
(-1) for a general error (-2) if the input cloud is too large for the file format 0 on success

Referenced by pcl::outofcore::OutofcoreOctreeDiskContainer< PointT >::insertRange(), and pcl::io::savePCDFileBinaryCompressed().

◆ writeBinaryCompressed() [2/3]

template<typename PointT >
int pcl::PCDWriter::writeBinaryCompressed ( const std::string &  file_name,
const pcl::PointCloud< PointT > &  cloud 
)

Save point cloud data to a binary comprssed PCD file.

Parameters
[in]file_namethe output file name
[in]cloudthe point cloud data message
Returns
(-1) for a general error (-2) if the input cloud is too large for the file format 0 on success

Definition at line 241 of file pcd_io.hpp.

References pcl::PointCloud< PointT >::empty(), pcl::getFieldSize(), pcl::lzfCompress(), pcl::io::raw_close(), pcl::io::raw_fallocate(), pcl::io::raw_open(), and pcl::PointCloud< PointT >::size().

◆ writeBinaryCompressed() [3/3]

int pcl::PCDWriter::writeBinaryCompressed ( std::ostream &  os,
const pcl::PCLPointCloud2 cloud,
const Eigen::Vector4f &  origin = Eigen::Vector4f::Zero(),
const Eigen::Quaternionf &  orientation = Eigen::Quaternionf::Identity() 
)

Save point cloud data to a std::ostream containing n-D points, in BINARY_COMPRESSED format.

Parameters
[out]osthe stream into which to write the data
[in]cloudthe point cloud data message
[in]originthe sensor acquisition origin
[in]orientationthe sensor acquisition orientation
Returns
(-1) for a general error (-2) if the input cloud is too large for the file format 0 on success

The documentation for this class was generated from the following files: