Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MNT: 3d viewer loc and idx #8998

Merged
merged 1 commit into from
Mar 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions mne/viz/_brain/_brain.py
Original file line number Diff line number Diff line change
Expand Up @@ -992,7 +992,7 @@ def _configure_dock_orientation_widget(self, name):
if len(rends) > 1:
def select_renderer(idx):
idx = int(idx)
loc = self.plotter.index_to_loc(idx)
loc = self._renderer._index_to_loc(idx)
self.plotter.subplot(*loc)

self.callbacks["renderer"] = SmartCallBack(
Expand All @@ -1019,7 +1019,7 @@ def select_renderer(idx):
orientation_data = [None] * len(rends)
for hemi in hemis_ref:
for ri, ci, view in self._iter_views(hemi):
idx = self.plotter.loc_to_index((ri, ci))
idx = self._renderer._loc_to_index((ri, ci))
if view == 'flat':
_data = None
else:
Expand Down Expand Up @@ -1639,7 +1639,7 @@ def _add_vertex_glyph(self, hemi, mesh, vertex_id):

# from the picked renderer to the subplot coords
rindex = self.plotter.renderers.index(self.picked_renderer)
row, col = self.plotter.index_to_loc(rindex)
row, col = self._renderer._index_to_loc(rindex)

actors = list()
spheres = list()
Expand Down
16 changes: 13 additions & 3 deletions mne/viz/backends/_pyvista.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def __init__(self, plotter=None,
# multi_samples > 1 is broken on macOS + Intel Iris + volume rendering
self.store['multi_samples'] = 1 if sys.platform == 'darwin' else 4

self._nrows, self._ncols = self.store["shape"]
self._azimuth = self._elevation = None

def build(self):
Expand Down Expand Up @@ -172,7 +173,6 @@ def __init__(self, fig=None, size=(600, 600), bgcolor='black',
smooth_shading=smooth_shading)
self.font_family = "arial"
self.tube_n_sides = 20
self.shape = shape
antialias = _get_3d_option('antialias')
self.antialias = antialias and not MNE_3D_BACKEND_TESTING
if isinstance(fig, int):
Expand Down Expand Up @@ -249,9 +249,19 @@ def _ensure_minimum_sizes(self):
_process_events(self.plotter)
_process_events(self.plotter)

def _index_to_loc(self, idx):
_ncols = self.figure._ncols
row = idx // _ncols
col = idx % _ncols
return (row, col)

def _loc_to_index(self, loc):
_ncols = self.figure._ncols
return loc[0] * _ncols + loc[1]

def subplot(self, x, y):
x = np.max([0, np.min([x, self.shape[0] - 1])])
y = np.max([0, np.min([y, self.shape[1] - 1])])
x = np.max([0, np.min([x, self.figure._nrows - 1])])
y = np.max([0, np.min([y, self.figure._ncols - 1])])
with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=FutureWarning)
self.plotter.subplot(x, y)
Expand Down