Skip to content

Commit 51cfa7e

Browse files
authored
Add RemoveTrack to TracksManager to safely remove complete tracks from the underlying data structure
1 parent b72eb60 commit 51cfa7e

2 files changed

Lines changed: 19 additions & 0 deletions

File tree

opensfm/src/map/src/tracks_manager.cc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,24 @@ void TracksManager::RemoveObservation(const ShotId& shot_id,
203203
find_track->second.erase(shot_id);
204204
}
205205

206+
void TracksManager::RemoveTrack(const TrackId& track_id) {
207+
// Step 1: Remove entries from tracks_per_shot_
208+
if (shots_per_track_.count(track_id)) {
209+
const auto& shot_ids = shots_per_track_[track_id];
210+
for (const auto& [shot_id, _] : shot_ids) {
211+
if (tracks_per_shot_.count(shot_id)) {
212+
tracks_per_shot_[shot_id].erase(track_id);
213+
// Remove the Shot entry if no observations remain
214+
if (tracks_per_shot_[shot_id].empty()) {
215+
tracks_per_shot_.erase(shot_id);
216+
}
217+
}
218+
}
219+
// Step 2: Remove the track from shots_per_track_
220+
shots_per_track_.erase(track_id);
221+
}
222+
}
223+
206224
int TracksManager::NumShots() const { return tracks_per_shot_.size(); }
207225

208226
int TracksManager::NumTracks() const { return shots_per_track_.size(); }

opensfm/src/map/tracks_manager.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class TracksManager {
1414
void AddObservation(const ShotId& shot_id, const TrackId& track_id,
1515
const Observation& observation);
1616
void RemoveObservation(const ShotId& shot_id, const TrackId& track_id);
17+
void RemoveTrack(const TrackId& track_id);
1718
Observation GetObservation(const ShotId& shot, const TrackId& track) const;
1819

1920
int NumShots() const;

0 commit comments

Comments
 (0)