fast_correlative_scan_matcher_3d.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 // FastCorrelativeScanMatcher2D.
19 
20 #ifndef CARTOGRAPHER_MAPPING_INTERNAL_3D_SCAN_MATCHING_FAST_CORRELATIVE_SCAN_MATCHER_3D_H_
21 #define CARTOGRAPHER_MAPPING_INTERNAL_3D_SCAN_MATCHING_FAST_CORRELATIVE_SCAN_MATCHER_3D_H_
22 
23 #include <memory>
24 #include <vector>
25 
26 #include "Eigen/Core"
32 #include "cartographer/mapping/proto/scan_matching/fast_correlative_scan_matcher_options_3d.pb.h"
35 
36 namespace cartographer {
37 namespace mapping {
38 namespace scan_matching {
39 
40 proto::FastCorrelativeScanMatcherOptions3D
42  common::LuaParameterDictionary* parameter_dictionary);
43 
45  public:
47  const HybridGrid& hybrid_grid,
48  const proto::FastCorrelativeScanMatcherOptions3D& options);
49 
50  const PrecomputationGrid3D& Get(int depth) const {
51  return precomputation_grids_.at(depth);
52  }
53 
54  int max_depth() const { return precomputation_grids_.size() - 1; }
55 
56  private:
57  std::vector<PrecomputationGrid3D> precomputation_grids_;
58 };
59 
60 struct DiscreteScan3D;
61 struct Candidate3D;
62 
63 // Used to compute scores between 0 and 1 how well the given pose matches.
64 using MatchingFunction = std::function<float(const transform::Rigid3f&)>;
65 
67  public:
68  struct Result {
69  float score;
73  };
74 
76  const HybridGrid& hybrid_grid,
77  const HybridGrid* low_resolution_hybrid_grid,
78  const std::vector<TrajectoryNode>& nodes,
79  const proto::FastCorrelativeScanMatcherOptions3D& options);
81 
84  delete;
85 
86  // Aligns the node with the given 'constant_data' within the 'hybrid_grid'
87  // given 'global_node_pose' and 'global_submap_pose'. 'Result' is only
88  // returned if a score above 'min_score' (excluding equality) is possible.
89  std::unique_ptr<Result> Match(const transform::Rigid3d& global_node_pose,
90  const transform::Rigid3d& global_submap_pose,
91  const TrajectoryNode::Data& constant_data,
92  float min_score) const;
93 
94  // Aligns the node with the given 'constant_data' within the 'hybrid_grid'
95  // given rotations which are expected to be approximately gravity aligned.
96  // 'Result' is only returned if a score above 'min_score' (excluding equality)
97  // is possible.
98  std::unique_ptr<Result> MatchFullSubmap(
99  const Eigen::Quaterniond& global_node_rotation,
100  const Eigen::Quaterniond& global_submap_rotation,
101  const TrajectoryNode::Data& constant_data, float min_score) 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
109  };
110 
111  std::unique_ptr<Result> MatchWithSearchParameters(
112  const SearchParameters& search_parameters,
113  const transform::Rigid3f& global_node_pose,
114  const transform::Rigid3f& global_submap_pose,
115  const sensor::PointCloud& point_cloud,
116  const Eigen::VectorXf& rotational_scan_matcher_histogram,
117  const Eigen::Quaterniond& gravity_alignment, float min_score) const;
118  DiscreteScan3D DiscretizeScan(const SearchParameters& search_parameters,
119  const sensor::PointCloud& point_cloud,
120  const transform::Rigid3f& pose,
121  float rotational_score) const;
122  std::vector<DiscreteScan3D> GenerateDiscreteScans(
123  const SearchParameters& search_parameters,
124  const sensor::PointCloud& point_cloud,
125  const Eigen::VectorXf& rotational_scan_matcher_histogram,
126  const Eigen::Quaterniond& gravity_alignment,
127  const transform::Rigid3f& global_node_pose,
128  const transform::Rigid3f& global_submap_pose) const;
129  std::vector<Candidate3D> GenerateLowestResolutionCandidates(
130  const SearchParameters& search_parameters, int num_discrete_scans) const;
131  void ScoreCandidates(int depth,
132  const std::vector<DiscreteScan3D>& discrete_scans,
133  std::vector<Candidate3D>* const candidates) const;
134  std::vector<Candidate3D> ComputeLowestResolutionCandidates(
135  const SearchParameters& search_parameters,
136  const std::vector<DiscreteScan3D>& discrete_scans) const;
137  Candidate3D BranchAndBound(const SearchParameters& search_parameters,
138  const std::vector<DiscreteScan3D>& discrete_scans,
139  const std::vector<Candidate3D>& candidates,
140  int candidate_depth, float min_score) const;
141  transform::Rigid3f GetPoseFromCandidate(
142  const std::vector<DiscreteScan3D>& discrete_scans,
143  const Candidate3D& candidate) const;
144 
145  const proto::FastCorrelativeScanMatcherOptions3D options_;
146  const float resolution_;
147  const int width_in_voxels_;
148  std::unique_ptr<PrecomputationGridStack3D> precomputation_grid_stack_;
151 };
152 
153 } // namespace scan_matching
154 } // namespace mapping
155 } // namespace cartographer
156 
157 #endif // CARTOGRAPHER_MAPPING_INTERNAL_3D_SCAN_MATCHING_FAST_CORRELATIVE_SCAN_MATCHER_3D_H_
std::function< float(const transform::Rigid3f &)> MatchingFunction
std::vector< Eigen::Vector3f > PointCloud
Definition: point_cloud.h:32
proto::FastCorrelativeScanMatcherOptions3D CreateFastCorrelativeScanMatcherOptions3D(common::LuaParameterDictionary *const parameter_dictionary)
transform::Rigid3d pose
PrecomputationGridStack3D(const HybridGrid &hybrid_grid, const proto::FastCorrelativeScanMatcherOptions3D &options)


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