cpp-toolbox  0.0.1
A toolbox library for C++
Loading...
Searching...
No Matches
toolbox::io Namespace Reference

< 用于列出目录下的文件/For listing files in a directory More...

Namespaces

namespace  kitti_semantic_labels
 

Classes

class  base_file_data_t
 文件数据的基类 / Base class for data loaded from files More...
 
class  base_file_format_t
 文件格式读写器的基类 / Base class for file format readers/writers More...
 
class  dataloader_t
 通用数据加载器/Generic data loader More...
 
class  dataset_t
 数据集基类/Abstract base class for datasets More...
 
struct  kitti_calibration_t
 KITTI calibration data structure. More...
 
class  kitti_corrupted_data
 Exception thrown when data is corrupted. More...
 
class  kitti_exception
 Base exception for KITTI dataset operations. More...
 
class  kitti_file_not_found
 Exception thrown when a file is not found. More...
 
class  kitti_format_t
 KITTI 点云数据(.bin)文件格式处理器。/File format handler for KITTI Point Cloud Data (.bin) files. More...
 
class  kitti_index_out_of_range
 Exception thrown when accessing out of bounds frame. More...
 
class  kitti_invalid_format
 Exception thrown when file format is invalid. More...
 
class  kitti_invalid_sequence
 Exception thrown when sequence directory structure is invalid. More...
 
class  kitti_odometry_dataset_t
 KITTI Odometry dataset loader. More...
 
struct  kitti_odometry_frame_pair_t
 Frame pair data for registration tasks. More...
 
struct  kitti_odometry_frame_t
 Single frame data from KITTI odometry dataset. More...
 
class  kitti_odometry_pair_dataset_t
 KITTI Odometry frame pair dataset loader. More...
 
class  kitti_pcd_dataset_t
 KITTI点云数据集类/KITTI point cloud dataset class. More...
 
class  kitti_pcd_pair_t
 KITTI点云对数据集类/KITTI point cloud pair dataset class. More...
 
class  kitti_pose_reader_t
 Reader for KITTI pose files. More...
 
struct  kitti_sequence_info_t
 Information about a KITTI sequence. More...
 
class  pcd_format_t
 点云数据(.pcd)文件格式处理器。/File format handler for Point Cloud Data (.pcd) files. More...
 
class  sampler_t
 通用采样器/Generic sampler More...
 
class  semantic_kitti_dataset_t
 Semantic KITTI dataset loader. More...
 
struct  semantic_kitti_frame_pair_t
 Frame pair data from Semantic KITTI dataset. More...
 
struct  semantic_kitti_frame_t
 Single frame data from Semantic KITTI dataset. More...
 
class  semantic_kitti_pair_dataset_t
 Semantic KITTI frame pair dataset loader. More...
 
struct  sequential_policy_t
 顺序采样策略/Sequential sampling policy More...
 
class  shuffle_policy_t
 随机打乱采样策略/Shuffle sampling policy More...
 

Enumerations

enum class  error_recovery_policy_t : uint8_t { strict , lenient , best_effort }
 Error recovery policy for dataset loading. More...
 

Functions

template<typename T >
CPP_TOOLBOX_EXPORT std::unique_ptr< toolbox::types::point_cloud_t< T > > read_point_cloud (const std::string &path)
 
template<typename T >
CPP_TOOLBOX_EXPORT bool write_point_cloud (const std::string &path, const toolbox::types::point_cloud_t< T > &cloud)
 
std::vector< uint32_t > read_kitti_labels (const std::string &file_path)
 Read Semantic KITTI label file.
 
bool write_kitti_labels (const std::string &file_path, const std::vector< uint32_t > &labels)
 Write labels to Semantic KITTI format.
 
template<typename DataType >
Eigen::Matrix< DataType, 4, 4 > parse_kitti_pose_line (const std::string &line)
 Parse a single line from KITTI poses file.
 
template<typename DataType >
std::vector< Eigen::Matrix< DataType, 4, 4 > > read_kitti_poses (const std::string &file_path)
 Read all poses from KITTI poses file.
 
template<typename DataType >
std::string format_kitti_pose (const Eigen::Matrix< DataType, 4, 4 > &pose)
 Format pose matrix as KITTI string.
 
template<typename DataType >
bool write_kitti_poses (const std::string &file_path, const std::vector< Eigen::Matrix< DataType, 4, 4 > > &poses)
 Write poses to KITTI format file.
 
template<typename DataType >
kitti_calibration_t< DataType > read_kitti_calibration (const std::string &file_path)
 Read KITTI calibration file.
 
template<typename DataType >
bool write_kitti_calibration (const std::string &file_path, const kitti_calibration_t< DataType > &calib)
 Write KITTI calibration file.
 
template<typename DataType >
Eigen::Matrix< DataType, 4, 4 > compute_relative_transform (const Eigen::Matrix< DataType, 4, 4 > &from_pose, const Eigen::Matrix< DataType, 4, 4 > &to_pose)
 Compute relative transformation between two poses.
 
template<typename DataType >
std::unique_ptr< point_cloud_t< DataType > > transform_point_cloud (const point_cloud_t< DataType > &cloud, const Eigen::Matrix< DataType, 4, 4 > &transform)
 Transform point cloud using transformation matrix.
 
template<typename DataType >
std::unique_ptr< point_cloud_t< DataType > > read_kitti_with_labels (const std::string &bin_path, const std::string &label_path, std::vector< uint32_t > &labels)
 Read KITTI point cloud with semantic labels.
 
std::vector< std::string > list_kitti_cloud_files (const std::string &velodyne_path)
 List all KITTI point cloud files in a directory.
 
std::vector< std::string > list_kitti_label_files (const std::string &labels_path)
 List all KITTI label files in a directory.
 
int parse_kitti_frame_index (const std::string &filename)
 Get frame index from KITTI filename (e.g., "000123.bin" -> 123)
 
std::string format_kitti_frame_index (std::size_t index, int digits=6)
 Format frame index as KITTI filename (e.g., 123 -> "000123")
 
kitti_sequence_info_t get_kitti_sequence_info (const std::string &sequence_path)
 Get information about a KITTI sequence directory.
 
bool validate_kitti_sequence_directory (const std::string &sequence_path)
 Validate KITTI sequence directory structure.
 
template<typename T >
CPP_TOOLBOX_EXPORT std::unique_ptr< toolbox::types::point_cloud_t< T > > read_kitti_bin (const std::string &path)
 从文件中读取 KITTI 点云数据的独立函数。/Standalone function to read KITTI point cloud data from a file.
 
template<typename T >
CPP_TOOLBOX_EXPORT bool write_kitti_bin (const std::string &path, const toolbox::types::point_cloud_t< T > &cloud)
 将点云数据写入 KITTI 点云文件的独立函数。/Standalone function to write point cloud data to a KITTI point cloud file.
 
template<typename T >
CPP_TOOLBOX_EXPORT std::unique_ptr< toolbox::types::point_cloud_t< T > > read_pcd (const std::string &path)
 从文件中读取 PCD 点云数据的独立函数。/Standalone function to read PCD point cloud data from a file.
 
template<typename T >
CPP_TOOLBOX_EXPORT bool write_pcd (const std::string &path, const toolbox::types::point_cloud_t< T > &cloud, bool binary)
 将点云数据写入 PCD 文件的独立函数。/Standalone function to write point cloud data to a PCD file.
 
uint16_t get_kitti_label_id (uint32_t full_label)
 Extract label ID from full label (ignoring instance ID)
 
uint16_t get_kitti_instance_id (uint32_t full_label)
 Extract instance ID from full label.
 
uint32_t make_kitti_full_label (uint16_t label_id, uint16_t instance_id)
 Combine label and instance IDs.
 

Detailed Description

< 用于列出目录下的文件/For listing files in a directory

< 用于读取KITTI点云/For reading KITTI

Enumeration Type Documentation

◆ error_recovery_policy_t

enum class toolbox::io::error_recovery_policy_t : uint8_t
strong

Error recovery policy for dataset loading.

Enumerator
strict 

Throw exception on any error.

lenient 

Skip problematic frames and continue.

best_effort 

Try to recover partial data.

Function Documentation

◆ compute_relative_transform()

template<typename DataType >
Eigen::Matrix< DataType, 4, 4 > toolbox::io::compute_relative_transform ( const Eigen::Matrix< DataType, 4, 4 > &  from_pose,
const Eigen::Matrix< DataType, 4, 4 > &  to_pose 
)

Compute relative transformation between two poses.

Template Parameters
DataTypeThe floating point type (float or double)
Parameters
from_poseSource pose
to_poseTarget pose
Returns
Relative transformation T_to_from such that to_pose = T_to_from * from_pose

◆ format_kitti_frame_index()

std::string toolbox::io::format_kitti_frame_index ( std::size_t  index,
int  digits = 6 
)
inline

Format frame index as KITTI filename (e.g., 123 -> "000123")

Parameters
indexFrame index
digitsNumber of digits (default 6 for KITTI)
Returns
Formatted string

◆ format_kitti_pose()

template<typename DataType >
std::string toolbox::io::format_kitti_pose ( const Eigen::Matrix< DataType, 4, 4 > &  pose)

Format pose matrix as KITTI string.

Template Parameters
DataTypeThe floating point type (float or double)
Parameters
pose4x4 transformation matrix
Returns
String with 12 values (first 3 rows)

◆ get_kitti_instance_id()

uint16_t toolbox::io::get_kitti_instance_id ( uint32_t  full_label)
inline

Extract instance ID from full label.

◆ get_kitti_label_id()

uint16_t toolbox::io::get_kitti_label_id ( uint32_t  full_label)
inline

Extract label ID from full label (ignoring instance ID)

◆ get_kitti_sequence_info()

kitti_sequence_info_t toolbox::io::get_kitti_sequence_info ( const std::string &  sequence_path)
inline

Get information about a KITTI sequence directory.

Parameters
sequence_pathPath to sequence directory
Returns
Sequence information

◆ list_kitti_cloud_files()

std::vector< std::string > toolbox::io::list_kitti_cloud_files ( const std::string &  velodyne_path)
inline

List all KITTI point cloud files in a directory.

Parameters
velodyne_pathPath to velodyne directory
Returns
Sorted list of .bin files with full paths

◆ list_kitti_label_files()

std::vector< std::string > toolbox::io::list_kitti_label_files ( const std::string &  labels_path)
inline

List all KITTI label files in a directory.

Parameters
labels_pathPath to labels directory
Returns
Sorted list of .label files with full paths

◆ make_kitti_full_label()

uint32_t toolbox::io::make_kitti_full_label ( uint16_t  label_id,
uint16_t  instance_id 
)
inline

Combine label and instance IDs.

◆ parse_kitti_frame_index()

int toolbox::io::parse_kitti_frame_index ( const std::string &  filename)
inline

Get frame index from KITTI filename (e.g., "000123.bin" -> 123)

Parameters
filenameFilename to parse
Returns
Frame index or -1 if invalid

◆ parse_kitti_pose_line()

template<typename DataType >
Eigen::Matrix< DataType, 4, 4 > toolbox::io::parse_kitti_pose_line ( const std::string &  line)

Parse a single line from KITTI poses file.

Template Parameters
DataTypeThe floating point type (float or double)
Parameters
lineLine containing 12 values (3x4 transformation matrix)
Returns
4x4 transformation matrix (with [0,0,0,1] as last row)
Exceptions
std::invalid_argumentif line format is invalid

◆ read_kitti_bin()

template<typename T >
CPP_TOOLBOX_EXPORT std::unique_ptr< toolbox::types::point_cloud_t< T > > toolbox::io::read_kitti_bin ( const std::string &  path)

从文件中读取 KITTI 点云数据的独立函数。/Standalone function to read KITTI point cloud data from a file.

Template Parameters
T点云数据的存储类型(如 float 或 double)/Storage type for the point cloud data (e.g., float or double)
Parameters
pathKITTI 点云文件的路径/Path to the KITTI point cloud file
Returns
包含读取点云的唯一指针,如果读取失败则返回 nullptr/Unique pointer containing the read point cloud, or nullptr if reading fails
// 读取 float 类型的点云/Read a point cloud with float precision
auto cloud_float = toolbox::io::read_kitti_bin<float>("cloud.bin");
if (cloud_float) {
std::cout << "读取了 " << cloud_float->size() << " 个点/Read " <<
cloud_float->size() << " points" << std::endl;
}
// 读取 double 类型的点云/Read a point cloud with double precision
auto cloud_double =
toolbox::io::read_kitti_bin<double>("cloud.bin");

◆ read_kitti_calibration()

template<typename DataType >
kitti_calibration_t< DataType > toolbox::io::read_kitti_calibration ( const std::string &  file_path)

Read KITTI calibration file.

Template Parameters
DataTypeThe floating point type (float or double)
Parameters
file_pathPath to calib.txt file
Returns
Calibration data
Exceptions
std::runtime_errorif file cannot be parsed

◆ read_kitti_labels()

std::vector< uint32_t > toolbox::io::read_kitti_labels ( const std::string &  file_path)
inline

Read Semantic KITTI label file.

Parameters
file_pathPath to the .label file
Returns
Vector of labels (one per point), empty on failure
Exceptions
std::runtime_errorif file cannot be read

◆ read_kitti_poses()

template<typename DataType >
std::vector< Eigen::Matrix< DataType, 4, 4 > > toolbox::io::read_kitti_poses ( const std::string &  file_path)

Read all poses from KITTI poses file.

Template Parameters
DataTypeThe floating point type (float or double)
Parameters
file_pathPath to poses file (e.g., "00.txt")
Returns
Vector of 4x4 transformation matrices

◆ read_kitti_with_labels()

template<typename DataType >
std::unique_ptr< point_cloud_t< DataType > > toolbox::io::read_kitti_with_labels ( const std::string &  bin_path,
const std::string &  label_path,
std::vector< uint32_t > &  labels 
)

Read KITTI point cloud with semantic labels.

Template Parameters
DataTypeThe floating point type (float or double)
Parameters
bin_pathPath to the .bin point cloud file
label_pathPath to the .label file
[out]labelsVector to store the semantic labels (one per point)
Returns
Point cloud, nullptr on error
Exceptions
std::runtime_errorif files cannot be read or have mismatched sizes
Note
The labels are returned in a separate vector parallel to the point cloud. Use get_kitti_label_id() and get_kitti_instance_id() to extract semantic class and instance.
std::vector<uint32_t> labels;
auto cloud = read_kitti_with_labels<float>("/path/to/000000.bin",
"/path/to/000000.label",
labels);
if (cloud) {
for (size_t i = 0; i < cloud->size(); ++i) {
uint16_t label_id = get_kitti_label_id(labels[i]);
uint16_t instance_id = get_kitti_instance_id(labels[i]);
// Use label_id and instance_id with cloud->points[i]...
}
}
uint16_t get_kitti_instance_id(uint32_t full_label)
Extract instance ID from full label.
Definition kitti_extended.hpp:296
uint16_t get_kitti_label_id(uint32_t full_label)
Extract label ID from full label (ignoring instance ID)
Definition kitti_extended.hpp:289

◆ read_pcd()

template<typename T >
CPP_TOOLBOX_EXPORT std::unique_ptr< toolbox::types::point_cloud_t< T > > toolbox::io::read_pcd ( const std::string &  path)

从文件中读取 PCD 点云数据的独立函数。/Standalone function to read PCD point cloud data from a file.

Template Parameters
T点云数据的存储类型(如 float 或 double)/Storage type for the point cloud data (e.g., float or double)
Parameters
pathPCD 文件的路径/Path to the PCD file
Returns
包含读取点云的唯一指针,如果读取失败则返回 nullptr/Unique pointer containing the read point cloud, or nullptr if reading fails
// 读取 float 类型的点云/Read a point cloud with float precision
auto cloud_float = toolbox::io::read_pcd<float>("cloud.pcd");
if (cloud_float) {
std::cout << "读取了 " << cloud_float->size() << " 个点/Read " <<
cloud_float->size() << " points" << std::endl;
}
// 读取 double 类型的点云/Read a point cloud with double precision
auto cloud_double = toolbox::io::read_pcd<double>("cloud.pcd");

◆ read_point_cloud()

template<typename T >
CPP_TOOLBOX_EXPORT std::unique_ptr< toolbox::types::point_cloud_t< T > > toolbox::io::read_point_cloud ( const std::string &  path)

◆ transform_point_cloud()

template<typename DataType >
std::unique_ptr< point_cloud_t< DataType > > toolbox::io::transform_point_cloud ( const point_cloud_t< DataType > &  cloud,
const Eigen::Matrix< DataType, 4, 4 > &  transform 
)

Transform point cloud using transformation matrix.

Template Parameters
DataTypeThe floating point type
Parameters
cloudInput point cloud
transformTransformation matrix
Returns
Transformed point cloud

◆ validate_kitti_sequence_directory()

bool toolbox::io::validate_kitti_sequence_directory ( const std::string &  sequence_path)
inline

Validate KITTI sequence directory structure.

Parameters
sequence_pathPath to sequence directory
Returns
True if valid KITTI structure

◆ write_kitti_bin()

template<typename T >
CPP_TOOLBOX_EXPORT bool toolbox::io::write_kitti_bin ( const std::string &  path,
const toolbox::types::point_cloud_t< T > &  cloud 
)

将点云数据写入 KITTI 点云文件的独立函数。/Standalone function to write point cloud data to a KITTI point cloud file.

Template Parameters
T点云数据的存储类型(如 float 或 double)/Storage type for the point cloud data (e.g., float or double)
Parameters
path要写入的 KITTI 点云文件路径/Path to the KITTI point cloud file to write
cloud要保存的点云数据/The point cloud data to save
Returns
写入成功返回 true,失败返回 false/Returns true if writing was successful, false otherwise
// 创建一个点云并添加一些点/Create a point cloud and add some points
cloud.points = {{1.0f, 2.0f, 3.0f}, {4.0f, 5.0f, 6.0f}};
// 以二进制格式保存/Save in binary format
bool binary_success =
toolbox::io::write_kitti_bin("cloud_binary.bin", cloud);
包含点和相关数据的点云类 / A point cloud class containing points and associated data
Definition point.hpp:268
std::vector< point_t< T > > points
点坐标 / Point coordinates
Definition point.hpp:270
CPP_TOOLBOX_EXPORT bool write_kitti_bin(const std::string &path, const toolbox::types::point_cloud_t< T > &cloud)
将点云数据写入 KITTI 点云文件的独立函数。/Standalone function to write point cloud data to a KITTI point cloud file.
Definition kitti_impl.hpp:258

◆ write_kitti_calibration()

template<typename DataType >
bool toolbox::io::write_kitti_calibration ( const std::string &  file_path,
const kitti_calibration_t< DataType > &  calib 
)

Write KITTI calibration file.

Template Parameters
DataTypeThe floating point type (float or double)
Parameters
file_pathOutput file path
calibCalibration data to write
Returns
True if successful

◆ write_kitti_labels()

bool toolbox::io::write_kitti_labels ( const std::string &  file_path,
const std::vector< uint32_t > &  labels 
)
inline

Write labels to Semantic KITTI format.

Parameters
file_pathOutput file path
labelsVector of labels to write
Returns
True if successful

◆ write_kitti_poses()

template<typename DataType >
bool toolbox::io::write_kitti_poses ( const std::string &  file_path,
const std::vector< Eigen::Matrix< DataType, 4, 4 > > &  poses 
)

Write poses to KITTI format file.

Template Parameters
DataTypeThe floating point type (float or double)
Parameters
file_pathOutput file path
posesVector of 4x4 transformation matrices
Returns
True if successful

◆ write_pcd()

template<typename T >
CPP_TOOLBOX_EXPORT bool toolbox::io::write_pcd ( const std::string &  path,
const toolbox::types::point_cloud_t< T > &  cloud,
bool  binary 
)

将点云数据写入 PCD 文件的独立函数。/Standalone function to write point cloud data to a PCD file.

Template Parameters
T点云数据的存储类型(如 float 或 double)/Storage type for the point cloud data (e.g., float or double)
Parameters
path要写入的 PCD 文件路径/Path to the PCD file to write
cloud要保存的点云数据/The point cloud data to save
binary如果为 true,则以二进制格式写入;如果为 false,则以 ASCII 格式写入/If true, writes in binary format; if false, writes in ASCII format
Returns
写入成功返回 true,失败返回 false/Returns true if writing was successful, false otherwise
// 创建一个点云并添加一些点/Create a point cloud and add some points
cloud.points = {{1.0f, 2.0f, 3.0f}, {4.0f, 5.0f, 6.0f}};
// 以 ASCII 格式保存/Save in ASCII format
bool ascii_success = toolbox::io::write_pcd("cloud_ascii.pcd",
cloud, false);
// 以二进制格式保存/Save in binary format
bool binary_success = toolbox::io::write_pcd("cloud_binary.pcd",
cloud, true);
CPP_TOOLBOX_EXPORT bool write_pcd(const std::string &path, const toolbox::types::point_cloud_t< T > &cloud, bool binary)
将点云数据写入 PCD 文件的独立函数。/Standalone function to write point cloud data to a PCD file.
Definition pcd_impl.hpp:833

◆ write_point_cloud()

template<typename T >
CPP_TOOLBOX_EXPORT bool toolbox::io::write_point_cloud ( const std::string &  path,
const toolbox::types::point_cloud_t< T > &  cloud 
)