trajectory_connectivity_state.cc
Go to the documentation of this file.
1 /*
2  * Copyright 2017 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 namespace cartographer {
20 namespace mapping {
21 
22 void TrajectoryConnectivityState::Add(const int trajectory_id) {
23  connected_components_.Add(trajectory_id);
24 }
25 
26 void TrajectoryConnectivityState::Connect(const int trajectory_id_a,
27  const int trajectory_id_b,
28  const common::Time time) {
29  if (TransitivelyConnected(trajectory_id_a, trajectory_id_b)) {
30  // The trajectories are transitively connected, i.e. they belong to the same
31  // connected component. In this case we only update the last connection time
32  // of those two trajectories.
33  auto sorted_pair = std::minmax(trajectory_id_a, trajectory_id_b);
34  if (last_connection_time_map_[sorted_pair] < time) {
35  last_connection_time_map_[sorted_pair] = time;
36  }
37  } else {
38  // The connection between these two trajectories is about to join to
39  // connected components. Here we update all bipartite trajectory pairs for
40  // the two connected components with the connection time. This is to quickly
41  // change to a more efficient loop closure search (by constraining the
42  // search window) when connected components are joined.
43  std::vector<int> component_a =
44  connected_components_.GetComponent(trajectory_id_a);
45  std::vector<int> component_b =
46  connected_components_.GetComponent(trajectory_id_b);
47  for (const auto id_a : component_a) {
48  for (const auto id_b : component_b) {
49  auto id_pair = std::minmax(id_a, id_b);
51  }
52  }
53  }
54  connected_components_.Connect(trajectory_id_a, trajectory_id_b);
55 }
56 
58  const int trajectory_id_a, const int trajectory_id_b) const {
59  return connected_components_.TransitivelyConnected(trajectory_id_a,
60  trajectory_id_b);
61 }
62 
63 std::vector<std::vector<int>> TrajectoryConnectivityState::Components() const {
65 }
66 
68  const int trajectory_id_a, const int trajectory_id_b) {
69  const auto sorted_pair = std::minmax(trajectory_id_a, trajectory_id_b);
70  return last_connection_time_map_[sorted_pair];
71 }
72 
73 } // namespace mapping
74 } // namespace cartographer
bool TransitivelyConnected(int trajectory_id_a, int trajectory_id_b) EXCLUDES(lock_)
std::vector< int > GetComponent(int trajectory_id) EXCLUDES(lock_)
void Connect(int trajectory_id_a, int trajectory_id_b, common::Time time)
std::vector< std::vector< int > > Components() EXCLUDES(lock_)
UniversalTimeScaleClock::time_point Time
Definition: time.h:44
static time_point time
common::Time LastConnectionTime(int trajectory_id_a, int trajectory_id_b)
std::map< std::pair< int, int >, common::Time > last_connection_time_map_
bool TransitivelyConnected(int trajectory_id_a, int trajectory_id_b) const
void Connect(int trajectory_id_a, int trajectory_id_b) EXCLUDES(lock_)
void Add(int trajectory_id) EXCLUDES(lock_)


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