diff --git a/cartographer/mapping/submaps.h b/cartographer/mapping/submaps.h index 840ad50..dd77f5a 100644 --- a/cartographer/mapping/submaps.h +++ b/cartographer/mapping/submaps.h @@ -67,25 +67,32 @@ class Submap { bool include_probability_grid_data) const = 0; virtual void UpdateFromProto(const proto::Submap& proto) = 0; + // Fills data into the 'response'. + virtual void ToResponseProto( + const transform::Rigid3d& global_submap_pose, + proto::SubmapQuery::Response* response) const = 0; + // Pose of this submap in the local map frame. transform::Rigid3d local_pose() const { return local_pose_; } // Number of RangeData inserted. int num_range_data() const { return num_range_data_; } - // Fills data into the 'response'. - virtual void ToResponseProto( - const transform::Rigid3d& global_submap_pose, - proto::SubmapQuery::Response* response) const = 0; + // Whether the submap is finished or not. + bool finished() const { return finished_; } void SetNumRangeData(const int num_range_data) { num_range_data_ = num_range_data; } + void SetFinished(bool finished) { finished_ = finished; } + private: const transform::Rigid3d local_pose_; int num_range_data_ = 0; + bool finished_ = false; }; + } // namespace mapping } // namespace cartographer diff --git a/cartographer/mapping_2d/submaps.cc b/cartographer/mapping_2d/submaps.cc index aef515a..9fc5598 100644 --- a/cartographer/mapping_2d/submaps.cc +++ b/cartographer/mapping_2d/submaps.cc @@ -71,7 +71,7 @@ Submap::Submap(const mapping::proto::Submap2D& proto) : mapping::Submap(transform::ToRigid3(proto.local_pose())), probability_grid_(ProbabilityGrid(proto.probability_grid())) { SetNumRangeData(proto.num_range_data()); - finished_ = proto.finished(); + SetFinished(proto.finished()); } void Submap::ToProto(mapping::proto::Submap* const proto, @@ -79,7 +79,7 @@ void Submap::ToProto(mapping::proto::Submap* const proto, 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->set_finished(finished()); if (include_probability_grid_data) { *submap_2d->mutable_probability_grid() = probability_grid_.ToProto(); } @@ -89,7 +89,7 @@ void Submap::UpdateFromProto(const mapping::proto::Submap& proto) { CHECK(proto.has_submap_2d()); const auto& submap_2d = proto.submap_2d(); SetNumRangeData(submap_2d.num_range_data()); - finished_ = submap_2d.finished(); + SetFinished(submap_2d.finished()); if (submap_2d.has_probability_grid()) { probability_grid_ = ProbabilityGrid(submap_2d.probability_grid()); } @@ -145,15 +145,15 @@ void Submap::ToResponseProto( void Submap::InsertRangeData(const sensor::RangeData& range_data, const RangeDataInserter& range_data_inserter) { - CHECK(!finished_); + CHECK(!finished()); range_data_inserter.Insert(range_data, &probability_grid_); SetNumRangeData(num_range_data() + 1); } void Submap::Finish() { - CHECK(!finished_); + CHECK(!finished()); probability_grid_ = ComputeCroppedProbabilityGrid(probability_grid_); - finished_ = true; + SetFinished(true); } ActiveSubmaps::ActiveSubmaps(const proto::SubmapsOptions& options) diff --git a/cartographer/mapping_2d/submaps.h b/cartographer/mapping_2d/submaps.h index 04ed518..67da5d8 100644 --- a/cartographer/mapping_2d/submaps.h +++ b/cartographer/mapping_2d/submaps.h @@ -51,13 +51,12 @@ class Submap : public mapping::Submap { bool include_probability_grid_data) const override; void UpdateFromProto(const mapping::proto::Submap& proto) override; - const ProbabilityGrid& probability_grid() const { return probability_grid_; } - bool finished() const { return finished_; } - void ToResponseProto( const transform::Rigid3d& global_submap_pose, mapping::proto::SubmapQuery::Response* response) const override; + const ProbabilityGrid& probability_grid() const { return probability_grid_; } + // Insert 'range_data' into this submap using 'range_data_inserter'. The // submap must not be finished yet. void InsertRangeData(const sensor::RangeData& range_data, @@ -66,7 +65,6 @@ class Submap : public mapping::Submap { private: ProbabilityGrid probability_grid_; - bool finished_ = false; }; // Except during initialization when only a single submap exists, there are diff --git a/cartographer/mapping_3d/submaps.cc b/cartographer/mapping_3d/submaps.cc index 5a425d0..22acaea 100644 --- a/cartographer/mapping_3d/submaps.cc +++ b/cartographer/mapping_3d/submaps.cc @@ -212,7 +212,7 @@ Submap::Submap(const mapping::proto::Submap3D& proto) low_resolution_hybrid_grid_( common::make_unique(proto.low_resolution_hybrid_grid())) { SetNumRangeData(proto.num_range_data()); - finished_ = proto.finished(); + SetFinished(proto.finished()); } void Submap::ToProto(mapping::proto::Submap* const proto, @@ -220,7 +220,7 @@ void Submap::ToProto(mapping::proto::Submap* const proto, 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->set_finished(finished()); if (include_probability_grid_data) { *submap_3d->mutable_high_resolution_hybrid_grid() = high_resolution_hybrid_grid().ToProto(); @@ -233,7 +233,7 @@ void Submap::UpdateFromProto(const mapping::proto::Submap& proto) { CHECK(proto.has_submap_3d()); const auto& submap_3d = proto.submap_3d(); SetNumRangeData(submap_3d.num_range_data()); - finished_ = submap_3d.finished(); + SetFinished(submap_3d.finished()); if (submap_3d.has_high_resolution_hybrid_grid()) { high_resolution_hybrid_grid_ = submap_3d.has_high_resolution_hybrid_grid() @@ -264,7 +264,7 @@ void Submap::ToResponseProto( void Submap::InsertRangeData(const sensor::RangeData& range_data, const RangeDataInserter& range_data_inserter, const int high_resolution_max_range) { - CHECK(!finished_); + CHECK(!finished()); const sensor::RangeData transformed_range_data = sensor::TransformRangeData( range_data, local_pose().inverse().cast()); range_data_inserter.Insert( @@ -277,8 +277,8 @@ void Submap::InsertRangeData(const sensor::RangeData& range_data, } void Submap::Finish() { - CHECK(!finished_); - finished_ = true; + CHECK(!finished()); + SetFinished(true); } ActiveSubmaps::ActiveSubmaps(const proto::SubmapsOptions& options) diff --git a/cartographer/mapping_3d/submaps.h b/cartographer/mapping_3d/submaps.h index d6635ee..51212f9 100644 --- a/cartographer/mapping_3d/submaps.h +++ b/cartographer/mapping_3d/submaps.h @@ -51,17 +51,16 @@ class Submap : public mapping::Submap { bool include_probability_grid_data) const override; void UpdateFromProto(const mapping::proto::Submap& proto) override; + void ToResponseProto( + const transform::Rigid3d& global_submap_pose, + mapping::proto::SubmapQuery::Response* response) const override; + const HybridGrid& high_resolution_hybrid_grid() const { return *high_resolution_hybrid_grid_; } const HybridGrid& low_resolution_hybrid_grid() const { return *low_resolution_hybrid_grid_; } - bool finished() const { return finished_; } - - void ToResponseProto( - const transform::Rigid3d& global_submap_pose, - mapping::proto::SubmapQuery::Response* response) const override; // Insert 'range_data' into this submap using 'range_data_inserter'. The // submap must not be finished yet. @@ -73,7 +72,6 @@ class Submap : public mapping::Submap { private: std::unique_ptr high_resolution_hybrid_grid_; std::unique_ptr low_resolution_hybrid_grid_; - bool finished_ = false; }; // Except during initialization when only a single submap exists, there are