cpp-toolbox  0.0.1
A toolbox library for C++
Loading...
Searching...
No Matches
toolbox::io::pcd_format_t Class Referencefinal

点云数据(.pcd)文件格式处理器。/File format handler for Point Cloud Data (.pcd) files. More...

#include <pcd.hpp>

Inheritance diagram for toolbox::io::pcd_format_t:

Public Member Functions

 pcd_format_t ()=default
 构造函数。/Constructor.
 
 ~pcd_format_t () override=default
 析构函数。/Destructor.
 
 pcd_format_t (const pcd_format_t &)=delete
 
pcd_format_toperator= (const pcd_format_t &)=delete
 
auto can_read (const std::string &path) const -> bool override
 检查文件扩展名是否为".pcd"。/Checks if the file extension is ".pcd".
 
auto get_supported_extensions () const -> std::vector< std::string > override
 返回支持的文件扩展名。/Returns the supported file extension.
 
auto read (const std::string &path, std::unique_ptr< base_file_data_t > &data) -> bool override
 将 PCD 文件(ASCII 或 BINARY)读入 point_cloud_t<float>。/Reads a PCD file (ASCII or BINARY) into a point_cloud_t<float>.
 
auto write (const std::string &path, const std::unique_ptr< base_file_data_t > &data, bool binary) const -> bool override
 将 point_cloud_t<float> 或 point_cloud_t<double> 中的数据写入 PCD 文件。/Writes data from a point_cloud_t<float> or point_cloud_t<double> to a PCD file.
 
- Public Member Functions inherited from toolbox::io::base_file_format_t
virtual ~base_file_format_t ()=default
 
 base_file_format_t (const base_file_format_t &)=delete
 
base_file_format_toperator= (const base_file_format_t &)=delete
 
 base_file_format_t (base_file_format_t &&)=default
 
base_file_format_toperator= (base_file_format_t &&)=default
 

Additional Inherited Members

- Protected Member Functions inherited from toolbox::io::base_file_format_t
 base_file_format_t ()=default
 

Detailed Description

点云数据(.pcd)文件格式处理器。/File format handler for Point Cloud Data (.pcd) files.

实现了 PCD 文件的 base_file_format_t 接口。/Implements the base_file_format_t interface for PCD files. 支持读取 ASCII 和 BINARY 格式。/Supports reading ASCII and BINARY formats. 支持写入 ASCII 和 BINARY 格式(可通过构造函数配置)。/Supports writing ASCII and BINARY formats (configurable via constructor). 使用内存映射加速 BINARY 文件的读取。/Uses memory mapping for accelerated reading of BINARY files. 默认将数据读入 point_cloud_t<float>。/Reads data into point_cloud_t<float> by default. 可以写入 point_cloud_t<float> 或 point_cloud_t<double>。/Can write point_cloud_t<float> or point_cloud_t<double>.

// 读取 PCD 文件/Reading a PCD file
std::unique_ptr<toolbox::io::base_file_data_t> data;
if (pcd_reader.can_read("pointcloud.pcd")) {
if (pcd_reader.read("pointcloud.pcd", data)) {
auto* cloud =
dynamic_cast<toolbox::types::point_cloud_t<float>*>(data.get()); if (cloud) {
std::cout << "读取了 " << cloud->size() << " 个点/Read " <<
cloud->size() << " points" << std::endl;
}
}
}
// 写入 PCD 文件/Writing a PCD file
// 填充点云数据/Fill point cloud data
cloud.push_back({1.0f, 2.0f, 3.0f});
cloud.push_back({4.0f, 5.0f, 6.0f});
std::unique_ptr<toolbox::io::base_file_data_t> write_data =
std::make_unique<toolbox::types::point_cloud_t<float>>(std::move(cloud));
pcd_reader.write("output.pcd", write_data, true); // 以二进制格式写入/Write
in binary format
点云数据(.pcd)文件格式处理器。/File format handler for Point Cloud Data (.pcd) files.
Definition pcd.hpp:72
auto read(const std::string &path, std::unique_ptr< base_file_data_t > &data) -> bool override
将 PCD 文件(ASCII 或 BINARY)读入 point_cloud_t<float>。/Reads a PCD file (ASCII or BINARY) into a point_clou...
auto write(const std::string &path, const std::unique_ptr< base_file_data_t > &data, bool binary) const -> bool override
将 point_cloud_t<float> 或 point_cloud_t<double> 中的数据写入 PCD 文件。/Writes data from a point_cloud_t<float>...
auto can_read(const std::string &path) const -> bool override
检查文件扩展名是否为".pcd"。/Checks if the file extension is ".pcd".
包含点和相关数据的点云类 / A point cloud class containing points and associated data
Definition point.hpp:268
auto size() const -> std::size_t
获取点云中的点数 / Get number of points in cloud
Definition point_impl.hpp:293

Constructor & Destructor Documentation

◆ pcd_format_t() [1/2]

toolbox::io::pcd_format_t::pcd_format_t ( )
explicitdefault

构造函数。/Constructor.

◆ ~pcd_format_t()

toolbox::io::pcd_format_t::~pcd_format_t ( )
overridedefault

析构函数。/Destructor.

◆ pcd_format_t() [2/2]

toolbox::io::pcd_format_t::pcd_format_t ( const pcd_format_t )
delete

Member Function Documentation

◆ can_read()

auto toolbox::io::pcd_format_t::can_read ( const std::string &  path) const -> bool
overridevirtual

检查文件扩展名是否为".pcd"。/Checks if the file extension is ".pcd".

Parameters
path文件路径/Path to the file
Returns
如果扩展名匹配则为 true,否则为 false/True if the extension matches, false otherwise
if (pcd_format.can_read("cloud.pcd")) {
std::cout << "这是一个 PCD 文件/This is a PCD file" << std::endl;
} else {
std::cout << "这不是一个 PCD 文件/This is not a PCD file" << std::endl;
}

Implements toolbox::io::base_file_format_t.

◆ get_supported_extensions()

auto toolbox::io::pcd_format_t::get_supported_extensions ( ) const -> std::vector< std::string >
overridevirtual

返回支持的文件扩展名。/Returns the supported file extension.

Returns
仅包含".pcd"的向量/A vector containing only ".pcd"
auto extensions = pcd_format.get_supported_extensions();
for (const auto& ext : extensions) {
std::cout << "支持的扩展名/Supported extension: " << ext << std::endl;
}
auto get_supported_extensions() const -> std::vector< std::string > override
返回支持的文件扩展名。/Returns the supported file extension.

Implements toolbox::io::base_file_format_t.

◆ operator=()

pcd_format_t & toolbox::io::pcd_format_t::operator= ( const pcd_format_t )
delete

◆ read()

auto toolbox::io::pcd_format_t::read ( const std::string &  path,
std::unique_ptr< base_file_data_t > &  data 
) -> bool
overridevirtual

将 PCD 文件(ASCII 或 BINARY)读入 point_cloud_t<float>。/Reads a PCD file (ASCII or BINARY) into a point_cloud_t<float>.

选择 T=float 作为常见默认值。/The specific type T=float is chosen as a common default.

Parameters
pathPCD 文件的路径/Path to the PCD file
data输出 unique_ptr,成功时将持有创建的 point_cloud_t<float>/Output unique_ptr that will hold the created point_cloud_t<float> on success
Returns
读取成功则为 true,否则为 false/True on successful read, false otherwise
std::unique_ptr<toolbox::io::base_file_data_t> cloud_data;
if (pcd_format.read("scan.pcd", cloud_data)) {
// 转换为具体类型/Convert to concrete type
auto* point_cloud =
dynamic_cast<toolbox::types::point_cloud_t<float>*>(cloud_data.get()); if
(point_cloud) { std::cout << "读取了 " << point_cloud->size() << "
个点/Read "
<< point_cloud->size() << " points" << std::endl;
}
} else {
std::cerr << "读取失败/Read failed" << std::endl;
}

Implements toolbox::io::base_file_format_t.

◆ write()

auto toolbox::io::pcd_format_t::write ( const std::string &  path,
const std::unique_ptr< base_file_data_t > &  data,
bool  binary 
) const -> bool
overridevirtual

将 point_cloud_t<float> 或 point_cloud_t<double> 中的数据写入 PCD 文件。/Writes data from a point_cloud_t<float> or point_cloud_t<double> to a PCD file.

格式(ASCII 或 BINARY)由 binary 参数决定。/The format (ASCII or BINARY) is determined by the binary parameter.

Parameters
path输出 PCD 文件的路径/Path to the output PCD file
data输入 unique_ptr,持有 point_cloud_t<float> 或 point_cloud_t<double>/Input unique_ptr holding a point_cloud_t<float> or point_cloud_t<double>
binary是否以二进制模式写入/Whether to write in binary mode
Returns
写入成功则为 true;如果输入数据为空、不是支持的点云类型或发生文件错误则为 false/True on successful write, false if input data is null, not a supported point cloud type, or if a file error occurs
// 创建点云/Create a point cloud
auto cloud = std::make_unique<toolbox::types::point_cloud_t<float>>();
// 添加一些点/Add some points
cloud->push_back({1.0f, 2.0f, 3.0f});
cloud->push_back({4.0f, 5.0f, 6.0f});
cloud->push_back({7.0f, 8.0f, 9.0f});
// 转换为基类指针/Convert to base class pointer
std::unique_ptr<toolbox::io::base_file_data_t>
data_ptr(cloud.release());
// 写入文件/Write to file
bool ascii_result = pcd_format.write("cloud_ascii.pcd", data_ptr, false);
// ASCII 格式/ASCII format bool binary_result =
pcd_format.write("cloud_binary.pcd", data_ptr, true); // 二进制格式/Binary
format
std::cout << "ASCII 写入" << (ascii_result ? "成功" : "失败")
<< "/ASCII write " << (ascii_result ? "succeeded" : "failed") <<
std::endl; std::cout << "二进制写入" << (binary_result ? "成功" : "失败")
<< "/Binary write " << (binary_result ? "succeeded" : "failed")
<< std::endl;

Implements toolbox::io::base_file_format_t.


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