Refactor number of cells magic number (#1522)
parent
aed6ee7b1d
commit
a60cca4a43
|
@ -23,14 +23,16 @@ namespace mapping {
|
|||
|
||||
namespace {
|
||||
|
||||
constexpr int kNumberOfValues = 32768;
|
||||
|
||||
// 0 is unknown, [1, 32767] maps to [lower_bound, upper_bound].
|
||||
float SlowValueToBoundedFloat(const uint16 value, const uint16 unknown_value,
|
||||
const float unknown_result,
|
||||
const float lower_bound,
|
||||
const float upper_bound) {
|
||||
CHECK_LE(value, 32767);
|
||||
CHECK_LT(value, kNumberOfValues);
|
||||
if (value == unknown_value) return unknown_result;
|
||||
const float kScale = (upper_bound - lower_bound) / 32766.f;
|
||||
const float kScale = (upper_bound - lower_bound) / (kNumberOfValues - 2.f);
|
||||
return value * kScale + (lower_bound - kScale);
|
||||
}
|
||||
|
||||
|
@ -41,7 +43,7 @@ std::unique_ptr<std::vector<float>> PrecomputeValueToBoundedFloat(
|
|||
// Repeat two times, so that both values with and without the update marker
|
||||
// can be converted to a probability.
|
||||
for (int repeat = 0; repeat != 2; ++repeat) {
|
||||
for (int value = 0; value != 32768; ++value) {
|
||||
for (int value = 0; value != kNumberOfValues; ++value) {
|
||||
result->push_back(SlowValueToBoundedFloat(
|
||||
value, unknown_value, unknown_result, lower_bound, upper_bound));
|
||||
}
|
||||
|
@ -73,7 +75,7 @@ std::vector<uint16> ComputeLookupTableToApplyOdds(const float odds) {
|
|||
std::vector<uint16> result;
|
||||
result.push_back(ProbabilityToValue(ProbabilityFromOdds(odds)) +
|
||||
kUpdateMarker);
|
||||
for (int cell = 1; cell != 32768; ++cell) {
|
||||
for (int cell = 1; cell != kNumberOfValues; ++cell) {
|
||||
result.push_back(ProbabilityToValue(ProbabilityFromOdds(
|
||||
odds * Odds((*kValueToProbability)[cell]))) +
|
||||
kUpdateMarker);
|
||||
|
@ -87,7 +89,7 @@ std::vector<uint16> ComputeLookupTableToApplyCorrespondenceCostOdds(
|
|||
result.push_back(CorrespondenceCostToValue(ProbabilityToCorrespondenceCost(
|
||||
ProbabilityFromOdds(odds))) +
|
||||
kUpdateMarker);
|
||||
for (int cell = 1; cell != 32768; ++cell) {
|
||||
for (int cell = 1; cell != kNumberOfValues; ++cell) {
|
||||
result.push_back(
|
||||
CorrespondenceCostToValue(
|
||||
ProbabilityToCorrespondenceCost(ProbabilityFromOdds(
|
||||
|
|
Loading…
Reference in New Issue