Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
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
00031
00032
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
00039
00040
00041
00042
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 }
00074 }