@@ -204,22 +204,44 @@ void TracksManager::RemoveObservation(const ShotId& shot_id,
204204}
205205
206206void 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
224246int TracksManager::NumShots () const { return tracks_per_shot_.size (); }
225247
0 commit comments