25 #include "glog/logging.h" 34 template <
typename LocalTrajectoryBuilder,
typename PoseGraph>
35 class GlobalTrajectoryBuilder :
public mapping::TrajectoryBuilderInterface {
39 GlobalTrajectoryBuilder(
40 std::unique_ptr<LocalTrajectoryBuilder> local_trajectory_builder,
41 const int trajectory_id, PoseGraph*
const pose_graph,
42 const LocalSlamResultCallback& local_slam_result_callback)
47 ~GlobalTrajectoryBuilder()
override {}
49 GlobalTrajectoryBuilder(
const GlobalTrajectoryBuilder&) =
delete;
50 GlobalTrajectoryBuilder& operator=(
const GlobalTrajectoryBuilder&) =
delete;
53 const std::string& sensor_id,
54 const sensor::TimedPointCloudData& timed_point_cloud_data)
override {
56 <<
"Cannot add TimedPointCloudData without a LocalTrajectoryBuilder.";
57 std::unique_ptr<typename LocalTrajectoryBuilder::MatchingResult>
59 sensor_id, timed_point_cloud_data);
60 if (matching_result ==
nullptr) {
64 kLocalSlamMatchingResults->Increment();
65 std::unique_ptr<InsertionResult> insertion_result;
66 if (matching_result->insertion_result !=
nullptr) {
67 kLocalSlamInsertionResults->Increment();
70 matching_result->insertion_result->insertion_submaps);
72 insertion_result = common::make_unique<InsertionResult>(InsertionResult{
73 node_id, matching_result->insertion_result->constant_data,
74 std::vector<std::shared_ptr<const Submap>>(
75 matching_result->insertion_result->insertion_submaps.begin(),
76 matching_result->insertion_result->insertion_submaps.end())});
80 trajectory_id_, matching_result->time, matching_result->local_pose,
81 std::move(matching_result->range_data_in_local),
82 std::move(insertion_result));
86 void AddSensorData(
const std::string& sensor_id,
87 const sensor::ImuData& imu_data)
override {
94 void AddSensorData(
const std::string& sensor_id,
95 const sensor::OdometryData& odometry_data)
override {
96 CHECK(odometry_data.pose.IsValid()) << odometry_data.pose;
104 const std::string& sensor_id,
105 const sensor::FixedFramePoseData& fixed_frame_pose)
override {
106 if (fixed_frame_pose.pose.has_value()) {
107 CHECK(fixed_frame_pose.pose.value().IsValid())
108 << fixed_frame_pose.pose.value();
113 void AddSensorData(
const std::string& sensor_id,
114 const sensor::LandmarkData& landmark_data)
override {
118 void AddLocalSlamResultData(std::unique_ptr<mapping::LocalSlamResultData>
119 local_slam_result_data)
override {
121 "local_trajectory_builder_ present.";
135 std::unique_ptr<LocalTrajectoryBuilder2D> local_trajectory_builder,
138 local_slam_result_callback) {
140 GlobalTrajectoryBuilder<LocalTrajectoryBuilder2D, mapping::PoseGraph2D>>(
141 std::move(local_trajectory_builder), trajectory_id, pose_graph,
142 local_slam_result_callback);
146 std::unique_ptr<LocalTrajectoryBuilder3D> local_trajectory_builder,
149 local_slam_result_callback) {
151 GlobalTrajectoryBuilder<LocalTrajectoryBuilder3D, mapping::PoseGraph3D>>(
152 std::move(local_trajectory_builder), trajectory_id, pose_graph,
153 local_slam_result_callback);
158 "mapping_internal_global_trajectory_builder_local_slam_results",
159 "Local SLAM results");
160 kLocalSlamMatchingResults = results->Add({{
"type",
"MatchingResult"}});
161 kLocalSlamInsertionResults = results->Add({{
"type",
"InsertionResult"}});
std::unique_ptr< TrajectoryBuilderInterface > CreateGlobalTrajectoryBuilder2D(std::unique_ptr< LocalTrajectoryBuilder2D > local_trajectory_builder, const int trajectory_id, mapping::PoseGraph2D *const pose_graph, const TrajectoryBuilderInterface::LocalSlamResultCallback &local_slam_result_callback)
LocalSlamResultCallback local_slam_result_callback_
_Unique_if< T >::_Single_object make_unique(Args &&... args)
void GlobalTrajectoryBuilderRegisterMetrics(metrics::FamilyFactory *factory)
virtual Family< Counter > * NewCounterFamily(const std::string &name, const std::string &description)=0
std::unique_ptr< LocalTrajectoryBuilder > local_trajectory_builder_
std::unique_ptr< TrajectoryBuilderInterface > CreateGlobalTrajectoryBuilder3D(std::unique_ptr< LocalTrajectoryBuilder3D > local_trajectory_builder, const int trajectory_id, mapping::PoseGraph3D *const pose_graph, const TrajectoryBuilderInterface::LocalSlamResultCallback &local_slam_result_callback)
PoseGraph *const pose_graph_
std::function< void(int, common::Time, transform::Rigid3d, sensor::RangeData, std::unique_ptr< const InsertionResult >)> LocalSlamResultCallback