// TODO(gaschler): Consider using just std::function, it can also be empty. // 将回调函数赋值给when_done_ when_done_ = absl::make_unique<std::function<void(const Result&)>>(callback); CHECK(when_done_task_ != nullptr);
voidPoseGraph2D::RunOptimization(){ // 如果submap为空直接退出 if (optimization_problem_->submap_data().empty()) { return; }
// No other thread is accessing the optimization_problem_, // data_.constraints, data_.frozen_trajectories and data_.landmark_nodes // when executing the Solve. Solve is time consuming, so not taking the mutex // before Solve to avoid blocking foreground processing. // Solve 比较耗时, 所以在执行 Solve 之前不要加互斥锁, 以免阻塞其他的任务处理 // landmark直接参与优化问题,这里到底如何solve后续再说 optimization_problem_->Solve(data_.constraints, GetTrajectoryStates(), data_.landmark_nodes);
// Extrapolate all point cloud poses that were not included in the // 'optimization_problem_' yet. // 推断尚未包含在“optimization_problem_”中的所有点云姿势,只是把他们应用在了刚刚计算出来的位姿,做一个简单的推测,并不准确
// 根据轨迹状态删除轨迹 voidPoseGraph2D::DeleteTrajectoriesIfNeeded(){ TrimmingHandle trimming_handle(this); for (auto& it : data_.trajectories_state) { if (it.second.deletion_state == InternalTrajectoryState::DeletionState::WAIT_FOR_DELETION) { // TODO(gaschler): Consider directly deleting from data_, which may be // more complete. auto submap_ids = trimming_handle.GetSubmapIds(it.first); for (auto& submap_id : submap_ids) { trimming_handle.TrimSubmap(submap_id); } it.second.state = TrajectoryState::DELETED; it.second.deletion_state = InternalTrajectoryState::DeletionState::NORMAL; } } }