range_data_inserter_3d.cc
Go to the documentation of this file.
00001 /*
00002  * Copyright 2016 The Cartographer Authors
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  *
00008  *      http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 
00017 #include "cartographer/mapping/3d/range_data_inserter_3d.h"
00018 
00019 #include "Eigen/Core"
00020 #include "cartographer/mapping/probability_values.h"
00021 #include "glog/logging.h"
00022 
00023 namespace cartographer {
00024 namespace mapping {
00025 namespace {
00026 
00027 void InsertMissesIntoGrid(const std::vector<uint16>& miss_table,
00028                           const Eigen::Vector3f& origin,
00029                           const sensor::PointCloud& returns,
00030                           HybridGrid* hybrid_grid,
00031                           const int num_free_space_voxels) {
00032   const Eigen::Array3i origin_cell = hybrid_grid->GetCellIndex(origin);
00033   for (const sensor::RangefinderPoint& hit : returns) {
00034     const Eigen::Array3i hit_cell = hybrid_grid->GetCellIndex(hit.position);
00035 
00036     const Eigen::Array3i delta = hit_cell - origin_cell;
00037     const int num_samples = delta.cwiseAbs().maxCoeff();
00038     CHECK_LT(num_samples, 1 << 15);
00039     // 'num_samples' is the number of samples we equi-distantly place on the
00040     // line between 'origin' and 'hit'. (including a fractional part for sub-
00041     // voxels) It is chosen so that between two samples we change from one voxel
00042     // to the next on the fastest changing dimension.
00043     //
00044     // Only the last 'num_free_space_voxels' are updated for performance.
00045     for (int position = std::max(0, num_samples - num_free_space_voxels);
00046          position < num_samples; ++position) {
00047       const Eigen::Array3i miss_cell =
00048           origin_cell + delta * position / num_samples;
00049       hybrid_grid->ApplyLookupTable(miss_cell, miss_table);
00050     }
00051   }
00052 }
00053 
00054 }  // namespace
00055 
00056 proto::RangeDataInserterOptions3D CreateRangeDataInserterOptions3D(
00057     common::LuaParameterDictionary* parameter_dictionary) {
00058   proto::RangeDataInserterOptions3D options;
00059   options.set_hit_probability(
00060       parameter_dictionary->GetDouble("hit_probability"));
00061   options.set_miss_probability(
00062       parameter_dictionary->GetDouble("miss_probability"));
00063   options.set_num_free_space_voxels(
00064       parameter_dictionary->GetInt("num_free_space_voxels"));
00065   CHECK_GT(options.hit_probability(), 0.5);
00066   CHECK_LT(options.miss_probability(), 0.5);
00067   return options;
00068 }
00069 
00070 RangeDataInserter3D::RangeDataInserter3D(
00071     const proto::RangeDataInserterOptions3D& options)
00072     : options_(options),
00073       hit_table_(
00074           ComputeLookupTableToApplyOdds(Odds(options_.hit_probability()))),
00075       miss_table_(
00076           ComputeLookupTableToApplyOdds(Odds(options_.miss_probability()))) {}
00077 
00078 void RangeDataInserter3D::Insert(const sensor::RangeData& range_data,
00079                                  HybridGrid* hybrid_grid) const {
00080   CHECK(hybrid_grid != nullptr);
00081 
00082   for (const sensor::RangefinderPoint& hit : range_data.returns) {
00083     const Eigen::Array3i hit_cell = hybrid_grid->GetCellIndex(hit.position);
00084     hybrid_grid->ApplyLookupTable(hit_cell, hit_table_);
00085   }
00086 
00087   // By not starting a new update after hits are inserted, we give hits priority
00088   // (i.e. no hits will be ignored because of a miss in the same cell).
00089   InsertMissesIntoGrid(miss_table_, range_data.origin, range_data.returns,
00090                        hybrid_grid, options_.num_free_space_voxels());
00091   hybrid_grid->FinishUpdate();
00092 }
00093 
00094 }  // namespace mapping
00095 }  // namespace cartographer


cartographer
Author(s): The Cartographer Authors
autogenerated on Thu May 9 2019 02:27:35