【cartographer源码分析】系列的第四部分【io源码分析】。
现总结io文件夹涉及到的主要功能:
【1】file_writer.h
file_writer.h定义了多个用于文件写入的类
- FileWriter
- FileWriter是负责文件写入的虚基类没有数据成员.只提供一系列抽象接口.
- 包括3个抽象接口:
- WriteHeader(),写入文件head
- Write(),写入数据
- Close(),关闭文件
StreamFileWriter
- StreamFileWriter 文件流写入类,继承自FileWriter
- 数据成员只有一个std::ofstream out_负责将文件写入磁盘.
- 包括3个成员函数:
- WriteHeader(),写入文件head
- Write(),写入数据
- Close(),关闭文件
全局函数:
- using FileWriterFactory =
std::function< std::unique_ptr< FileWriter >(const string& filename)>;
工厂模式,
创建一个FileWriter对象,由智能指针管理生命期,
返回值是std::unique_ptr,
函数参数是string.
- using FileWriterFactory =
【2】io/points_batch.h:
PointsBatch类是对多个点云point的抽象.这些point在由同一时刻,同一机器人坐标地点的传感器采集而得。
数据成员主要描述了point的特性.
PointsBatch数据成员:- common::Time time; point采集时间.
- Eigen::Vector3f origin; sensor的世界坐标, 传感器位姿
- string frame_id;关键帧的id
- int trajectory_index;轨迹线id
- std::vector points;point的几何参数,vector<{x,y,z}>
- std::vector intensities;光强
- std::vector colors;point的rgb值
全局函数
- void RemovePoints(std::vector to_remove, PointsBatch* batch);按照to_temove中的索引,在batch中移除某些point.
【3】流水线-points_processor
整个IO文件夹实现了对点云数据的读取和存储,并且为了模块化,cartographer使用流水线作业的方式对点云进行处理(pipeline)。不同的.h文件抽象了流水线不同的处理器processor。并且类似于链表,每个在流水线上的processor都含有一个Next指针,执行下一阶段的processor。以此来执行作业。在assets_writer_backpack_2d.lua文件中有各个pipeline的处理流程.
【4】io/points_processor.h
points_processor.h文件夹定义了一个抽象基类PointsProcessor,抽象了所有在流水线上的processor的公有接口。提供一种批量处理points的方法。
类内数据结构:
- enum class FlushResult {
kRestartStream,//重启流水线
kFinished,//已完成作业
};
用于表达本处理器的当前状态,枚举值
- enum class FlushResult {
2个抽象接口:
- virtual void Process(std::unique_ptr points_batch) =0;纯虚函数,Process()负责对PointsBatch进行处理
- Flush()刷新点云数据.
【5】min_max_range_filtering_points_processor
MinMaxRangeFiteringPointsProce