def test_add_surface(qtbot): """Test adding 3D surface.""" viewer = Viewer() view = viewer.window.qt_viewer qtbot.addWidget(view) np.random.seed(0) vertices = np.random.random((10, 3)) faces = np.random.randint(10, size=(6, 3)) values = np.random.random(10) data = (vertices, faces, values) viewer.add_surface(data) assert np.all( [np.all(vd == d) for vd, d in zip(viewer.layers[0].data, data)] ) assert len(viewer.layers) == 1 assert view.layers.vbox_layout.count() == 2 * len(viewer.layers) + 2 assert viewer.dims.ndim == 3 assert view.dims.nsliders == viewer.dims.ndim assert np.sum(view.dims._displayed_sliders) == 1 # Switch to 3D rendering mode and back to 2D rendering mode viewer.dims.ndisplay = 3 assert viewer.dims.ndisplay == 3 viewer.dims.ndisplay = 2 assert viewer.dims.ndisplay == 2 # Close the viewer viewer.window.close()
def test_data_change_ndisplay_surface(qtbot): """Test change data calls for surface layer with ndisplay change.""" viewer = Viewer() view = viewer.window.qt_viewer qtbot.addWidget(view) np.random.seed(0) vertices = np.random.random((10, 3)) faces = np.random.randint(10, size=(6, 3)) values = np.random.random(10) data = (vertices, faces, values) layer = viewer.add_surface(data) visual = view.layer_to_visual[layer] @patch.object(visual, '_on_data_change', wraps=visual._on_data_change) def test_ndisplay_change(mocked_method, ndisplay=3): viewer.dims.ndisplay = ndisplay mocked_method.assert_called_once() # Switch to 3D rendering mode and back to 2D rendering mode test_ndisplay_change(ndisplay=3) test_ndisplay_change(ndisplay=2) # Close the viewer viewer.window.close()
def test_changing_display_surface(qtbot): """Test adding 3D surface and changing its display.""" viewer = Viewer() view = viewer.window.qt_viewer qtbot.addWidget(view) np.random.seed(0) vertices = np.random.random((10, 3)) faces = np.random.randint(10, size=(6, 3)) values = np.random.random(10) data = (vertices, faces, values) viewer.add_surface(data) assert np.all( [np.all(vd == d) for vd, d in zip(viewer.layers[0].data, data)]) assert len(viewer.layers) == 1 assert view.layers.vbox_layout.count() == 2 * len(viewer.layers) + 2 assert viewer.dims.ndim == 3 assert view.dims.nsliders == viewer.dims.ndim # Check display is currently 2D with one slider assert viewer.layers[0]._data_view.shape[1] == 2 assert np.sum(view.dims._displayed_sliders) == 1 # Make display 3D viewer.dims.ndisplay = 3 assert viewer.layers[0]._data_view.shape[1] == 3 assert np.sum(view.dims._displayed_sliders) == 0 # Make display 2D again viewer.dims.ndisplay = 2 assert viewer.layers[0]._data_view.shape[1] == 2 assert np.sum(view.dims._displayed_sliders) == 1 # Iterate over all values in first dimension len_slider = viewer.dims.range[0] for s in len_slider: viewer.dims.set_point(0, s) # Close the viewer viewer.window.close()
from vispy.color import Colormap first = int((128 * 2) - np.round(255 * (1. - 0.90))) second = (256 - first) colors2 = plt.cm.viridis(np.linspace(0.1, .98, first)) colors3 = plt.cm.YlOrBr(np.linspace(0.25, 1, second)) cols = np.vstack((colors2, colors3)) mymap = Colormap(cols) base_path = 'data-njs/CBIG/stable_projects/brain_parcellation/Schaefer2018_LocalGlobal/Parcellations/FreeSurfer5.3/fsaverage6/' lh_pial = surface.load_surf_mesh(base_path + 'surf/lh.pial') lh_curv = surface.load_surf_data(base_path + 'surf/lh.curv') lg400_atlas = surface.load_surf_data( base_path + 'label/lh.Schaefer2018_400Parcels_7Networks_order.annot') u, idx = np.unique(lg400_atlas, return_inverse=True) ed = np.loadtxt('data-njs/mri/LG400_Med.txt') ed_lh = ed[:200] X = np.insert(ed_lh, 0, 0, axis=0) values = X[idx] with gui_qt(): # create an empty viewer viewer = Viewer(ndisplay=3) # add the mri layer = viewer.add_surface((lh_pial[0], lh_pial[1], lh_curv), name='base') layer = viewer.add_surface((lh_pial[0], lh_pial[1], values), name='gradient', colormap={'mymap': mymap}, opacity=0.8)