range_data_inserter_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 "Eigen/Core"
21 #include "glog/logging.h"
22 
23 namespace cartographer {
24 namespace mapping {
25 namespace {
26 
27 void InsertMissesIntoGrid(const std::vector<uint16>& miss_table,
28  const Eigen::Vector3f& origin,
29  const sensor::PointCloud& returns,
30  HybridGrid* hybrid_grid,
31  const int num_free_space_voxels) {
32  const Eigen::Array3i origin_cell = hybrid_grid->GetCellIndex(origin);
33  for (const Eigen::Vector3f& hit : returns) {
34  const Eigen::Array3i hit_cell = hybrid_grid->GetCellIndex(hit);
35 
36  const Eigen::Array3i delta = hit_cell - origin_cell;
37  const int num_samples = delta.cwiseAbs().maxCoeff();
38  CHECK_LT(num_samples, 1 << 15);
39  // 'num_samples' is the number of samples we equi-distantly place on the
40  // line between 'origin' and 'hit'. (including a fractional part for sub-
41  // voxels) It is chosen so that between two samples we change from one voxel
42  // to the next on the fastest changing dimension.
43  //
44  // Only the last 'num_free_space_voxels' are updated for performance.
45  for (int position = std::max(0, num_samples - num_free_space_voxels);
46  position < num_samples; ++position) {
47  const Eigen::Array3i miss_cell =
48  origin_cell + delta * position / num_samples;
49  hybrid_grid->ApplyLookupTable(miss_cell, miss_table);
50  }
51  }
52 }
53 
54 } // namespace
55 
56 proto::RangeDataInserterOptions3D CreateRangeDataInserterOptions3D(
57  common::LuaParameterDictionary* parameter_dictionary) {
58  proto::RangeDataInserterOptions3D options;
59  options.set_hit_probability(
60  parameter_dictionary->GetDouble("hit_probability"));
61  options.set_miss_probability(
62  parameter_dictionary->GetDouble("miss_probability"));
63  options.set_num_free_space_voxels(
64  parameter_dictionary->GetInt("num_free_space_voxels"));
65  CHECK_GT(options.hit_probability(), 0.5);
66  CHECK_LT(options.miss_probability(), 0.5);
67  return options;
68 }
69 
71  const proto::RangeDataInserterOptions3D& options)
72  : options_(options),
73  hit_table_(
74  ComputeLookupTableToApplyOdds(Odds(options_.hit_probability()))),
75  miss_table_(
76  ComputeLookupTableToApplyOdds(Odds(options_.miss_probability()))) {}
77 
79  HybridGrid* hybrid_grid) const {
80  CHECK_NOTNULL(hybrid_grid);
81 
82  for (const Eigen::Vector3f& hit : range_data.returns) {
83  const Eigen::Array3i hit_cell = hybrid_grid->GetCellIndex(hit);
84  hybrid_grid->ApplyLookupTable(hit_cell, hit_table_);
85  }
86 
87  // By not starting a new update after hits are inserted, we give hits priority
88  // (i.e. no hits will be ignored because of a miss in the same cell).
89  InsertMissesIntoGrid(miss_table_, range_data.origin, range_data.returns,
90  hybrid_grid, options_.num_free_space_voxels());
91  hybrid_grid->FinishUpdate();
92 }
93 
94 } // namespace mapping
95 } // namespace cartographer
std::vector< uint16 > ComputeLookupTableToApplyOdds(const float odds)
proto::RangeDataInserterOptions3D CreateRangeDataInserterOptions3D(common::LuaParameterDictionary *parameter_dictionary)
const proto::RangeDataInserterOptions3D options_
void Insert(const sensor::RangeData &range_data, HybridGrid *hybrid_grid) const
float Odds(float probability)
proto::ProbabilityGridRangeDataInserterOptions2D options_
bool ApplyLookupTable(const Eigen::Array3i &index, const std::vector< uint16 > &table)
Definition: hybrid_grid.h:507
std::vector< Eigen::Vector3f > PointCloud
Definition: point_cloud.h:32
Eigen::Array3i GetCellIndex(const Eigen::Vector3f &point) const
Definition: hybrid_grid.h:428
RangeDataInserter3D(const proto::RangeDataInserterOptions3D &options)


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