probability_values.cc
Go to the documentation of this file.
1 /*
2  * Copyright 2016 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 
18 
20 
21 namespace cartographer {
22 namespace mapping {
23 
24 namespace {
25 
26 // 0 is unknown, [1, 32767] maps to [lower_bound, upper_bound].
27 float SlowValueToBoundedFloat(const uint16 value, const uint16 unknown_value,
28  const float unknown_result,
29  const float lower_bound,
30  const float upper_bound) {
31  CHECK_GE(value, 0);
32  CHECK_LE(value, 32767);
33  if (value == unknown_value) return unknown_result;
34  const float kScale = (upper_bound - lower_bound) / 32766.f;
35  return value * kScale + (lower_bound - kScale);
36 }
37 
38 std::unique_ptr<std::vector<float>> PrecomputeValueToBoundedFloat(
39  const uint16 unknown_value, const float unknown_result,
40  const float lower_bound, const float upper_bound) {
41  auto result = common::make_unique<std::vector<float>>();
42  // Repeat two times, so that both values with and without the update marker
43  // can be converted to a probability.
44  for (int repeat = 0; repeat != 2; ++repeat) {
45  for (int value = 0; value != 32768; ++value) {
46  result->push_back(SlowValueToBoundedFloat(
47  value, unknown_value, unknown_result, lower_bound, upper_bound));
48  }
49  }
50  return result;
51 }
52 
53 std::unique_ptr<std::vector<float>> PrecomputeValueToProbability() {
54  return PrecomputeValueToBoundedFloat(kUnknownProbabilityValue,
57 }
58 
59 std::unique_ptr<std::vector<float>> PrecomputeValueToCorrespondenceCost() {
60  return PrecomputeValueToBoundedFloat(
63 }
64 
65 } // namespace
66 
67 const std::vector<float>* const kValueToProbability =
68  PrecomputeValueToProbability().release();
69 
70 const std::vector<float>* const kValueToCorrespondenceCost =
71  PrecomputeValueToCorrespondenceCost().release();
72 
73 std::vector<uint16> ComputeLookupTableToApplyOdds(const float odds) {
74  std::vector<uint16> result;
75  result.push_back(ProbabilityToValue(ProbabilityFromOdds(odds)) +
77  for (int cell = 1; cell != 32768; ++cell) {
78  result.push_back(ProbabilityToValue(ProbabilityFromOdds(
79  odds * Odds((*kValueToProbability)[cell]))) +
81  }
82  return result;
83 }
84 
86  float odds) {
87  std::vector<uint16> result;
89  ProbabilityFromOdds(odds))) +
91  for (int cell = 1; cell != 32768; ++cell) {
92  result.push_back(
96  (*kValueToCorrespondenceCost)[cell]))))) +
98  }
99  return result;
100 }
101 
102 } // namespace mapping
103 } // namespace cartographer
const std::vector< float > *const kValueToCorrespondenceCost
std::vector< uint16 > ComputeLookupTableToApplyOdds(const float odds)
std::vector< uint16 > ComputeLookupTableToApplyCorrespondenceCostOdds(float odds)
float ProbabilityFromOdds(const float odds)
constexpr float kMinProbability
constexpr float kMaxCorrespondenceCost
constexpr float kMaxProbability
float CorrespondenceCostToProbability(const float correspondence_cost)
uint16_t uint16
Definition: port.h:35
float Odds(float probability)
const std::vector< float > *const kValueToProbability
constexpr uint16 kUnknownProbabilityValue
float ProbabilityToCorrespondenceCost(const float probability)
uint16 ProbabilityToValue(const float probability)
uint16 CorrespondenceCostToValue(const float correspondence_cost)
constexpr uint16 kUpdateMarker
constexpr uint16 kUnknownCorrespondenceValue
constexpr float kMinCorrespondenceCost


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