00001 /* 00002 * Copyright 2018 The Cartographer Authors 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 00017 #ifndef CARTOGRAPHER_MAPPING_INTERNAL_SUBMAP_CONTROLLER_H 00018 #define CARTOGRAPHER_MAPPING_INTERNAL_SUBMAP_CONTROLLER_H 00019 00020 #include "cartographer/mapping/2d/submap_2d.h" 00021 #include "cartographer/mapping/3d/submap_3d.h" 00022 #include "cartographer/mapping/id.h" 00023 #include "cartographer/mapping/proto/serialization.pb.h" 00024 00025 namespace cartographer { 00026 namespace mapping { 00027 00028 template <class SubmapType> 00029 class SubmapController { 00030 public: 00031 std::shared_ptr<SubmapType> UpdateSubmap( 00032 const mapping::proto::Submap& proto) { 00033 mapping::SubmapId submap_id{proto.submap_id().trajectory_id(), 00034 proto.submap_id().submap_index()}; 00035 std::shared_ptr<SubmapType> submap_ptr; 00036 auto submap_it = unfinished_submaps_.find(submap_id); 00037 if (submap_it == unfinished_submaps_.end()) { 00038 submap_ptr = CreateSubmap(proto); 00039 if (submap_ptr) { 00040 unfinished_submaps_.Insert(submap_id, submap_ptr); 00041 } 00042 return submap_ptr; 00043 } 00044 submap_ptr = submap_it->data; 00045 CHECK(submap_ptr); 00046 submap_ptr->UpdateFromProto(proto); 00047 00048 // If the submap was just finished by the recent update, remove it from 00049 // the list of unfinished submaps. 00050 if (submap_ptr->insertion_finished()) { 00051 unfinished_submaps_.Trim(submap_id); 00052 } else { 00053 // If the submap is unfinished set the 'num_range_data' to 0 since we 00054 // haven't changed the HybridGrid. 00055 submap_ptr->set_num_range_data(0); 00056 } 00057 return submap_ptr; 00058 } 00059 00060 private: 00061 std::shared_ptr<SubmapType> CreateSubmap(const mapping::proto::Submap& proto); 00062 00063 mapping::MapById<mapping::SubmapId, std::shared_ptr<SubmapType>> 00064 unfinished_submaps_; 00065 00066 ValueConversionTables conversion_tables_; 00067 }; 00068 00069 template <> 00070 std::shared_ptr<mapping::Submap2D> 00071 SubmapController<mapping::Submap2D>::CreateSubmap( 00072 const mapping::proto::Submap& proto); 00073 template <> 00074 std::shared_ptr<mapping::Submap3D> 00075 SubmapController<mapping::Submap3D>::CreateSubmap( 00076 const mapping::proto::Submap& proto); 00077 00078 } // namespace mapping 00079 } // namespace cartographer 00080 00081 #endif // CARTOGRAPHER_MAPPING_INTERNAL_SUBMAP_CONTROLLER_H