00001 /* 00002 * Copyright 2018 The Cartographer Authors 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #ifndef CARTOGRAPHER_IO_PROTO_STREAM_DESERIALIZER_H_ 00018 #define CARTOGRAPHER_IO_PROTO_STREAM_DESERIALIZER_H_ 00019 00020 #include "cartographer/io/proto_stream_interface.h" 00021 #include "cartographer/mapping/proto/pose_graph.pb.h" 00022 #include "cartographer/mapping/proto/serialization.pb.h" 00023 #include "cartographer/mapping/proto/trajectory_builder_options.pb.h" 00024 00025 namespace cartographer { 00026 namespace io { 00027 00028 // Helper function for deserializing the PoseGraph from a proto stream file. 00029 mapping::proto::PoseGraph DeserializePoseGraphFromFile( 00030 const std::string& file_name); 00031 00032 // Helper for deserializing a previously serialized mapping state from a 00033 // proto stream, abstracting away the format parsing logic. 00034 class ProtoStreamDeserializer { 00035 public: 00036 explicit ProtoStreamDeserializer(ProtoStreamReaderInterface* const reader); 00037 00038 ProtoStreamDeserializer(const ProtoStreamDeserializer&) = delete; 00039 ProtoStreamDeserializer& operator=(const ProtoStreamDeserializer&) = delete; 00040 ProtoStreamDeserializer(ProtoStreamDeserializer&&) = delete; 00041 00042 mapping::proto::SerializationHeader& header() { return header_; } 00043 00044 mapping::proto::PoseGraph& pose_graph() { 00045 return *pose_graph_.mutable_pose_graph(); 00046 } 00047 const mapping::proto::PoseGraph& pose_graph() const { 00048 return pose_graph_.pose_graph(); 00049 } 00050 00051 const mapping::proto::AllTrajectoryBuilderOptions& 00052 all_trajectory_builder_options() { 00053 return all_trajectory_builder_options_.all_trajectory_builder_options(); 00054 } 00055 00056 // Reads the next `SerializedData` message of the ProtoStream into `data`. 00057 // Returns `true` if the message was successfully read or `false` in case 00058 // there are no-more messages or an error occurred. 00059 bool ReadNextSerializedData(mapping::proto::SerializedData* data); 00060 00061 private: 00062 ProtoStreamReaderInterface* reader_; 00063 00064 mapping::proto::SerializationHeader header_; 00065 mapping::proto::SerializedData pose_graph_; 00066 mapping::proto::SerializedData all_trajectory_builder_options_; 00067 }; 00068 00069 } // namespace io 00070 } // namespace cartographer 00071 00072 #endif // CARTOGRAPHER_IO_PROTO_STREAM_DESERIALIZER_H_