mapping_3d/scan_matching/fast_correlative_scan_matcher.h
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 
17 // This is an implementation of a 3D branch-and-bound algorithm similar to
18 // mapping_2d::FastCorrelativeScanMatcher.
19 
20 #ifndef CARTOGRAPHER_MAPPING_3D_SCAN_MATCHING_FAST_CORRELATIVE_SCAN_MATCHER_H_
21 #define CARTOGRAPHER_MAPPING_3D_SCAN_MATCHING_FAST_CORRELATIVE_SCAN_MATCHER_H_
22 
23 #include <memory>
24 #include <vector>
25 
26 #include "Eigen/Core"
31 #include "cartographer/mapping_3d/scan_matching/proto/fast_correlative_scan_matcher_options.pb.h"
34 
35 namespace cartographer {
36 namespace mapping_3d {
37 namespace scan_matching {
38 
39 proto::FastCorrelativeScanMatcherOptions
41  common::LuaParameterDictionary* parameter_dictionary);
42 
43 class PrecomputationGridStack;
44 
45 struct DiscreteScan {
47  // Contains a vector of discretized scans for each 'depth'.
48  std::vector<std::vector<Eigen::Array3i>> cell_indices_per_depth;
49 };
50 
51 struct Candidate {
52  Candidate(const int scan_index, const Eigen::Array3i& offset)
53  : scan_index(scan_index), offset(offset) {}
54 
55  // Index into the discrete scans vectors.
57 
58  // Linear offset from the initial pose in cell indices. For lower resolution
59  // candidates this is the lowest offset of the 2^depth x 2^depth x 2^depth
60  // block of possibilities.
61  Eigen::Array3i offset;
62 
63  // Score, higher is better.
64  float score = 0.f;
65 
66  bool operator<(const Candidate& other) const { return score < other.score; }
67  bool operator>(const Candidate& other) const { return score > other.score; }
68 };
69 
71  public:
73  const HybridGrid& hybrid_grid,
74  const std::vector<mapping::TrajectoryNode>& nodes,
75  const proto::FastCorrelativeScanMatcherOptions& options);
77 
80  delete;
81 
82  // Aligns 'coarse_point_cloud' within the 'hybrid_grid' given an
83  // 'initial_pose_estimate'. If a score above 'min_score' (excluding equality)
84  // is possible, true is returned, and 'score' and 'pose_estimate' are updated
85  // with the result. 'fine_point_cloud' is used to compute the rotational scan
86  // matcher score.
87  bool Match(const transform::Rigid3d& initial_pose_estimate,
88  const sensor::PointCloud& coarse_point_cloud,
89  const sensor::PointCloud& fine_point_cloud, float min_score,
90  float* score, transform::Rigid3d* pose_estimate) const;
91 
92  // Aligns 'coarse_point_cloud' within the 'hybrid_grid' given a rotation which
93  // is expected to be approximately gravity aligned. If a score above
94  // 'min_score' (excluding equality) is possible, true is returned, and 'score'
95  // and 'pose_estimate' are updated with the result. 'fine_point_cloud' is used
96  // to compute the rotational scan matcher score.
97  bool MatchFullSubmap(const Eigen::Quaterniond& gravity_alignment,
98  const sensor::PointCloud& coarse_point_cloud,
99  const sensor::PointCloud& fine_point_cloud,
100  float min_score, float* score,
101  transform::Rigid3d* pose_estimate) const;
102 
103  private:
105  const int linear_xy_window_size; // voxels
106  const int linear_z_window_size; // voxels
107  const double angular_search_window; // radians
108  };
109 
110  bool MatchWithSearchParameters(
111  const SearchParameters& search_parameters,
112  const transform::Rigid3d& initial_pose_estimate,
113  const sensor::PointCloud& coarse_point_cloud,
114  const sensor::PointCloud& fine_point_cloud, float min_score, float* score,
115  transform::Rigid3d* pose_estimate) const;
116  DiscreteScan DiscretizeScan(const SearchParameters& search_parameters,
117  const sensor::PointCloud& point_cloud,
118  const transform::Rigid3f& pose) const;
119  std::vector<DiscreteScan> GenerateDiscreteScans(
120  const SearchParameters& search_parameters,
121  const sensor::PointCloud& coarse_point_cloud,
122  const sensor::PointCloud& fine_point_cloud,
123  const transform::Rigid3f& initial_pose) const;
124  std::vector<Candidate> GenerateLowestResolutionCandidates(
125  const SearchParameters& search_parameters, int num_discrete_scans) const;
126  void ScoreCandidates(int depth,
127  const std::vector<DiscreteScan>& discrete_scans,
128  std::vector<Candidate>* const candidates) const;
129  std::vector<Candidate> ComputeLowestResolutionCandidates(
130  const SearchParameters& search_parameters,
131  const std::vector<DiscreteScan>& discrete_scans) const;
132  Candidate BranchAndBound(const SearchParameters& search_parameters,
133  const std::vector<DiscreteScan>& discrete_scans,
134  const std::vector<Candidate>& candidates,
135  int candidate_depth, float min_score) const;
136 
137  const proto::FastCorrelativeScanMatcherOptions options_;
138  const float resolution_;
139  const int width_in_voxels_;
140  std::unique_ptr<PrecomputationGridStack> precomputation_grid_stack_;
142 };
143 
144 } // namespace scan_matching
145 } // namespace mapping_3d
146 } // namespace cartographer
147 
148 #endif // CARTOGRAPHER_MAPPING_3D_SCAN_MATCHING_FAST_CORRELATIVE_SCAN_MATCHER_H_
proto::FastCorrelativeScanMatcherOptions CreateFastCorrelativeScanMatcherOptions(common::LuaParameterDictionary *const parameter_dictionary)
std::vector< Eigen::Vector3f > PointCloud
Definition: point_cloud.h:30


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