00001 /* 00002 * Copyright 2016 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_SUBMAPS_H_ 00018 #define CARTOGRAPHER_MAPPING_SUBMAPS_H_ 00019 00020 #include <memory> 00021 #include <vector> 00022 00023 #include "Eigen/Geometry" 00024 #include "cartographer/common/math.h" 00025 #include "cartographer/common/port.h" 00026 #include "cartographer/mapping/id.h" 00027 #include "cartographer/mapping/probability_values.h" 00028 #include "cartographer/mapping/proto/serialization.pb.h" 00029 #include "cartographer/mapping/proto/submap_visualization.pb.h" 00030 #include "cartographer/mapping/trajectory_node.h" 00031 #include "glog/logging.h" 00032 00033 namespace cartographer { 00034 namespace mapping { 00035 00036 // Converts the given probability to log odds. 00037 inline float Logit(float probability) { 00038 return std::log(probability / (1.f - probability)); 00039 } 00040 00041 const float kMaxLogOdds = Logit(kMaxProbability); 00042 const float kMinLogOdds = Logit(kMinProbability); 00043 00044 // Converts a probability to a log odds integer. 0 means unknown, [kMinLogOdds, 00045 // kMaxLogOdds] is mapped to [1, 255]. 00046 inline uint8 ProbabilityToLogOddsInteger(const float probability) { 00047 const int value = common::RoundToInt((Logit(probability) - kMinLogOdds) * 00048 254.f / (kMaxLogOdds - kMinLogOdds)) + 00049 1; 00050 CHECK_LE(1, value); 00051 CHECK_GE(255, value); 00052 return value; 00053 } 00054 00055 // An individual submap, which has a 'local_pose' in the local map frame, keeps 00056 // track of how many range data were inserted into it, and sets 00057 // 'insertion_finished' when the map no longer changes and is ready for loop 00058 // closing. 00059 class Submap { 00060 public: 00061 Submap(const transform::Rigid3d& local_submap_pose) 00062 : local_pose_(local_submap_pose) {} 00063 virtual ~Submap() {} 00064 00065 virtual proto::Submap ToProto(bool include_grid_data) const = 0; 00066 virtual void UpdateFromProto(const proto::Submap& proto) = 0; 00067 00068 // Fills data into the 'response'. 00069 virtual void ToResponseProto( 00070 const transform::Rigid3d& global_submap_pose, 00071 proto::SubmapQuery::Response* response) const = 0; 00072 00073 // Pose of this submap in the local map frame. 00074 transform::Rigid3d local_pose() const { return local_pose_; } 00075 00076 // Number of RangeData inserted. 00077 int num_range_data() const { return num_range_data_; } 00078 void set_num_range_data(const int num_range_data) { 00079 num_range_data_ = num_range_data; 00080 } 00081 00082 bool insertion_finished() const { return insertion_finished_; } 00083 void set_insertion_finished(bool insertion_finished) { 00084 insertion_finished_ = insertion_finished; 00085 } 00086 00087 private: 00088 const transform::Rigid3d local_pose_; 00089 int num_range_data_ = 0; 00090 bool insertion_finished_ = false; 00091 }; 00092 00093 } // namespace mapping 00094 } // namespace cartographer 00095 00096 #endif // CARTOGRAPHER_MAPPING_SUBMAPS_H_