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/probability_values.h"
00018
00019 #include "absl/memory/memory.h"
00020
00021 namespace cartographer {
00022 namespace mapping {
00023
00024 namespace {
00025
00026 constexpr int kValueCount = 32768;
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_LT(value, kValueCount);
00034 if (value == unknown_value) return unknown_result;
00035 const float kScale = (upper_bound - lower_bound) / (kValueCount - 2.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
00044
00045 constexpr int kRepetitionCount = 2;
00046 result->reserve(kRepetitionCount * kValueCount);
00047 for (int repeat = 0; repeat != kRepetitionCount; ++repeat) {
00048 for (int value = 0; value != kValueCount; ++value) {
00049 result->push_back(SlowValueToBoundedFloat(
00050 value, unknown_value, unknown_result, lower_bound, upper_bound));
00051 }
00052 }
00053 return result;
00054 }
00055
00056 std::unique_ptr<std::vector<float>> PrecomputeValueToProbability() {
00057 return PrecomputeValueToBoundedFloat(kUnknownProbabilityValue,
00058 kMinProbability, kMinProbability,
00059 kMaxProbability);
00060 }
00061
00062 std::unique_ptr<std::vector<float>> PrecomputeValueToCorrespondenceCost() {
00063 return PrecomputeValueToBoundedFloat(
00064 kUnknownCorrespondenceValue, kMaxCorrespondenceCost,
00065 kMinCorrespondenceCost, kMaxCorrespondenceCost);
00066 }
00067
00068 }
00069
00070 const std::vector<float>* const kValueToProbability =
00071 PrecomputeValueToProbability().release();
00072
00073 const std::vector<float>* const kValueToCorrespondenceCost =
00074 PrecomputeValueToCorrespondenceCost().release();
00075
00076 std::vector<uint16> ComputeLookupTableToApplyOdds(const float odds) {
00077 std::vector<uint16> result;
00078 result.reserve(kValueCount);
00079 result.push_back(ProbabilityToValue(ProbabilityFromOdds(odds)) +
00080 kUpdateMarker);
00081 for (int cell = 1; cell != kValueCount; ++cell) {
00082 result.push_back(ProbabilityToValue(ProbabilityFromOdds(
00083 odds * Odds((*kValueToProbability)[cell]))) +
00084 kUpdateMarker);
00085 }
00086 return result;
00087 }
00088
00089 std::vector<uint16> ComputeLookupTableToApplyCorrespondenceCostOdds(
00090 float odds) {
00091 std::vector<uint16> result;
00092 result.reserve(kValueCount);
00093 result.push_back(CorrespondenceCostToValue(ProbabilityToCorrespondenceCost(
00094 ProbabilityFromOdds(odds))) +
00095 kUpdateMarker);
00096 for (int cell = 1; cell != kValueCount; ++cell) {
00097 result.push_back(
00098 CorrespondenceCostToValue(
00099 ProbabilityToCorrespondenceCost(ProbabilityFromOdds(
00100 odds * Odds(CorrespondenceCostToProbability(
00101 (*kValueToCorrespondenceCost)[cell]))))) +
00102 kUpdateMarker);
00103 }
00104 return result;
00105 }
00106
00107 }
00108 }