diff --git a/invesalius/data/coordinates.py b/invesalius/data/coordinates.py index dc77df4bf..fed0d444c 100644 --- a/invesalius/data/coordinates.py +++ b/invesalius/data/coordinates.py @@ -253,18 +253,18 @@ def PolarisCoord(tracker_connection: "TrackerConnection", tracker_id: int, ref_m angles_ref = np.degrees(tr.euler_from_quaternion(ref[2:6], axes="rzyx")) trans_ref = np.array(ref[6:9]).astype(float) coord2 = np.hstack((trans_ref, angles_ref)) - + obj_coords = [] for i in range(trck.objs.size()): - obj = trck.objs[i].decode(const.FS_ENCODE).split(",") + obj = trck.objs[i].decode(const.FS_ENCODE).split(",") angles_obj = np.degrees(tr.euler_from_quaternion(obj[2:6], axes="rzyx")) trans_obj = np.array(obj[6:9]).astype(float) obj_coords.append(np.hstack((trans_obj, angles_obj))) - + coord = np.vstack([coord1, coord2, *obj_coords]) marker_visibilities = [trck.probeID, trck.refID] + list(trck.objIDs) - return coord, marker_visibilities + return coord, marker_visibilities def CameraCoord(tracker_connection: "TrackerConnection", tracker_id: int, ref_mode): diff --git a/invesalius/data/tracker_connection.py b/invesalius/data/tracker_connection.py index 399a678a4..09c6cd882 100644 --- a/invesalius/data/tracker_connection.py +++ b/invesalius/data/tracker_connection.py @@ -428,7 +428,7 @@ def Connect(self): com_port = self.configuration["com_port"].encode(const.FS_ENCODE) probe_dir = self.configuration["probe_dir"].encode(const.FS_ENCODE) ref_dir = self.configuration["ref_dir"].encode(const.FS_ENCODE) - obj_dirs = pypolaris.StringVector() # SWIG fails to convert python list to vector, so we directly create StringVector + obj_dirs = pypolaris.StringVector() # SWIG fails to convert python list to vector, so we directly create StringVector for obj_dir in self.configuration["obj_dirs"]: obj_dirs.append(obj_dir.encode(const.FS_ENCODE)) diff --git a/invesalius/data/viewer_volume.py b/invesalius/data/viewer_volume.py index 535d007b2..eff08f135 100644 --- a/invesalius/data/viewer_volume.py +++ b/invesalius/data/viewer_volume.py @@ -343,7 +343,6 @@ def __init__(self, parent): self.positions_above_threshold = None self.cell_id_indexes_above_threshold = None - # LUKATODO: delete this? Publisher.sendMessage("Press target mode button", pressed=False) def UpdateCanvas(self): @@ -616,7 +615,9 @@ def OnSensors(self, marker_visibilities): colour2 = green_color else: colour2 = red_color - if any(coil_ids): #LUKATODO: add subscript to show how many coils are visible (green when all visible, orange when some not) + if any( + coil_ids + ): # LUKATODO: add subscript to show how many coils are visible (green when all visible, orange when some not) colour3 = green_color else: colour3 = red_color @@ -2173,7 +2174,7 @@ def GetEnorm(self, enorm_data, plot_vector): if session.GetConfig("debug_efield"): self.e_field_norms = enorm_data[3][self.Id_list, 0] self.e_field_col1 = enorm_data[3][self.Id_list, 1] - self.e_field_col2 = enorm_data[3][self.Id_list, 1] #LUKATODO: is this a typo? + self.e_field_col2 = enorm_data[3][self.Id_list, 1] # LUKATODO: is this a typo? self.e_field_col3 = enorm_data[3][self.Id_list, 3] self.Idmax = np.array(self.Id_list[np.array(self.e_field_norms).argmax()]) max = np.array(self.e_field_norms).argmax() diff --git a/invesalius/data/visualization/coil_visualizer.py b/invesalius/data/visualization/coil_visualizer.py index 6c5c03407..e80273ceb 100644 --- a/invesalius/data/visualization/coil_visualizer.py +++ b/invesalius/data/visualization/coil_visualizer.py @@ -110,13 +110,13 @@ def SetCoilAtTarget(self, state): # Set the color of both target coil (representing the target) and the coil center (representing the actual coil). self.target_coil_actor.GetProperty().SetDiffuseColor(target_coil_color) - # self.coil_center_actor.GetProperty().SetDiffuseColor(target_coil_color) # LUKATODO + # self.coil_center_actor.GetProperty().SetDiffuseColor(target_coil_color) # LUKATODO: use main_coil from navigation? def OnNavigationStatus(self, nav_status, vis_status): self.is_navigating = nav_status # Called when 'show coil' button is pressed in the user interface or in code. - # LUKATODO: Right-click 'show coil' button to open combobox to choose specific coil to show/hide? + # LUKATODO: Right-click 'show coil' button to open combobox for choosing specific coil to show/hide def ShowCoil(self, state, coil_name=None): if coil_name is None: # Show/hide all coils for coil in self.coils.values(): @@ -127,7 +127,7 @@ def ShowCoil(self, state, coil_name=None): # LUKATODO: target? if self.target_coil_actor is not None: self.target_coil_actor.SetVisibility(state) - self.vector_field_assembly.SetVisibility(state) + # self.vector_field_assembly.SetVisibility(state) # LUKATODO: Keep this hidden for now if not self.is_navigating: self.interactor.Render() @@ -177,7 +177,7 @@ def AddTargetCoil(self, m_target): self.target_coil_actor.GetProperty().SetSpecular(0.5) self.target_coil_actor.GetProperty().SetSpecularPower(10) self.target_coil_actor.GetProperty().SetOpacity(0.3) - self.target_coil_actor.SetVisibility(True) #LUKATODO + self.target_coil_actor.SetVisibility(True) self.target_coil_actor.SetUserMatrix(m_target) self.renderer.AddActor(self.target_coil_actor) @@ -288,4 +288,4 @@ def UpdateCoilPoses(self, m_imgs, coords): self.coils[name]["center_actor"].SetUserMatrix(m_img_vtk) # LUKATODO - self.vector_field_assembly.SetUserMatrix(m_img_vtk) + # self.vector_field_assembly.SetUserMatrix(m_img_vtk) diff --git a/invesalius/gui/default_viewers.py b/invesalius/gui/default_viewers.py index 4e1d4ab43..d762c1d65 100644 --- a/invesalius/gui/default_viewers.py +++ b/invesalius/gui/default_viewers.py @@ -161,7 +161,9 @@ def __bind_events(self): def MaximizeViewerVolume(self, enabled=True): if enabled: - self.aui_manager.MaximizePane(self.aui_manager.GetAllPanes()[-1]) # Viewer volume is the last pane + self.aui_manager.MaximizePane( + self.aui_manager.GetAllPanes()[-1] + ) # Viewer volume is the last pane Publisher.sendMessage("Show raycasting widget") else: self.aui_manager.RestoreMaximizedPane() diff --git a/invesalius/gui/dialogs.py b/invesalius/gui/dialogs.py index 8afc89ea7..567588789 100644 --- a/invesalius/gui/dialogs.py +++ b/invesalius/gui/dialogs.py @@ -6867,7 +6867,9 @@ def _init_gui(self) -> None: self.dir_objs.append(dir_obj) row_obj = wx.BoxSizer(wx.VERTICAL) - row_obj.Add(wx.StaticText(self, wx.ID_ANY, f"Coil {i+1} ROM file:"), 0, wx.TOP | wx.RIGHT, 5) + row_obj.Add( + wx.StaticText(self, wx.ID_ANY, f"Coil {i+1} ROM file:"), 0, wx.TOP | wx.RIGHT, 5 + ) row_obj.Add(dir_obj, 0, wx.ALL | wx.CENTER | wx.EXPAND) row_objs.append(row_obj) diff --git a/invesalius/gui/preferences.py b/invesalius/gui/preferences.py index 912d84c24..d1fe349d3 100644 --- a/invesalius/gui/preferences.py +++ b/invesalius/gui/preferences.py @@ -468,7 +468,7 @@ def __init__(self, parent, navigation, tracker, pedal_connector, neuronavigation self.pedal_connector = pedal_connector self.neuronavigation_api = neuronavigation_api self.navigation = navigation - self.coil_registrations = {} + self.coil_registrations = {} self.__bind_events() # Sizer for displaying instructions @@ -494,7 +494,7 @@ def __init__(self, parent, navigation, tracker, pedal_connector, neuronavigation ), ) self.inner_sel_sizer = inner_sel_sizer = wx.FlexGridSizer(10, 1, 1) - + # Coils are selected by toggling coil-buttons self.coil_btns = {} self.no_coils_lbl = None @@ -533,14 +533,13 @@ def __init__(self, parent, navigation, tracker, pedal_connector, neuronavigation coil_sizer.Add(inner_coil_sizer, 0, wx.ALL | wx.EXPAND, 10) # Angle/Dist thresholds, timestamp interval - self.angle_threshold = ( - self.session.GetConfig("angle_threshold", const.DEFAULT_ANGLE_THRESHOLD) + self.angle_threshold = self.session.GetConfig( + "angle_threshold", const.DEFAULT_ANGLE_THRESHOLD ) - self.distance_threshold = ( - self.session.GetConfig("distance_threshold", const.DEFAULT_DISTANCE_THRESHOLD) + self.distance_threshold = self.session.GetConfig( + "distance_threshold", const.DEFAULT_DISTANCE_THRESHOLD ) - # Change angles threshold text_angles = wx.StaticText(self, -1, _("Angle threshold (degrees):")) spin_size_angles = wx.SpinCtrlDouble(self, -1, "", size=wx.Size(50, 23)) @@ -601,11 +600,9 @@ def __init__(self, parent, navigation, tracker, pedal_connector, neuronavigation ] ) self.SetSizerAndFit(main_sizer) - - self.LoadConfig() - self.Layout() - + self.LoadConfig() + self.Layout() def AddCoilButton(self, coil_name): if self.no_coils_lbl is not None: @@ -641,13 +638,13 @@ def OnSetCoilCount(self, n_coils): def LoadConfig(self): state = self.session.GetConfig("navigation", {}) - self.coil_registrations = self.session.GetConfig("coil_registrations", {}) - # Add a button for each coil + self.coil_registrations = self.session.GetConfig("coil_registrations", {}) + # Add a button for each coil for coil_name in self.coil_registrations: self.AddCoilButton(coil_name) - + # Press the buttons for coils that were selected in config file - selected_coils = state.get("selected_coils", []) + selected_coils = state.get("selected_coils", []) for coil_name in selected_coils: self.coil_btns[coil_name][0].SetValue(True) @@ -658,13 +655,12 @@ def LoadConfig(self): self.sel_sizer.GetStaticBox().SetLabel( f"TMS coil selection ({n_coils_selected} out of {n_coils})" ) - + if n_coils_selected == n_coils: # Allow only n_coils buttons to be pressed, so disable unpressed buttons for btn, *junk in self.coil_btns.values(): btn.Enable(btn.GetValue()) - def OnSelectCoil(self, event=None, name=None, select=False): coil_registration = None navigation = self.navigation @@ -706,7 +702,7 @@ def OnSelectCoil(self, event=None, name=None, select=False): # Select/Unselect coil Publisher.sendMessage("Select coil", coil_name=name, coil_registration=coil_registration) - + n_coils_selected = len(navigation.coil_registrations) n_coils = navigation.n_coils # Update label telling how many coils to select @@ -724,9 +720,7 @@ def OnSelectCoil(self, event=None, name=None, select=False): for btn, *junk in self.coil_btns.values(): btn.Enable(btn.GetValue()) else: # Enable all buttons - Publisher.sendMessage( - "Coil selection done", done=False - ) + Publisher.sendMessage("Coil selection done", done=False) for btn, *junk in self.coil_btns.values(): btn.Enable(True) @@ -777,15 +771,17 @@ def DeleteCoil(event, name): delete_coil = menu.Append(wx.ID_ANY, "Delete coil") set_obj_id = menu.Append(wx.ID_ANY, "Set coil index") save_coil = menu.Append(wx.ID_ANY, "Save coil to OBR file") - + self.Bind(wx.EVT_MENU, (lambda event, name=name: DeleteCoil(event, name)), delete_coil) self.Bind(wx.EVT_MENU, (lambda event, name=name: SetObjID(event, name)), set_obj_id) - self.Bind(wx.EVT_MENU, (lambda event, name=name: self.OnSaveCoilToOBR(event, name)), save_coil) + self.Bind( + wx.EVT_MENU, (lambda event, name=name: self.OnSaveCoilToOBR(event, name)), save_coil + ) self.PopupMenu(menu, event.GetPosition()) menu.Destroy() def OnCreateNewCoil(self, event=None): - # Create a coil registration and save it by the given name + # Create a coil registration and save it by the given name # Also used to edit coil registrations by overwriting to the same name if self.tracker.IsTrackerInitialized(): dialog = dlg.ObjectCalibrationDialog( @@ -801,17 +797,20 @@ def OnCreateNewCoil(self, event=None): # Warn that we are overwriting an old registration dialog = wx.TextEntryDialog( None, - _("A registration with this name already exists. Enter a new name or overwrite an old coil registration"), + _( + "A registration with this name already exists. Enter a new name or overwrite an old coil registration" + ), _("Warning: Coil Name Conflict"), value=coil_name, ) if dialog.ShowModal() == wx.ID_OK: - coil_name = dialog.GetValue().strip() # Update coil_name with user input + coil_name = ( + dialog.GetValue().strip() + ) # Update coil_name with user input else: return # Cancel the operation if the user closes the dialog or cancels dialog.Destroy() - # LUKATODO: update coil mesh elsewhere # self.neuronavigation_api.update_coil_mesh(polydata) @@ -832,11 +831,8 @@ def OnCreateNewCoil(self, event=None): if coil_btn.GetValue(): coil_btn.SetValue(False) self.OnSelectCoil(name=coil_name, select=False) - - self.Layout() - # LUKATODO: delete the below with dependencies - Publisher.sendMessage("Press target mode button", pressed=False) + self.Layout() except wx.PyAssertionError: # TODO FIX: win64 pass @@ -870,7 +866,9 @@ def OnLoadCoilFromOBR(self, event=None): # Warn that we are overwriting an old registration dialog = wx.TextEntryDialog( None, - _("A registration with this name already exists. Enter a new name or overwrite an old coil registration"), + _( + "A registration with this name already exists. Enter a new name or overwrite an old coil registration" + ), _("Warning: Coil Name Conflict"), value=coil_name, ) @@ -888,7 +886,7 @@ def OnLoadCoilFromOBR(self, event=None): coil_path = os.path.join(inv_paths.OBJ_DIR, "magstim_fig8_coil.stl") # LUKATODO: what is neuronavigation_api.update_coil_mesh ? - #if polydata: + # if polydata: # self.neuronavigation_api.update_coil_mesh(polydata) if np.isfinite(obj_fiducials).all() and np.isfinite(obj_orients).all(): @@ -925,7 +923,7 @@ def OnLoadCoilFromOBR(self, event=None): def OnSaveCoilToOBR(self, evt, coil_name): coil_registration = self.coil_registrations[coil_name] - + filename = dlg.ShowLoadSaveDialog( message=_("Save object registration as..."), wildcard=_("Registration files (*.obr)|*.obr"), @@ -935,7 +933,7 @@ def OnSaveCoilToOBR(self, evt, coil_name): ) if filename: hdr = ( - coil_name + coil_name + "\t" + utils.decode(coil_registration["path"], const.FS_ENCODE) + "\t" @@ -951,7 +949,6 @@ def OnSaveCoilToOBR(self, evt, coil_name): np.savetxt(filename, data, fmt="%.4f", delimiter="\t", newline="\n", header=hdr) wx.MessageBox(_("Object file successfully saved"), _("Save")) - def OnSelectAngleThreshold(self, evt, ctrl): self.angle_threshold = ctrl.GetValue() Publisher.sendMessage("Update angle threshold", angle=self.angle_threshold) @@ -1152,7 +1149,7 @@ def OnChooseNoOfCoils(self, evt, ctrl): else: self.n_coils = 1 - if self.n_coils != old_n_coils: # if n_coils was changed reset connection + if self.n_coils != old_n_coils: # if n_coils was changed reset connection tracker_id = self.tracker.tracker_id self.tracker.DisconnectTracker() self.tracker.SetTracker(tracker_id, n_coils=self.n_coils) diff --git a/invesalius/gui/task_navigator.py b/invesalius/gui/task_navigator.py index c9a56433f..9eae83027 100644 --- a/invesalius/gui/task_navigator.py +++ b/invesalius/gui/task_navigator.py @@ -276,7 +276,7 @@ def OnShowCoil(self, evt=None): Publisher.sendMessage("Show coil in viewer volume", state=pressed) def CollapseNavigation(self, done): - if not done: # Coil selection is no longer complete, so hide navigation panel + if not done: # Coil selection is no longer complete, so hide navigation panel self.fold_panel.Collapse(self.nav_panel) def OnFoldPressCaption(self, evt): @@ -443,19 +443,19 @@ def __init__(self, parent, nav_hub): sizer = wx.GridBagSizer(5, 5) sizer.Add( - self.btns_set_fiducial[0], # Left Ear + self.btns_set_fiducial[0], # Left Ear wx.GBPosition(1, 0), span=wx.GBSpan(1, 2), flag=wx.ALIGN_CENTER_VERTICAL, ) sizer.Add( - self.btns_set_fiducial[2], # Nasion + self.btns_set_fiducial[2], # Nasion wx.GBPosition(0, 2), span=wx.GBSpan(1, 2), flag=wx.ALIGN_CENTER_HORIZONTAL, ) sizer.Add( - self.btns_set_fiducial[1], # Right Ear + self.btns_set_fiducial[1], # Right Ear wx.GBPosition(1, 3), span=wx.GBSpan(1, 2), flag=wx.ALIGN_CENTER_VERTICAL, @@ -677,19 +677,19 @@ def __init__(self, parent, nav_hub): sizer = wx.GridBagSizer(5, 5) sizer.Add( - self.fiducial_buttons[0], # Left Ear + self.fiducial_buttons[0], # Left Ear wx.GBPosition(1, 0), span=wx.GBSpan(1, 2), flag=wx.ALIGN_CENTER_VERTICAL, ) sizer.Add( - self.fiducial_buttons[2], # Nasion + self.fiducial_buttons[2], # Nasion wx.GBPosition(0, 2), span=wx.GBSpan(1, 2), flag=wx.ALIGN_CENTER_HORIZONTAL, ) sizer.Add( - self.fiducial_buttons[1], # Right Ear + self.fiducial_buttons[1], # Right Ear wx.GBPosition(1, 3), span=wx.GBSpan(1, 2), flag=wx.ALIGN_CENTER_VERTICAL, @@ -1112,7 +1112,13 @@ def __init__(self, parent, nav_hub): border = wx.FlexGridSizer(1, 2, 1) self.coil_registrations = [] - lbl = wx.StaticText(self, -1, _(f"Ready for navigation with {self.navigation.n_coils} coil{'' if self.navigation.n_coils == 1 else 's'}!")) + lbl = wx.StaticText( + self, + -1, + _( + f"Ready for navigation with {self.navigation.n_coils} coil{'' if self.navigation.n_coils == 1 else 's'}!" + ), + ) # lbl.SetFont(wx.Font(9, wx.DEFAULT, wx.NORMAL, wx.BOLD)) self.lbl = lbl @@ -1159,7 +1165,9 @@ def OnCloseProject(self): def CoilSelectionDone(self, done): if done: - self.lbl.SetLabel(f"Ready for navigation with {self.navigation.n_coils} coil{'' if self.navigation.n_coils == 1 else 's'}!") + self.lbl.SetLabel( + f"Ready for navigation with {self.navigation.n_coils} coil{'' if self.navigation.n_coils == 1 else 's'}!" + ) else: self.lbl.SetLabel("Please select which coil(s) to track") @@ -1727,7 +1735,6 @@ def OnTrackObjectButton(self, evt=None, ctrl=None): Publisher.sendMessage("Press show-coil button", pressed=pressed) Publisher.sendMessage("Press show-probe button", pressed=(not pressed)) - # 'Lock to Target' button def OnLockToTargetButton(self, evt, ctrl): self.UpdateToggleButton(ctrl) @@ -1972,7 +1979,7 @@ def __init__(self, parent, nav_hub): wx.EVT_COMBOBOX, partial(self.OnChooseMainCoil, ctrl=select_main_coil) ) - # If main coil is defined, select this in the combobox + # If main coil is defined, select this in the combobox nav_state = self.session.GetConfig("navigation", {}) if (main_coil := nav_state.get("main_coil", None)) is not None: main_coil_index = select_main_coil.FindString(main_coil) @@ -2489,7 +2496,6 @@ def OnChooseMainCoil(self, evt, ctrl): self.navigation.SetMainCoil(main_coil) ctrl.SetSelection(choice) - def ChangeLabel(self, evt): list_index = self.marker_list_ctrl.GetFocusedItem() if list_index == -1: diff --git a/invesalius/navigation/robot.py b/invesalius/navigation/robot.py index 9d74e255d..d8df02893 100644 --- a/invesalius/navigation/robot.py +++ b/invesalius/navigation/robot.py @@ -178,7 +178,11 @@ def SendTargetToRobot(self): target = self.target[:] target[1] = -target[1] m_target = dcr.image_to_tracker( - navigation.m_change, coord_raw, target, self.icp, navigation.obj_datas[navigation.main_coil] + navigation.m_change, + coord_raw, + target, + self.icp, + navigation.obj_datas[navigation.main_coil], ) Publisher.sendMessage(