Skip to content

Commit

Permalink
Minor cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
NikolausDemmel committed Jul 24, 2019
1 parent dd09787 commit 2944a67
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
9 changes: 8 additions & 1 deletion include/Map.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ namespace ldso {
* @return true if pose graph thread is started
*/
bool OptimizeALLKFs();

// optimize pose graph on all kfs after odometry loop is done
void lastOptimizeAllKFs();

/// update the cached 3d position of all points.
void UpdateAllWorldPoints();

Expand All @@ -62,7 +65,8 @@ namespace ldso {

set<shared_ptr<Frame>, CmpFrameID> GetAllKFs() { return frames; }

unsigned long lastkfId = 0; // keyframe id of this frame
unsigned long getLatestOptimizedKfId() const { return latestOptimizedKfId; }

private:
// the pose graph optimization thread
void runPoseGraphOptimization();
Expand All @@ -72,6 +76,9 @@ namespace ldso {
set<shared_ptr<Frame>, CmpFrameID> framesOpti; // KFs to be optimized
shared_ptr<Frame> currentKF = nullptr;

// keyframe id of newest optimized keyframe frame
unsigned long latestOptimizedKfId = 0;

bool poseGraphRunning = false; // is pose graph running?
mutex mutexPoseGraph;

Expand Down
16 changes: 14 additions & 2 deletions src/Map.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,21 @@ namespace ldso {
}

void Map::lastOptimizeAllKFs() {
LOG(INFO) << "Final pose graph optimization after odometry is finished.";

{
unique_lock<mutex> lock(mutexPoseGraph);
if (poseGraphRunning) {
LOG(FATAL) << "Should not be called while pose graph optimization is running";
}
}

// no locking of mapMutex since we assume that odometry has finished
framesOpti = frames;
currentKF = *frames.rbegin();
runPoseGraphOptimization();
}

bool Map::OptimizeALLKFs() {
{
unique_lock<mutex> lock(mutexPoseGraph);
Expand Down Expand Up @@ -145,11 +156,12 @@ namespace ldso {
}

poseGraphRunning = false;

if (currentKF) {
lastkfId = currentKF->kfId;
latestOptimizedKfId = currentKF->kfId;
}

if (fullsystem) fullsystem->RefreshGUI();
if (fullsystem) fullsystem->RefreshGUI();
}

}
3 changes: 2 additions & 1 deletion src/frontend/FullSystem.cc
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ namespace ldso {
globalMap->lastOptimizeAllKFs();
}
}

// Update world points in case optimization hasn't run (with all keyframes)
// It would maybe be better if the 3d points would always be updated as soon
// as the poses or depths are updated (no matter if in PGO or in sliding window BA)
Expand Down Expand Up @@ -852,7 +853,7 @@ namespace ldso {
unique_lock<mutex> crlock(shellPoseMutex);
for (auto fr: frames) {
fr->setPose(fr->frameHessian->PRE_camToWorld.inverse());
if (fr->kfId >= globalMap->lastkfId) {
if (fr->kfId >= globalMap->getLatestOptimizedKfId()) {
fr->setPoseOpti(Sim3(fr->getPose().matrix()));
}
fr->aff_g2l = fr->frameHessian->aff_g2l();
Expand Down

0 comments on commit 2944a67

Please sign in to comment.