diff --git a/cartographer/mapping/map_builder.cc b/cartographer/mapping/map_builder.cc index d36de3b..4ecb5e1 100644 --- a/cartographer/mapping/map_builder.cc +++ b/cartographer/mapping/map_builder.cc @@ -173,7 +173,8 @@ void MapBuilder::SerializeState(io::ProtoStreamWriter* const writer) { submap_id_data.id.trajectory_id); submap_proto->mutable_submap_id()->set_submap_index( submap_id_data.id.submap_index); - submap_id_data.data.submap->ToProto(submap_proto); + submap_id_data.data.submap->ToProto( + submap_proto, true /* include_probability_grid_data */); writer->WriteProto(proto); } } diff --git a/cartographer/mapping/submaps.h b/cartographer/mapping/submaps.h index 6ff37f1..840ad50 100644 --- a/cartographer/mapping/submaps.h +++ b/cartographer/mapping/submaps.h @@ -63,7 +63,8 @@ class Submap { : local_pose_(local_submap_pose) {} virtual ~Submap() {} - virtual void ToProto(proto::Submap* proto) const = 0; + virtual void ToProto(proto::Submap* proto, + bool include_probability_grid_data) const = 0; virtual void UpdateFromProto(const proto::Submap& proto) = 0; // Pose of this submap in the local map frame. diff --git a/cartographer/mapping_2d/submaps.cc b/cartographer/mapping_2d/submaps.cc index 9eac079..aef515a 100644 --- a/cartographer/mapping_2d/submaps.cc +++ b/cartographer/mapping_2d/submaps.cc @@ -74,12 +74,15 @@ Submap::Submap(const mapping::proto::Submap2D& proto) finished_ = proto.finished(); } -void Submap::ToProto(mapping::proto::Submap* const proto) const { +void Submap::ToProto(mapping::proto::Submap* const proto, + bool include_probability_grid_data) const { auto* const submap_2d = proto->mutable_submap_2d(); *submap_2d->mutable_local_pose() = transform::ToProto(local_pose()); submap_2d->set_num_range_data(num_range_data()); submap_2d->set_finished(finished_); - *submap_2d->mutable_probability_grid() = probability_grid_.ToProto(); + if (include_probability_grid_data) { + *submap_2d->mutable_probability_grid() = probability_grid_.ToProto(); + } } void Submap::UpdateFromProto(const mapping::proto::Submap& proto) { diff --git a/cartographer/mapping_2d/submaps.h b/cartographer/mapping_2d/submaps.h index 67c8109..04ed518 100644 --- a/cartographer/mapping_2d/submaps.h +++ b/cartographer/mapping_2d/submaps.h @@ -47,7 +47,8 @@ class Submap : public mapping::Submap { Submap(const MapLimits& limits, const Eigen::Vector2f& origin); explicit Submap(const mapping::proto::Submap2D& proto); - void ToProto(mapping::proto::Submap* proto) const override; + void ToProto(mapping::proto::Submap* proto, + bool include_probability_grid_data) const override; void UpdateFromProto(const mapping::proto::Submap& proto) override; const ProbabilityGrid& probability_grid() const { return probability_grid_; } diff --git a/cartographer/mapping_2d/submaps_test.cc b/cartographer/mapping_2d/submaps_test.cc index a89d049..9981489 100644 --- a/cartographer/mapping_2d/submaps_test.cc +++ b/cartographer/mapping_2d/submaps_test.cc @@ -72,7 +72,7 @@ TEST(SubmapsTest, ToFromProto) { Submap expected(MapLimits(1., Eigen::Vector2d(2., 3.), CellLimits(100, 110)), Eigen::Vector2f(4.f, 5.f)); mapping::proto::Submap proto; - expected.ToProto(&proto); + expected.ToProto(&proto, true /* include_probability_grid_data */); EXPECT_TRUE(proto.has_submap_2d()); EXPECT_FALSE(proto.has_submap_3d()); const auto actual = Submap(proto.submap_2d()); diff --git a/cartographer/mapping_3d/submaps.cc b/cartographer/mapping_3d/submaps.cc index be4e426..5a425d0 100644 --- a/cartographer/mapping_3d/submaps.cc +++ b/cartographer/mapping_3d/submaps.cc @@ -215,15 +215,18 @@ Submap::Submap(const mapping::proto::Submap3D& proto) finished_ = proto.finished(); } -void Submap::ToProto(mapping::proto::Submap* const proto) const { +void Submap::ToProto(mapping::proto::Submap* const proto, + bool include_probability_grid_data) const { auto* const submap_3d = proto->mutable_submap_3d(); *submap_3d->mutable_local_pose() = transform::ToProto(local_pose()); submap_3d->set_num_range_data(num_range_data()); submap_3d->set_finished(finished_); - *submap_3d->mutable_high_resolution_hybrid_grid() = - high_resolution_hybrid_grid().ToProto(); - *submap_3d->mutable_low_resolution_hybrid_grid() = - low_resolution_hybrid_grid().ToProto(); + if (include_probability_grid_data) { + *submap_3d->mutable_high_resolution_hybrid_grid() = + high_resolution_hybrid_grid().ToProto(); + *submap_3d->mutable_low_resolution_hybrid_grid() = + low_resolution_hybrid_grid().ToProto(); + } } void Submap::UpdateFromProto(const mapping::proto::Submap& proto) { diff --git a/cartographer/mapping_3d/submaps.h b/cartographer/mapping_3d/submaps.h index cd16e60..d6635ee 100644 --- a/cartographer/mapping_3d/submaps.h +++ b/cartographer/mapping_3d/submaps.h @@ -47,7 +47,8 @@ class Submap : public mapping::Submap { const transform::Rigid3d& local_submap_pose); explicit Submap(const mapping::proto::Submap3D& proto); - void ToProto(mapping::proto::Submap* proto) const override; + void ToProto(mapping::proto::Submap* proto, + bool include_probability_grid_data) const override; void UpdateFromProto(const mapping::proto::Submap& proto) override; const HybridGrid& high_resolution_hybrid_grid() const { diff --git a/cartographer/mapping_3d/submaps_test.cc b/cartographer/mapping_3d/submaps_test.cc index bb48762..36776bc 100644 --- a/cartographer/mapping_3d/submaps_test.cc +++ b/cartographer/mapping_3d/submaps_test.cc @@ -28,7 +28,7 @@ TEST(SubmapsTest, ToFromProto) { transform::Rigid3d(Eigen::Vector3d(1., 2., 0.), Eigen::Quaterniond(0., 0., 0., 1.))); mapping::proto::Submap proto; - expected.ToProto(&proto); + expected.ToProto(&proto, true /* include_probability_grid_data */); EXPECT_FALSE(proto.has_submap_2d()); EXPECT_TRUE(proto.has_submap_3d()); const auto actual = Submap(proto.submap_3d());