precomputation_grid_3d.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 #include <algorithm>
20 
21 #include "Eigen/Core"
24 #include "glog/logging.h"
25 
26 namespace cartographer {
27 namespace mapping {
28 namespace scan_matching {
29 namespace {
30 
31 // C++11 defines that integer division rounds towards zero. For index math, we
32 // actually need it to round towards negative infinity. Luckily bit shifts have
33 // that property.
34 inline int DivideByTwoRoundingTowardsNegativeInfinity(const int value) {
35  return value >> 1;
36 }
37 
38 // Computes the half resolution index corresponding to the full resolution
39 // 'cell_index'.
40 Eigen::Array3i CellIndexAtHalfResolution(const Eigen::Array3i& cell_index) {
41  return Eigen::Array3i(
42  DivideByTwoRoundingTowardsNegativeInfinity(cell_index[0]),
43  DivideByTwoRoundingTowardsNegativeInfinity(cell_index[1]),
44  DivideByTwoRoundingTowardsNegativeInfinity(cell_index[2]));
45 }
46 
47 } // namespace
48 
50  const HybridGrid& hybrid_grid) {
51  PrecomputationGrid3D result(hybrid_grid.resolution());
52  for (auto it = HybridGrid::Iterator(hybrid_grid); !it.Done(); it.Next()) {
53  const int cell_value = common::RoundToInt(
54  (ValueToProbability(it.GetValue()) - kMinProbability) *
55  (255.f / (kMaxProbability - kMinProbability)));
56  CHECK_GE(cell_value, 0);
57  CHECK_LE(cell_value, 255);
58  *result.mutable_value(it.GetCellIndex()) = cell_value;
59  }
60  return result;
61 }
62 
64  const bool half_resolution,
65  const Eigen::Array3i& shift) {
66  PrecomputationGrid3D result(grid.resolution());
67  for (auto it = PrecomputationGrid3D::Iterator(grid); !it.Done(); it.Next()) {
68  for (int i = 0; i != 8; ++i) {
69  // We use this value to update 8 values in the resulting grid, at
70  // position (x - {0, 'shift'}, y - {0, 'shift'}, z - {0, 'shift'}).
71  // If 'shift' is 2 ** (depth - 1), where depth 0 is the original grid,
72  // this results in precomputation grids analogous to the 2D case.
73  const Eigen::Array3i cell_index =
75  auto* const cell_value = result.mutable_value(
76  half_resolution ? CellIndexAtHalfResolution(cell_index) : cell_index);
77  *cell_value = std::max(it.GetValue(), *cell_value);
78  }
79  }
80  return result;
81 }
82 
83 } // namespace scan_matching
84 } // namespace mapping
85 } // namespace cartographer
PrecomputationGrid3D ConvertToPrecomputationGrid(const HybridGrid &hybrid_grid)
int RoundToInt(const float x)
Definition: port.h:41
constexpr float kMinProbability
float ValueToProbability(const uint16 value)
constexpr float kMaxProbability
Eigen::Array3i GetCellIndex(const Eigen::Vector3f &point) const
Definition: hybrid_grid.h:428
PrecomputationGrid3D PrecomputeGrid(const PrecomputationGrid3D &grid, const bool half_resolution, const Eigen::Array3i &shift)
static Eigen::Array3i GetOctant(const int i)
Definition: hybrid_grid.h:436


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