code: def test_coreg_gui_pyvista_basic(
      tmp_path, monkeypatch, renderer_interactive_pyvistaqt
  ):
      """Test that using CoregistrationUI matches mne coreg."""
      from mne.gui import coregistration
  
      config = get_config()
      # the sample subject in testing has MRI fids
      assert (
          subjects_dir / "sample" / "bem" / "sample-fiducials.fif"
      ).is_file()
  
      coreg = coregistration(
          subject="sample", subjects_dir=subjects_dir, trans=fname_trans
      )
      assert coreg._lock_fids
      coreg._reset_fiducials()
      coreg.close()
  
      # make it always log the distances
      monkeypatch.setattr(_3d.logger, "info", _3d.logger.warning)
      with catch_logging() as log:
          coreg = coregistration(
              inst=raw_path,
              subject="sample",
              head_high_res=False,  # for speed
              subjects_dir=subjects_dir,
              verbose="debug",
          )
      log = log.getvalue()
      assert "Total 16/78 points inside the surface" in log
      coreg._set_fiducials_file(fid_fname)
      assert coreg._fiducials_file == str(fid_fname)
  
      # fitting (with scaling)
      assert not coreg._mri_scale_modified
      coreg._reset()
      coreg._reset_fitting_parameters()
      coreg._set_scale_mode("uniform")
      coreg._fits_fiducials()
      assert_allclose(
          coreg.coreg._scale,
          np.array([97.46, 97.46, 97.46]) * 1e-2,
          atol=1e-3,
      )
      shown_scale = [coreg._widgets[f"s{x}"].get_value() for x in "XYZ"]
      assert_allclose(shown_scale, coreg.coreg._scale * 100, atol=1e-2)
      coreg._set_icp_fid_match("nearest")
      coreg._set_scale_mode("3-axis")
      coreg._fits_icp()
      assert_allclose(
          coreg.coreg._scale,
          np.array([104.43, 101.47, 125.78]) * 1e-2,
          atol=1e-3,
      )
      shown_scale = [coreg._widgets[f"s{x}"].get_value() for x in "XYZ"]
      assert_allclose(shown_scale, coreg.coreg._scale * 100, atol=1e-2)
      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._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._mri_fids_modified
  
      # lock fiducials
      coreg._set_lock_fids(True)
      assert coreg._lock_fids
  
      # fitting (no scaling)
      assert coreg._nasion_weight == 10.0
      coreg._set_point_weight(11.0, "nasion")
      assert coreg._nasion_weight == 11.0
      coreg._fit_fiducials()
      with catch_logging() as log:
          coreg._redraw()  # actually emit the log
      log = log.getvalue()
      assert "Total 6/78 points inside the surface" in log
      with catch_logging() as log:
          coreg._fit_icp()
          coreg._redraw()
      log = log.getvalue()
      assert "Total 38/78 points inside the surface" in log
      assert coreg.coreg._extra_points_filter is None
      coreg._omit_hsp()
      with catch_logging() as log:
          coreg._redraw()
      log = log.getvalue()
      assert "Total 29/53 points inside the surface" in log
      assert coreg.coreg._extra_points_filter is not None
      coreg._reset_omit_hsp_filter()
      with catch_logging() as log:
          coreg._redraw()
      log = log.getvalue()
      assert "Total 38/78 points inside the surface" in log
      assert coreg.coreg._extra_points_filter is None
  
      assert coreg._grow_hair == 0
      coreg._fit_fiducials()  # go back to few inside to start
      with catch_logging() as log:
          coreg._redraw()
      log = log.getvalue()
      assert "Total 6/78 points inside the surface" in log
      norm = np.linalg.norm(
          coreg._head_geo["rr"]
      )  # what's used for inside
      assert_allclose(norm, 5.949288, atol=1e-3)
      coreg._set_grow_hair(20.0)
      with catch_logging() as log:
          coreg._redraw()
      assert coreg._grow_hair == 20.0
      norm = np.linalg.norm(coreg._head_geo["rr"])
      assert_allclose(norm, 6.555220, atol=1e-3)  # outward
      log = log.getvalue()
      assert (
          "Total 8/78 points inside the surface" in log
      )  # more outside now
  
      # visualization
      assert not coreg._helmet
      assert coreg._actors["helmet"] is None
      coreg._set_helmet(True)
      assert coreg._helmet
      with catch_logging() as log:
          coreg._redraw(verbose="debug")
      log = log.getvalue()
      assert "Drawing helmet" in log
      coreg._set_point_weight(1.0, "nasion")
      coreg._fit_fiducials()
      with catch_logging() as log:
          coreg._redraw(verbose="debug")
      log = log.getvalue()
      assert "Drawing helmet" in log
      assert not coreg._meg_channels
      coreg._set_meg_channels(True)
      assert coreg._meg_channels
      with catch_logging() as log:
          coreg._redraw(verbose="debug")
      assert "Drawing meg sensors" in log.getvalue()
      assert coreg._orient_glyphs
      assert coreg._scale_by_distance
      assert coreg._mark_inside
      assert_allclose(
          coreg._head_opacity,
          float(config.get("MNE_COREG_HEAD_OPACITY", "0.8")),
      )
      assert coreg._hpi_coils
      assert coreg._eeg_channels
      assert coreg._head_shape_points
      assert coreg._scale_mode == "None"
      assert coreg._icp_fid_match == "matched"
      assert coreg._head_resolution is False
  
      assert coreg._trans_modified
      tmp_trans = tmp_path / "tmp-trans.fif"
      coreg._save_trans(tmp_trans)
      assert not coreg._trans_modified
      assert tmp_trans.is_file()
  
      # first, disable auto cleanup
      coreg._renderer._window_close_disconnect(after=True)
      # test _close_callback()
      coreg._renderer._process_events()
      assert coreg._mri_fids_modified  # should prompt
      assert coreg._renderer.plotter.app_window.children() is not None
      assert "close_dialog" not in coreg._widgets
      assert not coreg._renderer.plotter._closed
      assert coreg._accept_close_event
      # make sure it's ignored (PySide6 causes problems here and doesn't wait)
      coreg._accept_close_event = False
      coreg.close()
      assert not coreg._renderer.plotter._closed
      coreg._widgets["close_dialog"].trigger("Discard")  # do not save
      coreg.close()
      assert coreg._renderer.plotter._closed
      coreg._clean()  # finally, cleanup internal structures
      assert coreg._renderer is None
  
      # Coregistration instance should survive
      assert isinstance(coreg.coreg, Coregistration)
  
imports: import os
  from contextlib import nullcontext
  from pathlib import Path
  import numpy
  import pytest
  from numpy.testing import assert_allclose
  import mne
  from mne._fiff.constants import FIFF
  from mne.channels import DigMontage
  from mne.coreg import Coregistration
  from mne.datasets import testing
  from mne.io import read_info
  from mne.io.kit.tests import data_dir
  from mne.utils import catch_logging, get_config
  from mne.viz import _3d
label_desc: Use image node_id 2 for calling a global function with example usage: test_coreg_gui_pyvista_basic(tmp_path, monkeypatch, renderer_interactive_pyvistaqt) without return types