| 1499 | |
| 1500 | |
| 1501 | void Optimizer::OptimizeEssentialGraph(Map* pMap, KeyFrame* pLoopKF, KeyFrame* pCurKF, |
| 1502 | const LoopClosing::KeyFrameAndPose &NonCorrectedSim3, |
| 1503 | const LoopClosing::KeyFrameAndPose &CorrectedSim3, |
| 1504 | const map<KeyFrame *, set<KeyFrame *> > &LoopConnections, const bool &bFixScale) |
| 1505 | { |
| 1506 | // Setup optimizer |
| 1507 | g2o::SparseOptimizer optimizer; |
| 1508 | optimizer.setVerbose(false); |
| 1509 | g2o::BlockSolver_7_3::LinearSolverType * linearSolver = |
| 1510 | new g2o::LinearSolverEigen<g2o::BlockSolver_7_3::PoseMatrixType>(); |
| 1511 | g2o::BlockSolver_7_3 * solver_ptr= new g2o::BlockSolver_7_3(linearSolver); |
| 1512 | g2o::OptimizationAlgorithmLevenberg* solver = new g2o::OptimizationAlgorithmLevenberg(solver_ptr); |
| 1513 | |
| 1514 | solver->setUserLambdaInit(1e-16); |
| 1515 | optimizer.setAlgorithm(solver); |
| 1516 | |
| 1517 | const vector<KeyFrame*> vpKFs = pMap->GetAllKeyFrames(); |
| 1518 | const vector<MapPoint*> vpMPs = pMap->GetAllMapPoints(); |
| 1519 | |
| 1520 | const unsigned int nMaxKFid = pMap->GetMaxKFid(); |
| 1521 | |
| 1522 | vector<g2o::Sim3,Eigen::aligned_allocator<g2o::Sim3> > vScw(nMaxKFid+1); |
| 1523 | vector<g2o::Sim3,Eigen::aligned_allocator<g2o::Sim3> > vCorrectedSwc(nMaxKFid+1); |
| 1524 | vector<g2o::VertexSim3Expmap*> vpVertices(nMaxKFid+1); |
| 1525 | |
| 1526 | vector<Eigen::Vector3d> vZvectors(nMaxKFid+1); // For debugging |
| 1527 | Eigen::Vector3d z_vec; |
| 1528 | z_vec << 0.0, 0.0, 1.0; |
| 1529 | |
| 1530 | const int minFeat = 100; |
| 1531 | |
| 1532 | // Set KeyFrame vertices |
| 1533 | for(size_t i=0, iend=vpKFs.size(); i<iend;i++) |
| 1534 | { |
| 1535 | KeyFrame* pKF = vpKFs[i]; |
| 1536 | if(pKF->isBad()) |
| 1537 | continue; |
| 1538 | g2o::VertexSim3Expmap* VSim3 = new g2o::VertexSim3Expmap(); |
| 1539 | |
| 1540 | const int nIDi = pKF->mnId; |
| 1541 | |
| 1542 | LoopClosing::KeyFrameAndPose::const_iterator it = CorrectedSim3.find(pKF); |
| 1543 | |
| 1544 | if(it!=CorrectedSim3.end()) |
| 1545 | { |
| 1546 | vScw[nIDi] = it->second; |
| 1547 | VSim3->setEstimate(it->second); |
| 1548 | } |
| 1549 | else |
| 1550 | { |
| 1551 | Sophus::SE3d Tcw = pKF->GetPose().cast<double>(); |
| 1552 | g2o::Sim3 Siw(Tcw.unit_quaternion(),Tcw.translation(),1.0); |
| 1553 | vScw[nIDi] = Siw; |
| 1554 | VSim3->setEstimate(Siw); |
| 1555 | } |
| 1556 | |
| 1557 | if(pKF->mnId==pMap->GetInitKFid()) |
| 1558 | VSim3->setFixed(true); |
nothing calls this directly
no test coverage detected