trajectory_connectivity_state.cc
Go to the documentation of this file.
00001 /*
00002  * Copyright 2017 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/internal/trajectory_connectivity_state.h"
00018 
00019 namespace cartographer {
00020 namespace mapping {
00021 
00022 void TrajectoryConnectivityState::Add(const int trajectory_id) {
00023   connected_components_.Add(trajectory_id);
00024 }
00025 
00026 void TrajectoryConnectivityState::Connect(const int trajectory_id_a,
00027                                           const int trajectory_id_b,
00028                                           const common::Time time) {
00029   if (TransitivelyConnected(trajectory_id_a, trajectory_id_b)) {
00030     // The trajectories are transitively connected, i.e. they belong to the same
00031     // connected component. In this case we only update the last connection time
00032     // of those two trajectories.
00033     auto sorted_pair = std::minmax(trajectory_id_a, trajectory_id_b);
00034     if (last_connection_time_map_[sorted_pair] < time) {
00035       last_connection_time_map_[sorted_pair] = time;
00036     }
00037   } else {
00038     // The connection between these two trajectories is about to join to
00039     // connected components. Here we update all bipartite trajectory pairs for
00040     // the two connected components with the connection time. This is to quickly
00041     // change to a more efficient loop closure search (by constraining the
00042     // search window) when connected components are joined.
00043     std::vector<int> component_a =
00044         connected_components_.GetComponent(trajectory_id_a);
00045     std::vector<int> component_b =
00046         connected_components_.GetComponent(trajectory_id_b);
00047     for (const auto id_a : component_a) {
00048       for (const auto id_b : component_b) {
00049         auto id_pair = std::minmax(id_a, id_b);
00050         last_connection_time_map_[id_pair] = time;
00051       }
00052     }
00053   }
00054   connected_components_.Connect(trajectory_id_a, trajectory_id_b);
00055 }
00056 
00057 bool TrajectoryConnectivityState::TransitivelyConnected(
00058     const int trajectory_id_a, const int trajectory_id_b) const {
00059   return connected_components_.TransitivelyConnected(trajectory_id_a,
00060                                                      trajectory_id_b);
00061 }
00062 
00063 std::vector<std::vector<int>> TrajectoryConnectivityState::Components() const {
00064   return connected_components_.Components();
00065 }
00066 
00067 common::Time TrajectoryConnectivityState::LastConnectionTime(
00068     const int trajectory_id_a, const int trajectory_id_b) {
00069   const auto sorted_pair = std::minmax(trajectory_id_a, trajectory_id_b);
00070   return last_connection_time_map_[sorted_pair];
00071 }
00072 
00073 }  // namespace mapping
00074 }  // namespace cartographer


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