MCPcopy Create free account
hub / github.com/PeterFWS/Structure-PLP-SLAM / optimize

Method optimize

src/PLPSLAM/optimize/graph_optimizer.cc:53–421  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

51 }
52
53 void graph_optimizer::optimize(data::keyframe *loop_keyfrm, data::keyframe *curr_keyfrm,
54 const module::keyframe_Sim3_pairs_t &non_corrected_Sim3s,
55 const module::keyframe_Sim3_pairs_t &pre_corrected_Sim3s,
56 const std::map<data::keyframe *, std::set<data::keyframe *>> &loop_connections) const
57 {
58 // [1] build optimizer
59
60 auto linear_solver = ::g2o::make_unique<::g2o::LinearSolverCSparse<::g2o::BlockSolver_7_3::PoseMatrixType>>();
61 auto block_solver = ::g2o::make_unique<::g2o::BlockSolver_7_3>(std::move(linear_solver));
62 auto algorithm = new ::g2o::OptimizationAlgorithmLevenberg(std::move(block_solver));
63
64 ::g2o::SparseOptimizer optimizer;
65 optimizer.setAlgorithm(algorithm);
66
67 // [2] add vertex
68
69 const auto all_keyfrms = map_db_->get_all_keyframes();
70 const auto all_lms = map_db_->get_all_landmarks();
71
72 // FW:
73 const auto all_lms_line = map_db_->get_all_landmarks_line();
74 std::unordered_map<unsigned int, data::keyframe *> keyframes;
75
76 const unsigned int max_keyfrm_id = map_db_->get_max_keyframe_id();
77
78 // Convert all keyframe poses (before modification) to Sim3 and save
79 std::vector<::g2o::Sim3, Eigen::aligned_allocator<::g2o::Sim3>> Sim3s_cw(max_keyfrm_id + 1);
80 // Save the added vertex
81 std::vector<g2o::sim3::shot_vertex *> vertices(max_keyfrm_id + 1);
82
83 constexpr int min_weight = 100;
84
85 for (auto keyfrm : all_keyfrms)
86 {
87 if (keyfrm->will_be_erased())
88 {
89 continue;
90 }
91 auto keyfrm_vtx = new g2o::sim3::shot_vertex();
92
93 const auto id = keyfrm->id_;
94
95 // Check if pose is corrected before optimization
96 const auto iter = pre_corrected_Sim3s.find(keyfrm);
97 if (iter != pre_corrected_Sim3s.end())
98 {
99 // If the pose has been corrected before optimization, take out that pose and set it in vertex
100 Sim3s_cw.at(id) = iter->second;
101 keyfrm_vtx->setEstimate(iter->second);
102 }
103 else
104 {
105 // If the pose is not corrected, convert the pose of keyframe to Sim3 and set it
106 const Mat33_t rot_cw = keyfrm->get_rotation();
107 const Vec3_t trans_cw = keyfrm->get_translation();
108 const ::g2o::Sim3 Sim3_cw(rot_cw, trans_cw, 1.0);
109
110 Sim3s_cw.at(id) = Sim3_cw;

Callers

nothing calls this directly

Calls 15

get_all_keyframesMethod · 0.80
get_all_landmarksMethod · 0.80
get_max_keyframe_idMethod · 0.80
findMethod · 0.80
get_rotationMethod · 0.80
get_translationMethod · 0.80
get_weightMethod · 0.80
get_spanning_parentMethod · 0.80
get_loop_edgesMethod · 0.80
has_spanning_childMethod · 0.80

Tested by

no test coverage detected