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 
19 namespace cartographer {
20 namespace mapping {
21 
22 namespace {
23 
24 // 0 is unknown, [1, 32767] maps to [kMinProbability, kMaxProbability].
25 float SlowValueToProbability(const uint16 value) {
26  CHECK_GE(value, 0);
27  CHECK_LE(value, 32767);
28  if (value == kUnknownProbabilityValue) {
29  // Unknown cells have kMinProbability.
30  return kMinProbability;
31  }
32  const float kScale = (kMaxProbability - kMinProbability) / 32766.f;
33  return value * kScale + (kMinProbability - kScale);
34 }
35 
36 const std::vector<float>* PrecomputeValueToProbability() {
37  std::vector<float>* result = new std::vector<float>;
38  // Repeat two times, so that both values with and without the update marker
39  // can be converted to a probability.
40  for (int repeat = 0; repeat != 2; ++repeat) {
41  for (int value = 0; value != 32768; ++value) {
42  result->push_back(SlowValueToProbability(value));
43  }
44  }
45  return result;
46 }
47 
48 } // namespace
49 
50 const std::vector<float>* const kValueToProbability =
51  PrecomputeValueToProbability();
52 
53 std::vector<uint16> ComputeLookupTableToApplyOdds(const float odds) {
54  std::vector<uint16> result;
55  result.push_back(ProbabilityToValue(ProbabilityFromOdds(odds)) +
57  for (int cell = 1; cell != 32768; ++cell) {
58  result.push_back(ProbabilityToValue(ProbabilityFromOdds(
59  odds * Odds((*kValueToProbability)[cell]))) +
61  }
62  return result;
63 }
64 
65 } // namespace mapping
66 } // namespace cartographer
std::vector< uint16 > ComputeLookupTableToApplyOdds(const float odds)
float ProbabilityFromOdds(const float odds)
constexpr float kMinProbability
constexpr float kMaxProbability
float Odds(float probability)
const std::vector< float > *const kValueToProbability
constexpr uint16 kUnknownProbabilityValue
uint16 ProbabilityToValue(const float probability)
float value
constexpr uint16 kUpdateMarker
uint16_t uint16
Definition: port.h:33


cartographer
Author(s):
autogenerated on Mon Jun 10 2019 12:51:39