Commit 2fbc32ff63d55ea592c51602d78883a6fc287409
Committed by
GitHub
1 parent
30ae50b1
Exists in
master
FIX: Loading image fiducials from disk (#295)
- It had broken due to a mix-up between fiducial name ("LE") and label ("LEI"). Fix by doing the mapping from label (which is stored on disk) to name before triggering 'Set image fiducial' event. Co-authored-by: Olli-Pekka Kahilakoski <olli-pekka.kahilakoski@aalto.fi>
Showing
1 changed file
with
25 additions
and
14 deletions
Show diff stats
invesalius/gui/task_navigator.py
@@ -482,27 +482,38 @@ class NeuronavigationPanel(wx.Panel): | @@ -482,27 +482,38 @@ class NeuronavigationPanel(wx.Panel): | ||
482 | Publisher.subscribe(self.UpdateTarget, 'Update target') | 482 | Publisher.subscribe(self.UpdateTarget, 'Update target') |
483 | 483 | ||
484 | def LoadImageFiducials(self, marker_id, coord): | 484 | def LoadImageFiducials(self, marker_id, coord): |
485 | - for n in const.BTNS_IMG_MARKERS: | ||
486 | - btn_id = list(const.BTNS_IMG_MARKERS[n].keys())[0] | ||
487 | - fiducial_name = list(const.BTNS_IMG_MARKERS[n].values())[0] | ||
488 | - if marker_id == fiducial_name and not self.btns_coord[btn_id].GetValue(): | ||
489 | - self.btns_coord[btn_id].SetValue(True) | ||
490 | - Publisher.sendMessage('Set image fiducial', fiducial_name=fiducial_name, coord=coord[0:3]) | ||
491 | - for m in [0, 1, 2]: | ||
492 | - self.numctrls_coord[btn_id][m].SetValue(coord[m]) | ||
493 | - | ||
494 | - def FiducialNameToIndex(self, fiducials, fiducial_name): | ||
495 | - fiducial = [fiducial for fiducial in fiducials if fiducial['fiducial_name'] == fiducial_name][0] | ||
496 | - return fiducial['fiducial_index'] | 485 | + fiducial = self.GetFiducialByAttribute(const.IMAGE_FIDUCIALS, 'label', marker_id) |
486 | + | ||
487 | + fiducial_index = fiducial['fiducial_index'] | ||
488 | + fiducial_name = fiducial['fiducial_name'] | ||
489 | + | ||
490 | + if self.btns_coord[fiducial_index].GetValue(): | ||
491 | + print("Fiducial {} already set, not resetting".format(marker_id)) | ||
492 | + return | ||
493 | + | ||
494 | + Publisher.sendMessage('Set image fiducial', fiducial_name=fiducial_name, coord=coord[0:3]) | ||
495 | + | ||
496 | + self.btns_coord[fiducial_index].SetValue(True) | ||
497 | + for m in [0, 1, 2]: | ||
498 | + self.numctrls_coord[fiducial_index][m].SetValue(coord[m]) | ||
499 | + | ||
500 | + def GetFiducialByAttribute(self, fiducials, attribute_name, attribute_value): | ||
501 | + found = [fiducial for fiducial in fiducials if fiducial[attribute_name] == attribute_value] | ||
502 | + | ||
503 | + assert len(found) != 0, "No fiducial found for which {} = {}".format(attribute_name, attribute_value) | ||
504 | + return found[0] | ||
497 | 505 | ||
498 | def SetImageFiducial(self, fiducial_name, coord): | 506 | def SetImageFiducial(self, fiducial_name, coord): |
499 | - fiducial_index = self.FiducialNameToIndex(const.IMAGE_FIDUCIALS, fiducial_name) | 507 | + fiducial = self.GetFiducialByAttribute(const.IMAGE_FIDUCIALS, 'fiducial_name', fiducial_name) |
508 | + fiducial_index = fiducial['fiducial_index'] | ||
500 | self.fiducials[fiducial_index, :] = coord | 509 | self.fiducials[fiducial_index, :] = coord |
501 | 510 | ||
502 | print("Set image fiducial {} to coordinates {}".format(fiducial_name, coord)) | 511 | print("Set image fiducial {} to coordinates {}".format(fiducial_name, coord)) |
503 | 512 | ||
504 | def SetTrackerFiducial(self, fiducial_name): | 513 | def SetTrackerFiducial(self, fiducial_name): |
505 | - fiducial_index = self.FiducialNameToIndex(const.TRACKER_FIDUCIALS, fiducial_name) | 514 | + fiducial = self.GetFiducialByAttribute(const.TRACKER_FIDUCIALS, 'fiducial_name', fiducial_name) |
515 | + fiducial_index = fiducial['fiducial_index'] | ||
516 | + | ||
506 | coord = None | 517 | coord = None |
507 | 518 | ||
508 | if not(self.trk_init and self.tracker_id): | 519 | if not(self.trk_init and self.tracker_id): |