Skip to content

Commit

Permalink
Add RemoveTrack to TracksManager to safely remove complete tracks fro…
Browse files Browse the repository at this point in the history
…m the underlying data structure
  • Loading branch information
kielnino authored Dec 16, 2024
1 parent b72eb60 commit 51cfa7e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
18 changes: 18 additions & 0 deletions opensfm/src/map/src/tracks_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,24 @@ void TracksManager::RemoveObservation(const ShotId& shot_id,
find_track->second.erase(shot_id);
}

void TracksManager::RemoveTrack(const TrackId& track_id) {
// Step 1: Remove entries from tracks_per_shot_
if (shots_per_track_.count(track_id)) {
const auto& shot_ids = shots_per_track_[track_id];
for (const auto& [shot_id, _] : shot_ids) {
if (tracks_per_shot_.count(shot_id)) {
tracks_per_shot_[shot_id].erase(track_id);
// Remove the Shot entry if no observations remain
if (tracks_per_shot_[shot_id].empty()) {
tracks_per_shot_.erase(shot_id);
}
}
}
// Step 2: Remove the track from shots_per_track_
shots_per_track_.erase(track_id);
}
}

int TracksManager::NumShots() const { return tracks_per_shot_.size(); }

int TracksManager::NumTracks() const { return shots_per_track_.size(); }
Expand Down
1 change: 1 addition & 0 deletions opensfm/src/map/tracks_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class TracksManager {
void AddObservation(const ShotId& shot_id, const TrackId& track_id,
const Observation& observation);
void RemoveObservation(const ShotId& shot_id, const TrackId& track_id);
void RemoveTrack(const TrackId& track_id);
Observation GetObservation(const ShotId& shot, const TrackId& track) const;

int NumShots() const;
Expand Down

0 comments on commit 51cfa7e

Please sign in to comment.