Skip to content

Commit

Permalink
mri_scale_modified
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeFavelier committed Feb 19, 2022
1 parent ab8fd7d commit 4d669c6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
33 changes: 29 additions & 4 deletions mne/gui/_coreg.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ def _get_default(var, val):
self._fiducials_file = None
self._trans_modified = False
self._mri_fids_modified = False
self._mri_scale_modified = False
self._accept_close_event = True
self._auto_cleanup = True
self._fid_colors = tuple(
Expand Down Expand Up @@ -316,6 +317,7 @@ def _get_default(var, val):
# initialization does not count as modification by the user
self._trans_modified = False
self._mri_fids_modified = False
self._mri_scale_modified = False
if block and self._renderer._kind != 'notebook':
_qt_app_exec(self._renderer.figure.store["app"])

Expand Down Expand Up @@ -450,7 +452,10 @@ def _set_fiducial(self, value, coord):
self._update_plot("mri_fids")

def _set_parameter(self, value, mode_name, coord):
self._trans_modified = True
if mode_name == "scale":
self._mri_scale_modified = True
else:
self._trans_modified = True
if self._params_locked:
return
if mode_name == "scale" and self._scale_mode == "uniform":
Expand Down Expand Up @@ -1231,6 +1236,7 @@ def _save_subject(self):
self._display_message(f"Computing {bem_name} solution..."
" Done!")
self._display_message(f"Saving {self._subject_to}... Done!")
self._mri_scale_modified = False

def _save_mri_fiducials(self, fname):
self._display_message(f"Saving {fname}...")
Expand Down Expand Up @@ -1726,6 +1732,7 @@ def close(self):
self._renderer.close()

def _close_dialog_callback(self, button_name):
from ..viz.backends.renderer import MNE_3D_BACKEND_TESTING
self._accept_close_event = True
if button_name == "Save":
if self._trans_modified:
Expand All @@ -1737,21 +1744,39 @@ def _close_dialog_callback(self, button_name):
if self._mri_fids_modified:
self._forward_widget_command(
"save_mri_fids", "set_value", None)
if self._mri_scale_modified:
if self._subject_to:
self._save_subject()
else:
dialog = self._renderer._dialog_warning(
title="CoregistrationUI",
text="The name of the output subject used to "
"save the scaled anatomy is not set.",
info_text="Please set a subject name",
callback=lambda x: None,
buttons=["Ok"],
modal=not MNE_3D_BACKEND_TESTING,
)
dialog.show()
self._accept_close_event = False
elif button_name == "Cancel":
self._accept_close_event = False
else:
assert button_name == "Discard"

def _close_callback(self):
if self._trans_modified or self._mri_fids_modified:
if self._trans_modified or self._mri_fids_modified or \
self._mri_scale_modified:
from ..viz.backends.renderer import MNE_3D_BACKEND_TESTING
# prepare the dialog's text
text = "The following is/are not saved:"
text += "<ul>"
if self._trans_modified:
text += "<li>Head<>MRI transform</li>"
text += "<li>Head&lt;&gt;MRI transform</li>"
if self._mri_fids_modified:
text += "<li>fiducials</li>"
text += "<li>MRI fiducials</li>"
if self._mri_scale_modified:
text += "<li>scaled subject MRI</li>"
text += "</ul>"
self._widgets["close_dialog"] = self._renderer._dialog_warning(
title="CoregistrationUI",
Expand Down
6 changes: 4 additions & 2 deletions mne/gui/tests/test_coreg_gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ def test_coreg_gui_pyvista(tmp_path, renderer_interactive_pyvistaqt):
assert coreg._fiducials_file == fid_fname

# fitting (with scaling)
assert not coreg._mri_scale_modified
coreg._reset()
coreg._reset_fitting_parameters()
coreg._set_scale_mode("uniform")
Expand All @@ -161,21 +162,22 @@ def test_coreg_gui_pyvista(tmp_path, renderer_interactive_pyvistaqt):
atol=1e-3)
coreg._set_scale_mode("None")
coreg._set_icp_fid_match("matched")
assert coreg._mri_scale_modified

# unlock fiducials
assert coreg._lock_fids
coreg._set_lock_fids(False)
assert not coreg._lock_fids

# picking
assert not coreg._fids_modified
assert not coreg._mri_fids_modified
vtk_picker = TstVTKPicker(coreg._surfaces['head'], 0, (0, 0))
coreg._on_mouse_move(vtk_picker, None)
coreg._on_button_press(vtk_picker, None)
coreg._on_pick(vtk_picker, None)
coreg._on_button_release(vtk_picker, None)
coreg._on_pick(vtk_picker, None) # also pick when locked
assert coreg._fids_modified
assert coreg._mri_fids_modified

# lock fiducials
coreg._set_lock_fids(True)
Expand Down

0 comments on commit 4d669c6

Please sign in to comment.