trajectory_connectivity.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 #ifndef CARTOGRAPHER_MAPPING_TRAJECTORY_CONNECTIVITY_H_
18 #define CARTOGRAPHER_MAPPING_TRAJECTORY_CONNECTIVITY_H_
19 
20 #include <map>
21 #include <unordered_map>
22 
24 #include "cartographer/mapping/proto/trajectory_connectivity.pb.h"
26 
27 namespace cartographer {
28 namespace mapping {
29 
30 // A class that tracks the connectivity structure between trajectories.
31 //
32 // Connectivity includes both the count ("How many times have I _directly_
33 // connected trajectories i and j?") and the transitive connectivity.
34 //
35 // This class is thread-safe.
37  public:
39 
42 
43  // Add a trajectory which is initially connected to nothing.
44  void Add(int trajectory_id) EXCLUDES(lock_);
45 
46  // Connect two trajectories. If either trajectory is untracked, it will be
47  // tracked. This function is invariant to the order of its arguments. Repeated
48  // calls to Connect increment the connectivity count.
49  void Connect(int trajectory_id_a, int trajectory_id_b) EXCLUDES(lock_);
50 
51  // Determines if two trajectories have been (transitively) connected. If
52  // either trajectory is not being tracked, returns false. This function is
53  // invariant to the order of its arguments.
54  bool TransitivelyConnected(int trajectory_id_a, int trajectory_id_b)
55  EXCLUDES(lock_);
56 
57  // Return the number of _direct_ connections between 'trajectory_id_a' and
58  // 'trajectory_id_b'. If either trajectory is not being tracked, returns 0.
59  // This function is invariant to the order of its arguments.
60  int ConnectionCount(int trajectory_id_a, int trajectory_id_b) EXCLUDES(lock_);
61 
62  // The trajectory IDs, grouped by connectivity.
63  std::vector<std::vector<int>> ConnectedComponents() EXCLUDES(lock_);
64 
65  private:
66  // Find the representative and compresses the path to it.
67  int FindSet(int trajectory_id) REQUIRES(lock_);
68  void Union(int trajectory_id_a, int trajectory_id_b) REQUIRES(lock_);
69 
70  common::Mutex lock_;
71  // Tracks transitive connectivity using a disjoint set forest, i.e. each
72  // entry points towards the representative for the given trajectory.
73  std::map<int, int> forest_ GUARDED_BY(lock_);
74  // Tracks the number of direct connections between a pair of trajectories.
75  std::map<std::pair<int, int>, int> connection_map_ GUARDED_BY(lock_);
76 };
77 
78 // Returns a proto encoding connected components.
79 proto::TrajectoryConnectivity ToProto(
80  std::vector<std::vector<int>> connected_components);
81 
82 // Returns the connected component containing 'trajectory_index'.
83 proto::TrajectoryConnectivity::ConnectedComponent FindConnectedComponent(
84  const cartographer::mapping::proto::TrajectoryConnectivity&
85  trajectory_connectivity,
86  int trajectory_id);
87 
88 } // namespace mapping
89 } // namespace cartographer
90 
91 #endif // CARTOGRAPHER_MAPPING_TRAJECTORY_CONNECTIVITY_H_
void Union(int trajectory_id_a, int trajectory_id_b) REQUIRES(lock_)
void Add(int trajectory_id) EXCLUDES(lock_)
#define EXCLUDES(...)
Definition: mutex.h:53
int FindSet(int trajectory_id) REQUIRES(lock_)
bool TransitivelyConnected(int trajectory_id_a, int trajectory_id_b) EXCLUDES(lock_)
std::map< int, int > forest_ GUARDED_BY(lock_)
proto::TrajectoryConnectivity::ConnectedComponent FindConnectedComponent(const proto::TrajectoryConnectivity &trajectory_connectivity, const int trajectory_id)
#define REQUIRES(...)
Definition: mutex.h:44
void Connect(int trajectory_id_a, int trajectory_id_b) EXCLUDES(lock_)
std::vector< std::vector< int > > ConnectedComponents() EXCLUDES(lock_)
TrajectoryConnectivity & operator=(const TrajectoryConnectivity &)=delete
proto::SparsePoseGraph::Constraint::Tag ToProto(const SparsePoseGraph::Constraint::Tag &tag)
int ConnectionCount(int trajectory_id_a, int trajectory_id_b) EXCLUDES(lock_)


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