submap_controller.h
Go to the documentation of this file.
1 /*
2  * Copyright 2018 The Cartographer Authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef CARTOGRAPHER_MAPPING_INTERNAL_SUBMAP_CONTROLLER_H
18 #define CARTOGRAPHER_MAPPING_INTERNAL_SUBMAP_CONTROLLER_H
19 
23 #include "cartographer/mapping/proto/serialization.pb.h"
24 
25 namespace cartographer {
26 namespace mapping {
27 
28 template <class SubmapType>
30  public:
31  std::shared_ptr<SubmapType> UpdateSubmap(
32  const mapping::proto::Submap& proto) {
33  mapping::SubmapId submap_id{proto.submap_id().trajectory_id(),
34  proto.submap_id().submap_index()};
35  std::shared_ptr<SubmapType> submap_ptr;
36  auto submap_it = unfinished_submaps_.find(submap_id);
37  if (submap_it == unfinished_submaps_.end()) {
38  submap_ptr = CreateSubmap(proto);
39  unfinished_submaps_.Insert(submap_id, submap_ptr);
40  return submap_ptr;
41  }
42  submap_ptr = submap_it->data;
43  CHECK(submap_ptr);
44  submap_ptr->UpdateFromProto(proto);
45 
46  // If the submap was just finished by the recent update, remove it from
47  // the list of unfinished submaps.
48  if (submap_ptr->finished()) {
49  unfinished_submaps_.Trim(submap_id);
50  } else {
51  // If the submap is unfinished set the 'num_range_data' to 0 since we
52  // haven't changed the HybridGrid.
53  submap_ptr->set_num_range_data(0);
54  }
55  return submap_ptr;
56  }
57 
58  private:
59  std::shared_ptr<SubmapType> CreateSubmap(const mapping::proto::Submap& proto);
60 
63 };
64 
65 template <>
66 std::shared_ptr<mapping::Submap2D>
68  const mapping::proto::Submap& proto);
69 template <>
70 std::shared_ptr<mapping::Submap3D>
72  const mapping::proto::Submap& proto);
73 
74 } // namespace mapping
75 } // namespace cartographer
76 
77 #endif // CARTOGRAPHER_MAPPING_INTERNAL_SUBMAP_CONTROLLER_H
std::shared_ptr< SubmapType > CreateSubmap(const mapping::proto::Submap &proto)
mapping::MapById< mapping::SubmapId, std::shared_ptr< SubmapType > > unfinished_submaps_
std::shared_ptr< SubmapType > UpdateSubmap(const mapping::proto::Submap &proto)


cartographer
Author(s): The Cartographer Authors
autogenerated on Mon Feb 28 2022 22:00:58