Move 'finished' getter to the base class. (#803)

* Move 'finished' getter to the base class.

* Ran clang-format.

* Ran clang-format.
master
Alexander Belyaev 2018-01-16 14:20:33 +01:00 committed by GitHub
parent 712c7e3e39
commit 53c2a6b58f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 29 additions and 26 deletions

View File

@ -67,25 +67,32 @@ class Submap {
bool include_probability_grid_data) const = 0; bool include_probability_grid_data) const = 0;
virtual void UpdateFromProto(const proto::Submap& proto) = 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. // Pose of this submap in the local map frame.
transform::Rigid3d local_pose() const { return local_pose_; } transform::Rigid3d local_pose() const { return local_pose_; }
// Number of RangeData inserted. // Number of RangeData inserted.
int num_range_data() const { return num_range_data_; } int num_range_data() const { return num_range_data_; }
// Fills data into the 'response'. // Whether the submap is finished or not.
virtual void ToResponseProto( bool finished() const { return finished_; }
const transform::Rigid3d& global_submap_pose,
proto::SubmapQuery::Response* response) const = 0;
void SetNumRangeData(const int num_range_data) { void SetNumRangeData(const int num_range_data) {
num_range_data_ = num_range_data; num_range_data_ = num_range_data;
} }
void SetFinished(bool finished) { finished_ = finished; }
private: private:
const transform::Rigid3d local_pose_; const transform::Rigid3d local_pose_;
int num_range_data_ = 0; int num_range_data_ = 0;
bool finished_ = false;
}; };
} // namespace mapping } // namespace mapping
} // namespace cartographer } // namespace cartographer

View File

@ -71,7 +71,7 @@ Submap::Submap(const mapping::proto::Submap2D& proto)
: mapping::Submap(transform::ToRigid3(proto.local_pose())), : mapping::Submap(transform::ToRigid3(proto.local_pose())),
probability_grid_(ProbabilityGrid(proto.probability_grid())) { probability_grid_(ProbabilityGrid(proto.probability_grid())) {
SetNumRangeData(proto.num_range_data()); SetNumRangeData(proto.num_range_data());
finished_ = proto.finished(); SetFinished(proto.finished());
} }
void Submap::ToProto(mapping::proto::Submap* const proto, 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(); auto* const submap_2d = proto->mutable_submap_2d();
*submap_2d->mutable_local_pose() = transform::ToProto(local_pose()); *submap_2d->mutable_local_pose() = transform::ToProto(local_pose());
submap_2d->set_num_range_data(num_range_data()); submap_2d->set_num_range_data(num_range_data());
submap_2d->set_finished(finished_); submap_2d->set_finished(finished());
if (include_probability_grid_data) { if (include_probability_grid_data) {
*submap_2d->mutable_probability_grid() = probability_grid_.ToProto(); *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()); CHECK(proto.has_submap_2d());
const auto& submap_2d = proto.submap_2d(); const auto& submap_2d = proto.submap_2d();
SetNumRangeData(submap_2d.num_range_data()); SetNumRangeData(submap_2d.num_range_data());
finished_ = submap_2d.finished(); SetFinished(submap_2d.finished());
if (submap_2d.has_probability_grid()) { if (submap_2d.has_probability_grid()) {
probability_grid_ = ProbabilityGrid(submap_2d.probability_grid()); probability_grid_ = ProbabilityGrid(submap_2d.probability_grid());
} }
@ -145,15 +145,15 @@ void Submap::ToResponseProto(
void Submap::InsertRangeData(const sensor::RangeData& range_data, void Submap::InsertRangeData(const sensor::RangeData& range_data,
const RangeDataInserter& range_data_inserter) { const RangeDataInserter& range_data_inserter) {
CHECK(!finished_); CHECK(!finished());
range_data_inserter.Insert(range_data, &probability_grid_); range_data_inserter.Insert(range_data, &probability_grid_);
SetNumRangeData(num_range_data() + 1); SetNumRangeData(num_range_data() + 1);
} }
void Submap::Finish() { void Submap::Finish() {
CHECK(!finished_); CHECK(!finished());
probability_grid_ = ComputeCroppedProbabilityGrid(probability_grid_); probability_grid_ = ComputeCroppedProbabilityGrid(probability_grid_);
finished_ = true; SetFinished(true);
} }
ActiveSubmaps::ActiveSubmaps(const proto::SubmapsOptions& options) ActiveSubmaps::ActiveSubmaps(const proto::SubmapsOptions& options)

View File

@ -51,13 +51,12 @@ class Submap : public mapping::Submap {
bool include_probability_grid_data) const override; bool include_probability_grid_data) const override;
void UpdateFromProto(const mapping::proto::Submap& proto) override; void UpdateFromProto(const mapping::proto::Submap& proto) override;
const ProbabilityGrid& probability_grid() const { return probability_grid_; }
bool finished() const { return finished_; }
void ToResponseProto( void ToResponseProto(
const transform::Rigid3d& global_submap_pose, const transform::Rigid3d& global_submap_pose,
mapping::proto::SubmapQuery::Response* response) const override; 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 // Insert 'range_data' into this submap using 'range_data_inserter'. The
// submap must not be finished yet. // submap must not be finished yet.
void InsertRangeData(const sensor::RangeData& range_data, void InsertRangeData(const sensor::RangeData& range_data,
@ -66,7 +65,6 @@ class Submap : public mapping::Submap {
private: private:
ProbabilityGrid probability_grid_; ProbabilityGrid probability_grid_;
bool finished_ = false;
}; };
// Except during initialization when only a single submap exists, there are // Except during initialization when only a single submap exists, there are

View File

@ -212,7 +212,7 @@ Submap::Submap(const mapping::proto::Submap3D& proto)
low_resolution_hybrid_grid_( low_resolution_hybrid_grid_(
common::make_unique<HybridGrid>(proto.low_resolution_hybrid_grid())) { common::make_unique<HybridGrid>(proto.low_resolution_hybrid_grid())) {
SetNumRangeData(proto.num_range_data()); SetNumRangeData(proto.num_range_data());
finished_ = proto.finished(); SetFinished(proto.finished());
} }
void Submap::ToProto(mapping::proto::Submap* const proto, 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(); auto* const submap_3d = proto->mutable_submap_3d();
*submap_3d->mutable_local_pose() = transform::ToProto(local_pose()); *submap_3d->mutable_local_pose() = transform::ToProto(local_pose());
submap_3d->set_num_range_data(num_range_data()); submap_3d->set_num_range_data(num_range_data());
submap_3d->set_finished(finished_); submap_3d->set_finished(finished());
if (include_probability_grid_data) { if (include_probability_grid_data) {
*submap_3d->mutable_high_resolution_hybrid_grid() = *submap_3d->mutable_high_resolution_hybrid_grid() =
high_resolution_hybrid_grid().ToProto(); high_resolution_hybrid_grid().ToProto();
@ -233,7 +233,7 @@ void Submap::UpdateFromProto(const mapping::proto::Submap& proto) {
CHECK(proto.has_submap_3d()); CHECK(proto.has_submap_3d());
const auto& submap_3d = proto.submap_3d(); const auto& submap_3d = proto.submap_3d();
SetNumRangeData(submap_3d.num_range_data()); SetNumRangeData(submap_3d.num_range_data());
finished_ = submap_3d.finished(); SetFinished(submap_3d.finished());
if (submap_3d.has_high_resolution_hybrid_grid()) { if (submap_3d.has_high_resolution_hybrid_grid()) {
high_resolution_hybrid_grid_ = high_resolution_hybrid_grid_ =
submap_3d.has_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, void Submap::InsertRangeData(const sensor::RangeData& range_data,
const RangeDataInserter& range_data_inserter, const RangeDataInserter& range_data_inserter,
const int high_resolution_max_range) { const int high_resolution_max_range) {
CHECK(!finished_); CHECK(!finished());
const sensor::RangeData transformed_range_data = sensor::TransformRangeData( const sensor::RangeData transformed_range_data = sensor::TransformRangeData(
range_data, local_pose().inverse().cast<float>()); range_data, local_pose().inverse().cast<float>());
range_data_inserter.Insert( range_data_inserter.Insert(
@ -277,8 +277,8 @@ void Submap::InsertRangeData(const sensor::RangeData& range_data,
} }
void Submap::Finish() { void Submap::Finish() {
CHECK(!finished_); CHECK(!finished());
finished_ = true; SetFinished(true);
} }
ActiveSubmaps::ActiveSubmaps(const proto::SubmapsOptions& options) ActiveSubmaps::ActiveSubmaps(const proto::SubmapsOptions& options)

View File

@ -51,17 +51,16 @@ class Submap : public mapping::Submap {
bool include_probability_grid_data) const override; bool include_probability_grid_data) const override;
void UpdateFromProto(const mapping::proto::Submap& proto) 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 { const HybridGrid& high_resolution_hybrid_grid() const {
return *high_resolution_hybrid_grid_; return *high_resolution_hybrid_grid_;
} }
const HybridGrid& low_resolution_hybrid_grid() const { const HybridGrid& low_resolution_hybrid_grid() const {
return *low_resolution_hybrid_grid_; 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 // Insert 'range_data' into this submap using 'range_data_inserter'. The
// submap must not be finished yet. // submap must not be finished yet.
@ -73,7 +72,6 @@ class Submap : public mapping::Submap {
private: private:
std::unique_ptr<HybridGrid> high_resolution_hybrid_grid_; std::unique_ptr<HybridGrid> high_resolution_hybrid_grid_;
std::unique_ptr<HybridGrid> low_resolution_hybrid_grid_; std::unique_ptr<HybridGrid> low_resolution_hybrid_grid_;
bool finished_ = false;
}; };
// Except during initialization when only a single submap exists, there are // Except during initialization when only a single submap exists, there are