![](/style/images/good.png)
![](/style/images/bad.png)
保存文件SerializeState | 沉默杀手
source link: https://charon-cheung.github.io/2022/11/22/%E6%BF%80%E5%85%89SLAM/Cartographer/%E6%BA%90%E7%A0%81%E8%A7%A3%E8%AF%BB/%E4%BF%9D%E5%AD%98%E6%96%87%E4%BB%B6SerializeState/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
保存文件SerializeState | 沉默杀手
Node::SerializeState
—— MapBuilder::SerializeState
—— MapBuilder::SerializeState
—— cartographer\io\internal\mapping_state_serialization.cc
文件中的WritePbStream
函数
实际是MapBuilderBridge::SerializeState
,Node::HandleWriteState
调用的也是这个函数。在最新版本里是bool MapBuilderBridge::SerializeState(const std::string& filename, const bool include_unfinished_submaps);
cartographer::io::ProtoStreamWriter writer(filename);
map_builder_->SerializeState(&writer);
return writer.Close();
然后是
void MapBuilder::SerializeState(bool include_unfinished_submaps,
io::ProtoStreamWriterInterface* const writer)
{
io::WritePbStream(*pose_graph_, all_trajectory_builder_options_, writer,
include_unfinished_submaps);
}
proto_stream.cc
包含ProtoStreamWriter
和ProtoStreamReader
两个类,这里用的是类ProtoStreamWriter
,在它的构造函数里以二进制方式,写入8个字节的魔术数以确定proto stream格式,
WritePbStream
如下,这里的writer
就是类ProtoStreamWriter
void WritePbStream(
const mapping::PoseGraph& pose_graph,
const std::vector<mapping::proto::TrajectoryBuilderOptionsWithSensorIds>&
trajectory_builder_options,
ProtoStreamWriterInterface* const writer, bool include_unfinished_submaps)
{
writer->WriteProto(CreateHeader());
writer->WriteProto(
SerializePoseGraph(pose_graph, include_unfinished_submaps));
writer->WriteProto(SerializeTrajectoryBuilderOptions(
trajectory_builder_options,
GetValidTrajectoryIds(pose_graph.GetTrajectoryStates())));
SerializeSubmaps(pose_graph.GetAllSubmapData(), include_unfinished_submaps,
writer);
SerializeTrajectoryNodes(pose_graph.GetTrajectoryNodes(), writer);
SerializeTrajectoryData(pose_graph.GetTrajectoryData(), writer);
SerializeImuData(pose_graph.GetImuData(), writer);
SerializeOdometryData(pose_graph.GetOdometryData(), writer);
SerializeFixedFramePoseData(pose_graph.GetFixedFramePoseData(), writer);
SerializeLandmarkNodes(pose_graph.GetLandmarkNodes(), writer);
}
保存的是子图、轨迹节点、轨迹数据、IMU数据、里程计、Landmark等等
ProtoStreamWriter
保存数据时用到了common::FastGzipString
函数,实质是boost::iostreams::gzip_compressor
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK