Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #include "cartographer/mapping/value_conversion_tables.h"
00018
00019 #include "absl/memory/memory.h"
00020 #include "glog/logging.h"
00021
00022 namespace cartographer {
00023 namespace mapping {
00024 namespace {
00025
00026 constexpr uint16 kUpdateMarker = 1u << 15;
00027
00028
00029 float SlowValueToBoundedFloat(const uint16 value, const uint16 unknown_value,
00030 const float unknown_result,
00031 const float lower_bound,
00032 const float upper_bound) {
00033 CHECK_LE(value, 32767);
00034 if (value == unknown_value) return unknown_result;
00035 const float kScale = (upper_bound - lower_bound) / 32766.f;
00036 return value * kScale + (lower_bound - kScale);
00037 }
00038
00039 std::unique_ptr<std::vector<float>> PrecomputeValueToBoundedFloat(
00040 const uint16 unknown_value, const float unknown_result,
00041 const float lower_bound, const float upper_bound) {
00042 auto result = absl::make_unique<std::vector<float>>();
00043 size_t num_values = std::numeric_limits<uint16>::max() + 1;
00044 result->reserve(num_values);
00045 for (size_t value = 0; value != num_values; ++value) {
00046 result->push_back(SlowValueToBoundedFloat(
00047 static_cast<uint16>(value) & ~kUpdateMarker, unknown_value,
00048 unknown_result, lower_bound, upper_bound));
00049 }
00050 return result;
00051 }
00052 }
00053
00054 const std::vector<float>* ValueConversionTables::GetConversionTable(
00055 float unknown_result, float lower_bound, float upper_bound) {
00056 std::tuple<float, float, float> bounds =
00057 std::make_tuple(unknown_result, lower_bound, upper_bound);
00058 auto lookup_table_iterator = bounds_to_lookup_table_.find(bounds);
00059 if (lookup_table_iterator == bounds_to_lookup_table_.end()) {
00060 auto insertion_result = bounds_to_lookup_table_.emplace(
00061 bounds, PrecomputeValueToBoundedFloat(0, unknown_result, lower_bound,
00062 upper_bound));
00063 return insertion_result.first->second.get();
00064 } else {
00065 return lookup_table_iterator->second.get();
00066 }
00067 }
00068
00069 }
00070 }