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

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

#include <kitti.hpp>

Inheritance diagram for toolbox::io::kitti_format_t:

Public Member Functions

 kitti_format_t ()=default
 构造函数。/Constructor.
 
 ~kitti_format_t () override=default
 析构函数。/Destructor.
 
 kitti_format_t (const kitti_format_t &)=delete
 
kitti_format_toperator= (const kitti_format_t &)=delete
 
auto can_read (const std::string &path) const -> bool override
 检查文件扩展名是否为".bin"。/Checks if the file extension is ".bin".
 
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
 将 KITTI 点云文件(BINARY)读入 point_cloud_t<float>。/Reads a KITTI point cloud file (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> 中的数据写入 KITTI 点云文件。/Writes data from a point_cloud_t<float> or point_cloud_t<double> to a KITTI point cloud 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

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

实现了 PCD 文件的 base_file_format_t 接口。/Implements the base_file_format_t interface for PCD files. 支持读取 BINARY 格式。/Supports reading BINARY formats. 支持写入 BINARY

// 读取 PCD 文件/Reading a PCD file
std::unique_ptr<toolbox::io::base_file_data_t> data;
if (kitti_reader.can_read("pointcloud.bin")) {
if (kitti_reader.read("pointcloud.bin", 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));
kitti_reader.write("output.bin", 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

◆ kitti_format_t() [1/2]

toolbox::io::kitti_format_t::kitti_format_t ( )
explicitdefault

构造函数。/Constructor.

◆ ~kitti_format_t()

toolbox::io::kitti_format_t::~kitti_format_t ( )
overridedefault

析构函数。/Destructor.

◆ kitti_format_t() [2/2]

toolbox::io::kitti_format_t::kitti_format_t ( const kitti_format_t )
delete

Member Function Documentation

◆ can_read()

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

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

Parameters
path文件路径/Path to the file
Returns
如果扩展名匹配则为 true,否则为 false/True if the extension matches, false otherwise
if (kitti_format.can_read("cloud.bin")) {
std::cout << "这是一个 KITTI 点云文件/This is a KITTI point cloud file"
<< std::endl;
} else {
std::cout << "这不是一个 KITTI 点云文件/This is not a KITTI point
cloud file" << std::endl;
}
KITTI 点云数据(.bin)文件格式处理器。/File format handler for KITTI Point Cloud Data (.bin) files.
Definition kitti.hpp:67
auto can_read(const std::string &path) const -> bool override
检查文件扩展名是否为".bin"。/Checks if the file extension is ".bin".

Implements toolbox::io::base_file_format_t.

◆ get_supported_extensions()

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

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

Returns
仅包含".bin"的向量/A vector containing only ".bin"
auto extensions = kitti_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=()

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

◆ read()

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

将 KITTI 点云文件(BINARY)读入 point_cloud_t<float>。/Reads a KITTI point cloud file (BINARY) into a point_cloud_t<float>.

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

Parameters
pathKITTI 点云文件的路径/Path to the KITTI point cloud 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 (kitti_format.read("scan.bin", 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;
}
auto read(const std::string &path, std::unique_ptr< base_file_data_t > &data) -> bool override
将 KITTI 点云文件(BINARY)读入 point_cloud_t<float>。/Reads a KITTI point cloud file (BINARY) into a point_clo...

Implements toolbox::io::base_file_format_t.

◆ write()

auto toolbox::io::kitti_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> 中的数据写入 KITTI 点云文件。/Writes data from a point_cloud_t<float> or point_cloud_t<double> to a KITTI point cloud file.

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

Parameters
path输出 KITTI 点云文件的路径/Path to the output KITTI point cloud 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是否以二进制模式写入,总是 true, 因为只支持二进制格式/Whether to write in binary mode(always true, because only binary format is supported)
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 binary_result = kitti_format.write("cloud_binary.bin", data_ptr,
true);
// ASCII 格式/ASCII format bool binary_result =
pcd_format.write("cloud_binary.pcd", data_ptr, true); // 二进制格式/Binary
format
std::cout << "二进制写入" << (binary_result ? "成功" : "失败")
<< "/Binary write " << (binary_result ? "succeeded" : "failed")
<< std::endl;
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> 中的数据写入 KITTI 点云文件。/Writes data from a point_cloud_t<fl...

Implements toolbox::io::base_file_format_t.


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