diff --git a/invesalius/constants.py b/invesalius/constants.py index 7e003b2..6ef6481 100644 --- a/invesalius/constants.py +++ b/invesalius/constants.py @@ -659,6 +659,8 @@ BOOLEAN_XOR = 4 MARKER_COLOUR = (1.0, 1.0, 0.) MARKER_SIZE = 2 + +FIDUCIAL_REGISTRATION_TRACKER_SAMPLES = 10 FIDUCIAL_REGISTRATION_ERROR_THRESHOLD = 3.0 SELECT = 0 diff --git a/invesalius/gui/task_navigator.py b/invesalius/gui/task_navigator.py index cf6bf72..38ec010 100644 --- a/invesalius/gui/task_navigator.py +++ b/invesalius/gui/task_navigator.py @@ -566,16 +566,29 @@ class Tracker(): def AreTrackerFiducialsSet(self): return not np.isnan(self.tracker_fiducials).any() - def SetTrackerFiducial(self, fiducial_index): - coord = None + def GetTrackerCoordinates(self, n_samples=1): + coord_raw_samples = {} + coord_samples = {} - coord_raw = dco.GetCoordinates(self.trk_init, self.tracker_id, self.ref_mode_id) + for i in range(n_samples): + coord_raw = dco.GetCoordinates(self.trk_init, self.tracker_id, self.ref_mode_id) - if self.ref_mode_id: - coord = dco.dynamic_reference_m(coord_raw[0, :], coord_raw[1, :]) - else: - coord = coord_raw[0, :] - coord[2] = -coord[2] + if self.ref_mode_id: + coord = dco.dynamic_reference_m(coord_raw[0, :], coord_raw[1, :]) + else: + coord = coord_raw[0, :] + coord[2] = -coord[2] + + coord_raw_samples[i] = coord_raw + coord_samples[i] = coord + + coord_raw_avg = np.median(list(coord_raw_samples.values()), axis=0) + coord_avg = np.median(list(coord_samples.values()), axis=0) + + return coord_avg, coord_raw_avg + + def SetTrackerFiducial(self, fiducial_index): + coord, coord_raw = self.GetTrackerCoordinates(n_samples=const.FIDUCIAL_REGISTRATION_TRACKER_SAMPLES) # Update tracker fiducial with tracker coordinates self.tracker_fiducials[fiducial_index, :] = coord[0:3] -- libgit2 0.21.2