gaschler 2018-06-19 11:00:41 +02:00 committed by GitHub
parent 42c1288e66
commit 5d26742bfa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 47 additions and 12 deletions

View File

@ -124,8 +124,8 @@ void MapBuilderStub::SerializeState(io::ProtoStreamWriterInterface* writer) {
} }
} }
void MapBuilderStub::LoadState(io::ProtoStreamReaderInterface* reader, std::map<int, int> MapBuilderStub::LoadState(
const bool load_frozen_state) { io::ProtoStreamReaderInterface* reader, const bool load_frozen_state) {
if (!load_frozen_state) { if (!load_frozen_state) {
LOG(FATAL) << "Not implemented"; LOG(FATAL) << "Not implemented";
} }
@ -163,6 +163,13 @@ void MapBuilderStub::LoadState(io::ProtoStreamReaderInterface* reader,
CHECK(reader->eof()); CHECK(reader->eof());
CHECK(client.StreamWritesDone()); CHECK(client.StreamWritesDone());
CHECK(client.StreamFinish().ok()); CHECK(client.StreamFinish().ok());
// TODO(gaschler): Return trajectory remapping.
return {};
}
std::map<int, int> MapBuilderStub::LoadStateFromFile(
const std::string& filename) {
LOG(FATAL) << "not implemented";
} }
int MapBuilderStub::num_trajectory_builders() const { int MapBuilderStub::num_trajectory_builders() const {

View File

@ -48,8 +48,9 @@ class MapBuilderStub : public mapping::MapBuilderInterface {
const mapping::SubmapId& submap_id, const mapping::SubmapId& submap_id,
mapping::proto::SubmapQuery::Response* response) override; mapping::proto::SubmapQuery::Response* response) override;
void SerializeState(io::ProtoStreamWriterInterface* writer) override; void SerializeState(io::ProtoStreamWriterInterface* writer) override;
void LoadState(io::ProtoStreamReaderInterface* reader, std::map<int, int> LoadState(io::ProtoStreamReaderInterface* reader,
bool load_frozen_state) override; bool load_frozen_state) override;
std::map<int, int> LoadStateFromFile(const std::string& filename) override;
int num_trajectory_builders() const override; int num_trajectory_builders() const override;
mapping::PoseGraphInterface* pose_graph() override; mapping::PoseGraphInterface* pose_graph() override;
const std::vector<mapping::proto::TrajectoryBuilderOptionsWithSensorIds>& const std::vector<mapping::proto::TrajectoryBuilderOptionsWithSensorIds>&

View File

@ -448,6 +448,8 @@ TEST_F(ClientServerTest, LoadState) {
server_->Shutdown(); server_->Shutdown();
} }
// TODO(gaschler): Test-cover LoadStateFromFile.
} // namespace } // namespace
} // namespace cloud } // namespace cloud
} // namespace cartographer } // namespace cartographer

View File

@ -48,7 +48,9 @@ class MockMapBuilder : public mapping::MapBuilderInterface {
std::string(const mapping::SubmapId &, std::string(const mapping::SubmapId &,
mapping::proto::SubmapQuery::Response *)); mapping::proto::SubmapQuery::Response *));
MOCK_METHOD1(SerializeState, void(io::ProtoStreamWriterInterface *)); MOCK_METHOD1(SerializeState, void(io::ProtoStreamWriterInterface *));
MOCK_METHOD2(LoadState, void(io::ProtoStreamReaderInterface *, bool)); MOCK_METHOD2(LoadState,
std::map<int, int>(io::ProtoStreamReaderInterface *, bool));
MOCK_METHOD1(LoadStateFromFile, std::map<int, int>(const std::string &));
MOCK_CONST_METHOD0(num_trajectory_builders, int()); MOCK_CONST_METHOD0(num_trajectory_builders, int());
MOCK_METHOD0(pose_graph, mapping::PoseGraphInterface *()); MOCK_METHOD0(pose_graph, mapping::PoseGraphInterface *());
MOCK_CONST_METHOD0( MOCK_CONST_METHOD0(

View File

@ -19,6 +19,7 @@
#include "cartographer/common/make_unique.h" #include "cartographer/common/make_unique.h"
#include "cartographer/common/time.h" #include "cartographer/common/time.h"
#include "cartographer/io/internal/mapping_state_serialization.h" #include "cartographer/io/internal/mapping_state_serialization.h"
#include "cartographer/io/proto_stream.h"
#include "cartographer/io/proto_stream_deserializer.h" #include "cartographer/io/proto_stream_deserializer.h"
#include "cartographer/mapping/internal/2d/local_trajectory_builder_2d.h" #include "cartographer/mapping/internal/2d/local_trajectory_builder_2d.h"
#include "cartographer/mapping/internal/2d/overlapping_submaps_trimmer_2d.h" #include "cartographer/mapping/internal/2d/overlapping_submaps_trimmer_2d.h"
@ -206,8 +207,8 @@ void MapBuilder::SerializeState(io::ProtoStreamWriterInterface* const writer) {
io::WritePbStream(*pose_graph_, all_trajectory_builder_options_, writer); io::WritePbStream(*pose_graph_, all_trajectory_builder_options_, writer);
} }
void MapBuilder::LoadState(io::ProtoStreamReaderInterface* const reader, std::map<int, int> MapBuilder::LoadState(
bool load_frozen_state) { io::ProtoStreamReaderInterface* const reader, bool load_frozen_state) {
io::ProtoStreamDeserializer deserializer(reader); io::ProtoStreamDeserializer deserializer(reader);
// Create a copy of the pose_graph_proto, such that we can re-write the // Create a copy of the pose_graph_proto, such that we can re-write the
@ -364,6 +365,20 @@ void MapBuilder::LoadState(io::ProtoStreamReaderInterface* const reader,
FromProto(pose_graph_proto.constraint())); FromProto(pose_graph_proto.constraint()));
} }
CHECK(reader->eof()); CHECK(reader->eof());
return trajectory_remapping;
}
std::map<int, int> MapBuilder::LoadStateFromFile(
const std::string& state_filename) {
const std::string suffix = ".pbstream";
if (state_filename.substr(
std::max<int>(state_filename.size() - suffix.size(), 0)) != suffix) {
LOG(WARNING) << "The file containing the state should be a "
".pbstream file.";
}
LOG(INFO) << "Loading saved state '" << state_filename << "'...";
io::ProtoStreamReader stream(state_filename);
return LoadState(&stream, true);
} }
} // namespace mapping } // namespace mapping

View File

@ -58,9 +58,11 @@ class MapBuilder : public MapBuilderInterface {
void SerializeState(io::ProtoStreamWriterInterface *writer) override; void SerializeState(io::ProtoStreamWriterInterface *writer) override;
void LoadState(io::ProtoStreamReaderInterface *reader, std::map<int, int> LoadState(io::ProtoStreamReaderInterface *reader,
bool load_frozen_state) override; bool load_frozen_state) override;
std::map<int, int> LoadStateFromFile(const std::string &filename) override;
mapping::PoseGraphInterface *pose_graph() override { mapping::PoseGraphInterface *pose_graph() override {
return pose_graph_.get(); return pose_graph_.get();
} }

View File

@ -80,9 +80,15 @@ class MapBuilderInterface {
// Serializes the current state to a proto stream. // Serializes the current state to a proto stream.
virtual void SerializeState(io::ProtoStreamWriterInterface* writer) = 0; virtual void SerializeState(io::ProtoStreamWriterInterface* writer) = 0;
// Loads the SLAM state from a proto stream. // Loads the SLAM state from a proto stream. Returns the remapping of new
virtual void LoadState(io::ProtoStreamReaderInterface* reader, // trajectory_ids.
bool load_frozen_state) = 0; virtual std::map<int /* trajectory id in proto */, int /* trajectory id */>
LoadState(io::ProtoStreamReaderInterface* reader, bool load_frozen_state) = 0;
// Loads the SLAM state froma a pbstream file. Returns the remapping of new
// trajectory_ids.
virtual std::map<int /* trajectory id in proto */, int /* trajectory id */>
LoadStateFromFile(const std::string& filename) = 0;
virtual int num_trajectory_builders() const = 0; virtual int num_trajectory_builders() const = 0;