Skip to content

Commit f99f2f5

Browse files
authored
Added RemoveShot
1 parent cb62683 commit f99f2f5

4 files changed

Lines changed: 37 additions & 12 deletions

File tree

opensfm/src/map/pymap.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,7 @@ class TracksManager:
586586
def num_tracks(self) -> int: ...
587587
def remove_observation(self, arg0: str, arg1: str) -> None: ...
588588
def remove_track(self, arg0: str) -> None: ...
589+
def remove_shot(self, arg0: str) -> None: ...
589590
def write_to_file(self, arg0: str) -> None: ...
590591

591592
Angular: "ErrorType"

opensfm/src/map/python/pybind.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ PYBIND11_MODULE(pymap, m) {
293293
.def("add_observation", &map::TracksManager::AddObservation)
294294
.def("remove_observation", &map::TracksManager::RemoveObservation)
295295
.def("remove_track", &map::TracksManager::RemoveTrack)
296+
.def("remove_shot", &map::TracksManager::RemoveShot)
296297
.def("num_shots", &map::TracksManager::NumShots)
297298
.def("num_tracks", &map::TracksManager::NumTracks)
298299
.def("get_shot_ids", &map::TracksManager::GetShotIds)

opensfm/src/map/src/tracks_manager.cc

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -204,22 +204,44 @@ void TracksManager::RemoveObservation(const ShotId& shot_id,
204204
}
205205

206206
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-
}
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+
224+
void TracksManager::RemoveShot(const ShotId& shot_id) {
225+
// Remove shot from tracks_per_shot_
226+
const auto find_shot = tracks_per_shot_.find(shot_id);
227+
if (find_shot != tracks_per_shot_.end()) {
228+
// Iterate all tracks which are observed by the shot
229+
for (const auto& [track_id, _] : find_shot->second) {
230+
// Remove the shot from the corrsponding track-list in shots_per_track_
231+
if (shots_per_track_.count(track_id)) {
232+
shots_per_track_[track_id].erase(shot_id);
233+
// Remove the track entry if no observations remain
234+
if (shots_per_track_[track_id].empty()) {
235+
shots_per_track_.erase(track_id);
217236
}
218237
}
219-
// Step 2: Remove the track from shots_per_track_
220-
shots_per_track_.erase(track_id);
221238
}
239+
tracks_per_shot_.erase(shot_id);
222240
}
241+
else {
242+
throw std::runtime_error("Shot ID not found");
243+
}
244+
}
223245

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

opensfm/src/map/tracks_manager.h

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

2021
int NumShots() const;

0 commit comments

Comments
 (0)