def test_bundle_maps(): scene = window.Scene() bundle = simulated_bundle(no_streamlines=10, waves=False) metric = 100 * np.ones((200, 200, 200)) # add lower values metric[100, :, :] = 100 * 0.5 # create a nice orange-red colormap lut = actor.colormap_lookup_table(scale_range=(0., 100.), hue_range=(0., 0.1), saturation_range=(1, 1), value_range=(1., 1)) line = actor.line(bundle, metric, linewidth=0.1, lookup_colormap=lut) scene.add(line) scene.add(actor.scalar_bar(lut, ' ')) report = window.analyze_scene(scene) npt.assert_almost_equal(report.actors, 1) # window.show(scene) scene.clear() nb_points = np.sum([len(b) for b in bundle]) values = 100 * np.random.rand(nb_points) # values[:nb_points/2] = 0 line = actor.streamtube(bundle, values, linewidth=0.1, lookup_colormap=lut) scene.add(line) # window.show(scene) report = window.analyze_scene(scene) npt.assert_equal(report.actors_classnames[0], 'vtkLODActor') scene.clear() colors = np.random.rand(nb_points, 3) # values[:nb_points/2] = 0 line = actor.line(bundle, colors, linewidth=2) scene.add(line) # window.show(scene) report = window.analyze_scene(scene) npt.assert_equal(report.actors_classnames[0], 'vtkLODActor') # window.show(scene) arr = window.snapshot(scene) report2 = window.analyze_snapshot(arr) npt.assert_equal(report2.objects, 1) # try other input options for colors scene.clear() actor.line(bundle, (1., 0.5, 0)) actor.line(bundle, np.arange(len(bundle))) actor.line(bundle) colors = [np.random.rand(*b.shape) for b in bundle] actor.line(bundle, colors=colors)
scene.camera_info() ############################################################################### # Show every point with a value from a volume with default colormap # ================================================================= # # Here we will need to input the ``fa`` map in ``streamtube`` or ``line``. scene.clear() stream_actor2 = actor.line(bundle_native, fa, linewidth=0.1) ############################################################################### # We can also show the scalar bar. bar = actor.scalar_bar() scene.add(stream_actor2) scene.add(bar) # window.show(scene, size=(600, 600), reset_camera=False) window.record(scene, out_path='bundle2.png', size=(600, 600)) ############################################################################## # Show every point with a value from a volume with your colormap # ============================================================== # # Here we will need to input the ``fa`` map in ``streamtube`` scene.clear()
def test_bundle_maps(): renderer = window.renderer() bundle = fornix_streamlines() bundle, shift = center_streamlines(bundle) mat = np.array([[1, 0, 0, 100], [0, 1, 0, 100], [0, 0, 1, 100], [0, 0, 0, 1.]]) bundle = transform_streamlines(bundle, mat) # metric = np.random.rand(*(200, 200, 200)) metric = 100 * np.ones((200, 200, 200)) # add lower values metric[100, :, :] = 100 * 0.5 # create a nice orange-red colormap lut = actor.colormap_lookup_table(scale_range=(0., 100.), hue_range=(0., 0.1), saturation_range=(1, 1), value_range=(1., 1)) line = actor.line(bundle, metric, linewidth=0.1, lookup_colormap=lut) window.add(renderer, line) window.add(renderer, actor.scalar_bar(lut, ' ')) report = window.analyze_renderer(renderer) npt.assert_almost_equal(report.actors, 1) # window.show(renderer) renderer.clear() nb_points = np.sum([len(b) for b in bundle]) values = 100 * np.random.rand(nb_points) # values[:nb_points/2] = 0 line = actor.streamtube(bundle, values, linewidth=0.1, lookup_colormap=lut) renderer.add(line) # window.show(renderer) report = window.analyze_renderer(renderer) npt.assert_equal(report.actors_classnames[0], 'vtkLODActor') renderer.clear() colors = np.random.rand(nb_points, 3) # values[:nb_points/2] = 0 line = actor.line(bundle, colors, linewidth=2) renderer.add(line) # window.show(renderer) report = window.analyze_renderer(renderer) npt.assert_equal(report.actors_classnames[0], 'vtkLODActor') # window.show(renderer) arr = window.snapshot(renderer) report2 = window.analyze_snapshot(arr) npt.assert_equal(report2.objects, 1) # try other input options for colors renderer.clear() actor.line(bundle, (1., 0.5, 0)) actor.line(bundle, np.arange(len(bundle))) actor.line(bundle) colors = [np.random.rand(*b.shape) for b in bundle] actor.line(bundle, colors=colors)
def test_manifest_pbr_vtk(): # Test non-supported property test_actor = actor.text_3d('Test') npt.assert_warns(UserWarning, material.manifest_pbr, test_actor) # Test non-supported PBR interpolation test_actor = actor.scalar_bar() npt.assert_warns(UserWarning, material.manifest_pbr, test_actor) # Create tmp dir to save and query images # with TemporaryDirectory() as out_dir: # tmp_fname = os.path.join(out_dir, 'tmp_img.png') # Tmp image to test scene = window.Scene() # Setup scene test_actor = actor.square(np.array([[0, 0, 0]]), directions=(0, 0, 0), colors=(0, 0, 1)) scene.add(test_actor) # Test basic actor # window.record(scene, out_path=tmp_fname, size=(200, 200), # reset_camera=True) ss = window.snapshot(scene, size=(200, 200)) # npt.assert_equal(os.path.exists(tmp_fname), True) # ss = load_image(tmp_fname) actual = ss[100, 100, :] / 1000 desired = np.array([0, 0, 255]) / 1000 npt.assert_array_almost_equal(actual, desired, decimal=2) actual = ss[40, 40, :] / 1000 npt.assert_array_almost_equal(actual, desired, decimal=2) # Test default parameters material.manifest_pbr(test_actor) ss = window.snapshot(scene, size=(200, 200)) # window.record(scene, out_path=tmp_fname, size=(200, 200), # reset_camera=True) # npt.assert_equal(os.path.exists(tmp_fname), True) # ss = load_image(tmp_fname) actual = ss[100, 100, :] / 1000 desired = np.array([66, 66, 165]) / 1000 npt.assert_array_almost_equal(actual, desired, decimal=2) actual = ss[40, 40, :] / 1000 desired = np.array([40, 40, 157]) / 1000 npt.assert_array_almost_equal(actual, desired, decimal=2) # Test roughness material.manifest_pbr(test_actor, roughness=0) ss = window.snapshot(scene, size=(200, 200)) # window.record(scene, out_path=tmp_fname, size=(200, 200), # reset_camera=True) # npt.assert_equal(os.path.exists(tmp_fname), True) # ss = load_image(tmp_fname) actual = ss[100, 100, :] / 1000 desired = np.array([0, 0, 155]) / 1000 npt.assert_array_almost_equal(actual, desired, decimal=2) actual = ss[40, 40, :] / 1000 desired = np.array([0, 0, 153]) / 1000 npt.assert_array_almost_equal(actual, desired, decimal=2) # Test metallicity material.manifest_pbr(test_actor, metallic=1) ss = window.snapshot(scene, size=(200, 200)) # window.record(scene, out_path=tmp_fname, size=(200, 200), # reset_camera=True) # npt.assert_equal(os.path.exists(tmp_fname), True) # ss = load_image(tmp_fname) actual = ss[100, 100, :] / 1000 desired = np.array([0, 0, 255]) / 1000 npt.assert_array_almost_equal(actual, desired, decimal=2) actual = ss[40, 40, :] / 1000 desired = np.array([0, 0, 175]) / 1000 npt.assert_array_almost_equal(actual, desired, decimal=2)