def timer_callback(_obj, _event): global current_Timepoint, Timepoint, c cnt = next(counter) maxcnt = 1000 Logic_check = (current_Timepoint == Timepoint) current_Timepoint = Timepoint tb.message = "Time Point : " + str(Timepoint)+ " hrs" scene.add(tb) #scene.camera_info() if (Logic_check == False): window.rm_all(scene) scene.add(Sphere_Actor_List[Timepoint]) current_Timepoint = Timepoint showm.scene.add(line_slider) print('Slider Changed') scene.add(tb) x_label = actor.text_3d(text='x axis (micron)',position=(-100,-900,550),font_size=50,justification='left') scene.add(x_label) y_label = actor.text_3d(text='y axis (micron)',position=(-900,0,550),font_size=50,justification='left') scene.add(y_label) z_label = actor.text_3d(text='z axis (micron)',position=(600,-900,0),font_size=50,justification='left') scene.add(z_label) scene.add(c) if cnt == maxcnt: showm.exit() showm.render()
def test_manifest_principled(): # Test non-supported property test_actor = actor.text_3d('Test') npt.assert_warns(UserWarning, material.manifest_principled, test_actor) center = np.array([[0, 0, 0]]) # Test expected parameters expected_principled_params = { 'subsurface': 0, 'subsurface_color': [0, 0, 0], 'metallic': 0, 'specular': 0, 'specular_tint': 0, 'roughness': 0, 'anisotropic': 0, 'anisotropic_direction': [0, 1, .5], 'sheen': 0, 'sheen_tint': 0, 'clearcoat': 0, 'clearcoat_gloss': 0 } test_actor = actor.square(center, directions=(1, 1, 1), colors=(0, 0, 1)) actual_principled_params = material.manifest_principled(test_actor) npt.assert_equal(actual_principled_params, expected_principled_params)
def test_text_3d(): msg = 'I \nlove\n FURY' txt_actor = actor.text_3d(msg) npt.assert_equal(txt_actor.get_message().lower(), msg.lower()) npt.assert_raises(ValueError, txt_actor.justification, 'middle') npt.assert_raises(ValueError, txt_actor.vertical_justification, 'center') scene = window.Scene() scene.add(txt_actor) txt_actor.vertical_justification('middle') txt_actor.justification('right') arr_right = window.snapshot(scene, size=(1920, 1080), offscreen=True) scene.clear() txt_actor.vertical_justification('middle') txt_actor.justification('left') scene.add(txt_actor) arr_left = window.snapshot(scene, size=(1920, 1080), offscreen=True) # X axis of right alignment should have a lower center of mass position # than left assert_greater(center_of_mass(arr_left)[0], center_of_mass(arr_right)[0]) scene.clear() txt_actor.justification('center') txt_actor.vertical_justification('top') scene.add(txt_actor) arr_top = window.snapshot(scene, size=(1920, 1080), offscreen=True) scene.clear() txt_actor.justification('center') txt_actor.vertical_justification('bottom') scene.add(txt_actor) arr_bottom = window.snapshot(scene, size=(1920, 1080), offscreen=True) assert_greater_equal( center_of_mass(arr_bottom)[0], center_of_mass(arr_top)[0]) scene.clear() txt_actor.font_style(bold=True, italic=True, shadow=True) scene.add(txt_actor) arr = window.snapshot(scene, size=(1920, 1080), offscreen=True) assert_greater_equal(arr.mean(), arr_bottom.mean())
def test_apply_affine_to_actor(interactive=False): text_act = actor.text_3d("ALIGN TOP RIGHT", justification='right', vertical_justification='top') text_act2 = TextActor3D() text_act2.SetInput("ALIGN TOP RIGHT") text_act2.GetTextProperty().SetFontFamilyToArial() text_act2.GetTextProperty().SetFontSize(24) text_act2.SetScale((1. / 24. * 12, ) * 3) if interactive: scene = window.Scene() scene.add(text_act, text_act2) window.show(scene) text_bounds = [0, 0, 0, 0] text_act2.GetBoundingBox(text_bounds) initial_bounds = text_act2.GetBounds() affine = np.eye(4) affine[:3, -1] += (-text_bounds[1], 0, 0) affine[:3, -1] += (0, -text_bounds[3], 0) affine[:3, -1] *= text_act2.GetScale() apply_affine_to_actor(text_act2, affine) text_act2.GetBoundingBox(text_bounds) if interactive: scene = window.Scene() scene.add(text_act, text_act2) window.show(scene) updated_bounds = text_act2.GetBounds() original_bounds = text_act.GetBounds() npt.assert_array_almost_equal(updated_bounds, original_bounds, decimal=0) def compare(x, y): return np.isclose(x, y, rtol=1) npt.assert_array_compare(compare, updated_bounds, original_bounds)
def test_grid_ui1(interactive=False): vol1 = np.zeros((100, 100, 100)) vol1[25:75, 25:75, 25:75] = 100 colors = distinguishable_colormap(nb_colors=3) contour_actor1 = actor.contour_from_roi(vol1, np.eye(4), colors[0], 1.) vol2 = np.zeros((100, 100, 100)) vol2[25:75, 25:75, 25:75] = 100 contour_actor2 = actor.contour_from_roi(vol2, np.eye(4), colors[1], 1.) vol3 = np.zeros((100, 100, 100)) vol3[25:75, 25:75, 25:75] = 100 contour_actor3 = actor.contour_from_roi(vol3, np.eye(4), colors[2], 1.) scene = window.Scene() actors = [] texts = [] actors.append(contour_actor1) text_actor1 = actor.text_3d('cube 1', justification='center') texts.append(text_actor1) actors.append(contour_actor2) text_actor2 = actor.text_3d('cube 2', justification='center') texts.append(text_actor2) actors.append(contour_actor3) text_actor3 = actor.text_3d('cube 3', justification='center') texts.append(text_actor3) actors.append(shallow_copy(contour_actor1)) text_actor1 = actor.text_3d('cube 4', justification='center') texts.append(text_actor1) actors.append(shallow_copy(contour_actor2)) text_actor2 = actor.text_3d('cube 5', justification='center') texts.append(text_actor2) actors.append(shallow_copy(contour_actor3)) text_actor3 = actor.text_3d('cube 6', justification='center') texts.append(text_actor3) actors.append(shallow_copy(contour_actor1)) text_actor1 = actor.text_3d('cube 7', justification='center') texts.append(text_actor1) actors.append(shallow_copy(contour_actor2)) text_actor2 = actor.text_3d('cube 8', justification='center') texts.append(text_actor2) actors.append(shallow_copy(contour_actor3)) text_actor3 = actor.text_3d('cube 9', justification='center') texts.append(text_actor3) counter = itertools.count() show_m = window.ShowManager(scene) show_m.initialize() def timer_callback(_obj, _event): nonlocal show_m, counter cnt = next(counter) show_m.scene.zoom(1) show_m.render() if cnt == 10: show_m.exit() # show the grid with the captions grid_ui = ui.GridUI(actors=actors, captions=texts, caption_offset=(0, -50, 0), cell_padding=(60, 60), dim=(3, 3), rotation_axis=(1, 0, 0)) scene.add(grid_ui) show_m.add_timer_callback(True, 200, timer_callback) show_m.start() arr = window.snapshot(scene) report = window.analyze_snapshot(arr) npt.assert_equal(report.objects > 9, True)
def test_grid_ui2(interactive=False): vol1 = np.zeros((100, 100, 100)) vol1[25:75, 25:75, 25:75] = 100 colors = distinguishable_colormap(nb_colors=3) contour_actor1 = actor.contour_from_roi(vol1, np.eye(4), colors[0], 1.) vol2 = np.zeros((100, 100, 100)) vol2[25:75, 25:75, 25:75] = 100 contour_actor2 = actor.contour_from_roi(vol2, np.eye(4), colors[1], 1.) vol3 = np.zeros((100, 100, 100)) vol3[25:75, 25:75, 25:75] = 100 contour_actor3 = actor.contour_from_roi(vol3, np.eye(4), colors[2], 1.) scene = window.Scene() actors = [] texts = [] actors.append(contour_actor1) text_actor1 = actor.text_3d('cube 1', justification='center') texts.append(text_actor1) actors.append(contour_actor2) text_actor2 = actor.text_3d('cube 2', justification='center') texts.append(text_actor2) actors.append(contour_actor3) text_actor3 = actor.text_3d('cube 3', justification='center') texts.append(text_actor3) actors.append(shallow_copy(contour_actor1)) text_actor1 = actor.text_3d('cube 4', justification='center') texts.append(text_actor1) actors.append(shallow_copy(contour_actor2)) text_actor2 = actor.text_3d('cube 5', justification='center') texts.append(text_actor2) actors.append(shallow_copy(contour_actor3)) text_actor3 = actor.text_3d('cube 6', justification='center') texts.append(text_actor3) actors.append(shallow_copy(contour_actor1)) text_actor1 = actor.text_3d('cube 7', justification='center') texts.append(text_actor1) actors.append(shallow_copy(contour_actor2)) text_actor2 = actor.text_3d('cube 8', justification='center') texts.append(text_actor2) actors.append(shallow_copy(contour_actor3)) text_actor3 = actor.text_3d('cube 9', justification='center') texts.append(text_actor3) # this needs to happen automatically when start() ends. # for act in actors: # act.RemoveAllObservers() filename = "test_grid_ui" recording_filename = pjoin(DATA_DIR, filename + ".log.gz") expected_events_counts_filename = pjoin(DATA_DIR, filename + ".json") current_size = (900, 600) scene = window.Scene() show_manager = window.ShowManager(scene, size=current_size, title="FURY GridUI") show_manager.initialize() grid_ui2 = ui.GridUI(actors=actors, captions=texts, caption_offset=(0, -50, 0), cell_padding=(60, 60), dim=(3, 3), rotation_axis=None) scene.add(grid_ui2) event_counter = EventCounter() event_counter.monitor(grid_ui2) if interactive: show_manager.start() recording = False if recording: # Record the following events # 1. Left click on top left box (will rotate the box) show_manager.record_events_to_file(recording_filename) # print(list(event_counter.events_counts.items())) event_counter.save(expected_events_counts_filename) else: show_manager.play_events_from_file(recording_filename) expected = EventCounter.load(expected_events_counts_filename) event_counter.check_counts(expected)
def test_grid_ui(interactive=False): vol1 = np.zeros((100, 100, 100)) vol1[25:75, 25:75, 25:75] = 100 colors = distinguishable_colormap(nb_colors=3) contour_actor1 = actor.contour_from_roi(vol1, np.eye(4), colors[0], 1.) vol2 = np.zeros((100, 100, 100)) vol2[25:75, 25:75, 25:75] = 100 contour_actor2 = actor.contour_from_roi(vol2, np.eye(4), colors[1], 1.) vol3 = np.zeros((100, 100, 100)) vol3[25:75, 25:75, 25:75] = 100 contour_actor3 = actor.contour_from_roi(vol3, np.eye(4), colors[2], 1.) scene = window.Scene() actors = [] texts = [] actors.append(contour_actor1) text_actor1 = actor.text_3d('cube 1', justification='center') texts.append(text_actor1) actors.append(contour_actor2) text_actor2 = actor.text_3d('cube 2', justification='center') texts.append(text_actor2) actors.append(contour_actor3) text_actor3 = actor.text_3d('cube 3', justification='center') texts.append(text_actor3) actors.append(shallow_copy(contour_actor1)) text_actor1 = actor.text_3d('cube 4', justification='center') texts.append(text_actor1) actors.append(shallow_copy(contour_actor2)) text_actor2 = actor.text_3d('cube 5', justification='center') texts.append(text_actor2) actors.append(shallow_copy(contour_actor3)) text_actor3 = actor.text_3d('cube 6', justification='center') texts.append(text_actor3) actors.append(shallow_copy(contour_actor1)) text_actor1 = actor.text_3d('cube 7', justification='center') texts.append(text_actor1) actors.append(shallow_copy(contour_actor2)) text_actor2 = actor.text_3d('cube 8', justification='center') texts.append(text_actor2) actors.append(shallow_copy(contour_actor3)) text_actor3 = actor.text_3d('cube 9', justification='center') texts.append(text_actor3) counter = itertools.count() show_m = window.ShowManager(scene) show_m.initialize() def timer_callback(_obj, _event): cnt = next(counter) show_m.scene.zoom(1) show_m.render() if cnt == 10: show_m.exit() show_m.destroy_timers() # show the grid with the captions grid_ui = ui.GridUI(actors=actors, captions=texts, caption_offset=(0, -50, 0), cell_padding=(60, 60), dim=(3, 3), rotation_axis=(1, 0, 0)) scene.add(grid_ui) show_m.add_timer_callback(True, 200, timer_callback) show_m.start() arr = window.snapshot(scene) report = window.analyze_snapshot(arr) npt.assert_equal(report.objects > 9, True) # this needs to happen automatically when start() ends. for act in actors: act.RemoveAllObservers() filename = "test_grid_ui" recording_filename = pjoin(DATA_DIR, filename + ".log.gz") expected_events_counts_filename = pjoin(DATA_DIR, filename + ".json") current_size = (900, 600) scene = window.Scene() show_manager = window.ShowManager(scene, size=current_size, title="FURY GridUI") show_manager.initialize() grid_ui2 = ui.GridUI(actors=actors, captions=texts, caption_offset=(0, -50, 0), cell_padding=(60, 60), dim=(3, 3), rotation_axis=None) scene.add(grid_ui2) event_counter = EventCounter() event_counter.monitor(grid_ui2) if interactive: show_manager.start() recording = False if recording: # Record the following events # 1. Left click on top left box (will rotate the box) show_manager.record_events_to_file(recording_filename) # print(list(event_counter.events_counts.items())) event_counter.save(expected_events_counts_filename) else: show_manager.play_events_from_file(recording_filename) expected = EventCounter.load(expected_events_counts_filename) event_counter.check_counts(expected)
def test_grid(_interactive=False): vol1 = np.zeros((100, 100, 100)) vol1[25:75, 25:75, 25:75] = 100 contour_actor1 = actor.contour_from_roi(vol1, np.eye(4), (1., 0, 0), 1.) vol2 = np.zeros((100, 100, 100)) vol2[25:75, 25:75, 25:75] = 100 contour_actor2 = actor.contour_from_roi(vol2, np.eye(4), (1., 0.5, 0), 1.) vol3 = np.zeros((100, 100, 100)) vol3[25:75, 25:75, 25:75] = 100 contour_actor3 = actor.contour_from_roi(vol3, np.eye(4), (1., 0.5, 0.5), 1.) scene = window.Scene() actors = [] texts = [] actors.append(contour_actor1) text_actor1 = actor.text_3d('cube 1', justification='center') texts.append(text_actor1) actors.append(contour_actor2) text_actor2 = actor.text_3d('cube 2', justification='center') texts.append(text_actor2) actors.append(contour_actor3) text_actor3 = actor.text_3d('cube 3', justification='center') texts.append(text_actor3) actors.append(shallow_copy(contour_actor1)) text_actor1 = 'cube 4' texts.append(text_actor1) actors.append(shallow_copy(contour_actor2)) text_actor2 = 'cube 5' texts.append(text_actor2) actors.append(shallow_copy(contour_actor3)) text_actor3 = 'cube 6' texts.append(text_actor3) # show the grid without the captions container = grid(actors=actors, captions=None, caption_offset=(0, -40, 0), cell_padding=(10, 10), dim=(2, 3)) scene.add(container) scene.projection('orthogonal') counter = itertools.count() show_m = window.ShowManager(scene) show_m.initialize() def timer_callback(_obj, _event): nonlocal counter cnt = next(counter) # show_m.scene.zoom(1) show_m.render() if cnt == 5: show_m.exit() # show_m.destroy_timers() show_m.add_timer_callback(True, 200, timer_callback) show_m.start() arr = window.snapshot(scene) arr[arr < 100] = 0 report = window.analyze_snapshot(arr) npt.assert_equal(report.objects, 6) scene.rm_all() counter = itertools.count() show_m = window.ShowManager(scene) show_m.initialize() # show the grid with the captions container = grid(actors=actors, captions=texts, caption_offset=(0, -50, 0), cell_padding=(10, 10), dim=(3, 3)) scene.add(container) show_m.add_timer_callback(True, 200, timer_callback) show_m.start() arr = window.snapshot(scene) report = window.analyze_snapshot(arr) npt.assert_equal(report.objects > 6, True)
# Z_domain = np.unique(mesh_structure[2][0]) # dx = X_domain[1]-X_domain[0] # dy = Y_domain[1]-Y_domain[0] # dz = Z_domain[1]-Z_domain[0] # xlims = np.array([X_domain[0]-dx/2, X_domain[-1]+dx/2]) # ylims = np.array([Y_domain[0]-dy/2, Y_domain[-1]+dy/2]) # zlims = np.array([Z_domain[0]-dz/2, Z_domain[-1]+dz/2]) #Drawing Domain Boundaries lines = [np.array([[-2880.,-500.,-2880.],[2880.,-500.,-2880.],[2880.,500.,-2880.],[-2880.,500.,-2880.],[-2880.,-500.,-2880.],[-2880.,-500.,2880.],[-2880.,500.,2880.],[-2880.,500.,-2880.],[-2880.,500.,2880.],[2880.,500.,2880.],[2880.,500.,-2880.],[2880.,500.,-2880.],[2880.,-500.,-2880.],[2880.,-500.,2880.],[2880.,500.,2880.],[2880.,-500.,2880.],[-2880.,-500.,2880.]])] colors = np.array([0.5, 0.5, 0.5]) c = actor.line(lines, colors) scene.add(c) #Adding Dimension Labels x_label = actor.text_3d(text='x axis (micron)',position=(-750.0,-700.0,3000.0),font_size=200,justification='left') scene.add(x_label) y_label = actor.text_3d(text='y axis (micron)',position=(3000,0,3000.0),font_size=200,justification='left') scene.add(y_label) z_label = actor.text_3d(text='z axis (micron)',position=(3000,-700.0,0.0),font_size=200,justification='left') scene.add(z_label) #scene.add(actor.texture_on_sphere(image)) showm.initialize() showm.scene.reset_camera() scene.set_camera(position=(5026.62, 2766.0, 9293.52), focal_point=(221.95, -75.04, -77.73), view_up=(-0.06, 0.963, -0.26))
scene.set_camera(position=(0.24, 0.00, 4.34), focal_point=(0.00, 0.00, 0.00), view_up=(0.00, 1.00, 0.00)) ############################################################################## # Let's create a sphere actor to add to the Earth. We will place this sphere # on the Earth's surface on Bloomington, IN, home of FURY's headquarters! center = [[-0.39, 0.3175, 0.025]] radius = 0.002 sphere_actor = actor.sphere(center, window.colors.blue_medium, radius) ############################################################################## # Also creating a text actor to add below the sphere. text_actor = actor.text_3d("Bloomington, Indiana", (-0.42, 0.31, 0.03), window.colors.white, 0.004) utils.rotate(text_actor, (-90, 0, 1, 0)) ############################################################################## # Let's also import a model of a satellite to visualize circling the moon. fetch_viz_models() satellite_filename = read_viz_models("satellite_obj.obj") satellite = io.load_polydata(satellite_filename) satellite_actor = utils.get_actor_from_polydata(satellite) satellite_actor.SetPosition(-0.75, 0.1, 0.4) satellite_actor.SetScale(0.005, 0.005, 0.005) ############################################################################## # In the ``timer_callback`` function, use if statements to specify when
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)
def test_manifest_standard(): # Test non-supported property test_actor = actor.text_3d('Test') npt.assert_warns(UserWarning, material.manifest_standard, test_actor) center = np.array([[0, 0, 0]]) # Test non-supported interpolation method test_actor = actor.square(center, directions=(1, 1, 1), colors=(0, 0, 1)) npt.assert_warns(UserWarning, material.manifest_standard, test_actor, interpolation='test') scene = window.Scene() # Setup scene test_actor = actor.box(center, directions=(1, 1, 1), colors=(0, 0, 1), scales=1) scene.add(test_actor) # scene.reset_camera() # window.show(scene) ss = window.snapshot(scene, size=(200, 200)) actual = ss[75, 100, :] / 1000 desired = np.array([0, 0, 170]) / 1000 npt.assert_array_almost_equal(actual, desired, decimal=2) actual = ss[125, 125, :] / 1000 npt.assert_array_almost_equal(actual, desired, decimal=2) actual = ss[125, 75, :] / 1000 desired = np.array([0, 0, 85]) / 1000 # TODO: check if camera affects this assert # npt.assert_array_almost_equal(actual, desired, decimal=2) # Test ambient level material.manifest_standard(test_actor, ambient_level=1) ss = window.snapshot(scene, size=(200, 200)) actual = ss[75, 100, :] / 1000 desired = np.array([0, 0, 255]) / 1000 npt.assert_array_almost_equal(actual, desired, decimal=2) actual = ss[125, 125, :] / 1000 npt.assert_array_almost_equal(actual, desired, decimal=2) actual = ss[125, 75, :] / 1000 npt.assert_array_almost_equal(actual, desired, decimal=2) # Test ambient color material.manifest_standard(test_actor, ambient_level=.5, ambient_color=(1, 0, 0)) ss = window.snapshot(scene, size=(200, 200)) actual = ss[75, 100, :] / 1000 npt.assert_array_almost_equal(actual, desired, decimal=2) actual = ss[125, 125, :] / 1000 npt.assert_array_almost_equal(actual, desired, decimal=2) actual = ss[125, 75, :] / 1000 desired = np.array([0, 0, 212]) / 1000 # TODO: check what affects this # npt.assert_array_almost_equal(actual, desired, decimal=2) # Test diffuse level material.manifest_standard(test_actor, diffuse_level=.75) ss = window.snapshot(scene, size=(200, 200)) actual = ss[75, 100, :] / 1000 desired = np.array([0, 0, 127]) / 1000 npt.assert_array_almost_equal(actual, desired, decimal=2) actual = ss[125, 125, :] / 1000 desired = np.array([0, 0, 128]) / 1000 npt.assert_array_almost_equal(actual, desired, decimal=2) actual = ss[125, 75, :] / 1000 desired = np.array([0, 0, 64]) / 1000 # TODO: check what affects this # npt.assert_array_almost_equal(actual, desired, decimal=2) # Test diffuse color material.manifest_standard(test_actor, diffuse_level=.5, diffuse_color=(1, 0, 0)) ss = window.snapshot(scene, size=(200, 200)) actual = ss[75, 100, :] / 1000 desired = np.array([0, 0, 85]) / 1000 npt.assert_array_almost_equal(actual, desired, decimal=2) actual = ss[125, 125, :] / 1000 npt.assert_array_almost_equal(actual, desired, decimal=2) actual = ss[125, 75, :] / 1000 desired = np.array([0, 0, 42]) / 1000 # TODO: check what affects the line below # npt.assert_array_almost_equal(actual, desired, decimal=2) # Test specular level material.manifest_standard(test_actor, specular_level=1) ss = window.snapshot(scene, size=(200, 200)) actual = ss[75, 100, :] / 1000 desired = np.array([170, 170, 255]) / 1000 npt.assert_array_almost_equal(actual, desired, decimal=2) actual = ss[125, 125, :] / 1000 npt.assert_array_almost_equal(actual, desired, decimal=2) actual = ss[125, 75, :] / 1000 desired = np.array([85, 85, 170]) / 1000 # TODO: check what affects the line below # npt.assert_array_almost_equal(actual, desired, decimal=2) # Test specular power material.manifest_standard(test_actor, specular_level=1, specular_power=5) ss = window.snapshot(scene, size=(200, 200)) actual = ss[75, 100, :] / 1000 desired = np.array([34, 34, 204]) / 1000 npt.assert_array_almost_equal(actual, desired, decimal=2) actual = ss[125, 125, :] / 1000 npt.assert_array_almost_equal(actual, desired, decimal=2) actual = ss[125, 75, :] / 1000 desired = np.array([1, 1, 86]) / 1000 # TODO: check what affects the line below # npt.assert_array_almost_equal(actual, desired, decimal=2) # Test specular color material.manifest_standard(test_actor, specular_level=1, specular_color=(1, 0, 0), specular_power=5) ss = window.snapshot(scene, size=(200, 200)) actual = ss[75, 100, :] / 1000 desired = np.array([34, 0, 170]) / 1000 npt.assert_array_almost_equal(actual, desired, decimal=2) actual = ss[125, 125, :] / 1000 npt.assert_array_almost_equal(actual, desired, decimal=2) actual = ss[125, 75, :] / 1000 desired = np.array([1, 0, 85]) / 1000 # TODO: check what affects the line below # npt.assert_array_almost_equal(actual, desired, decimal=2) scene.clear() # Reset scene # Special case: Contour from roi data = np.zeros((50, 50, 50)) data[20:30, 25, 25] = 1. data[25, 20:30, 25] = 1. test_actor = actor.contour_from_roi(data, color=np.array([1, 0, 1])) scene.add(test_actor) ss = window.snapshot(scene, size=(200, 200)) actual = ss[90, 110, :] / 1000 desired = np.array([253, 0, 253]) / 1000 # TODO: check what affects the line below # npt.assert_array_almost_equal(actual, desired, decimal=2) actual = ss[90, 60, :] / 1000 desired = np.array([180, 0, 180]) / 1000 # TODO: check what affects the line below # npt.assert_array_almost_equal(actual, desired, decimal=2) material.manifest_standard(test_actor) ss = window.snapshot(scene, size=(200, 200)) actual = ss[90, 110, :] / 1000 desired = np.array([253, 253, 253]) / 1000 # TODO: check what affects the line below # npt.assert_array_almost_equal(actual, desired, decimal=2) actual = ss[90, 60, :] / 1000 desired = np.array([180, 180, 180]) / 1000 # TODO: check what affects the line below # npt.assert_array_almost_equal(actual, desired, decimal=2) material.manifest_standard(test_actor, diffuse_color=(1, 0, 1)) ss = window.snapshot(scene, size=(200, 200)) actual = ss[90, 110, :] / 1000 desired = np.array([253, 0, 253]) / 1000 # TODO: check what affects the line below # npt.assert_array_almost_equal(actual, desired, decimal=2) actual = ss[90, 60, :] / 1000 desired = np.array([180, 0, 180]) / 1000
showm.initialize() tb = ui.TextBlock2D(bold=True) # use itertools to avoid global variables counter = itertools.count() #Drawing Axis lines = [np.array([[-500.,-800.,-500.],[500.,-800.,-500.],[500.,800.,-500.],[-500.,800.,-500.],[-500.,-800.,-500.],[-500.,-800.,500.],[-500.,800.,500.],[-500.,800.,-500.],[-500.,800.,500.],[500.,800.,500.],[500.,800.,-500.],[500.,800.,-500.],[500.,-800.,-500.],[500.,-800.,500.],[500.,800.,500.],[500.,-800.,500.],[-500.,-800.,500.]])] colors = np.random.rand(1,3) c = actor.line(lines, colors) scene.add(c) x_label = actor.text_3d(text='x axis (micron)',position=(-100,-900,550),font_size=50,justification='left') scene.add(x_label) y_label = actor.text_3d(text='y axis (micron)',position=(-900,0,550),font_size=50,justification='left') scene.add(y_label) z_label = actor.text_3d(text='z axis (micron)',position=(600,-900,0),font_size=50,justification='left') scene.add(z_label) line_slider = ui.LineSlider2D(center=(200, 250), initial_value=1, min_value=0, max_value=37,text_template="{value:.0f}") line_slider.on_change = line_slider_value showm.scene.add(line_slider) current_Timepoint = 1
############################################################################### # Set the centers, radii, and colors of these spheres, and create a new # ``sphere_actor`` for each location to add to the scene. centers = np.array([[*locationone], [*locationtwo], [*locationthree]]) colors = np.random.rand(3, 3) radii = np.array([0.005, 0.005, 0.005]) sphere_actor = actor.sphere(centers, colors, radii) scene.add(sphere_actor) ############################################################################### # Create some text actors to add to the scene indicating each location and its # geographical coordinates. nyc_actor = actor.text_3d( "New York City, New York\n40.7128° N, 74.0060° W", (locationone[0] - 0.04, locationone[1], locationone[2] + 0.07), window.colors.white, 0.01) paris_actor = actor.text_3d( "Paris, France\n48.8566° N, 2.3522° E", (locationthree[0] - 0.04, locationthree[1], locationthree[2] - 0.07), window.colors.white, 0.01) beijing_actor = actor.text_3d( "Beijing, China\n39.9042° N, 116.4074° E", (locationtwo[0] - 0.06, locationtwo[1], locationtwo[2] - 0.07), window.colors.white, 0.01) utils.rotate(paris_actor, (85, 0, 1, 0)) utils.rotate(beijing_actor, (180, 0, 1, 0)) utils.rotate(nyc_actor, (5, 1, 0, 0)) ############################################################################## # Create a ShowManager object, which acts as the interface between the scene,
def test_manifest_standard(): # Test non-supported property test_actor = actor.text_3d('Test') npt.assert_warns(UserWarning, material.manifest_standard, test_actor) center = np.array([[0, 0, 0]]) # Test non-supported interpolation method test_actor = actor.square(center, directions=(1, 1, 1), colors=(0, 0, 1)) npt.assert_warns(UserWarning, material.manifest_standard, test_actor, interpolation='test') # 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.box(center, directions=(1, 1, 1), colors=(0, 0, 1), scales=1) scene.add(test_actor) # Test basic actor 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[75, 100, :] / 1000 desired = np.array([0, 0, 170]) / 1000 npt.assert_array_almost_equal(actual, desired, decimal=2) actual = ss[125, 125, :] / 1000 npt.assert_array_almost_equal(actual, desired, decimal=2) actual = ss[125, 75, :] / 1000 desired = np.array([0, 0, 85]) / 1000 npt.assert_array_almost_equal(actual, desired, decimal=2) # Test ambient level material.manifest_standard(test_actor, ambient_level=1) 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[75, 100, :] / 1000 desired = np.array([0, 0, 255]) / 1000 npt.assert_array_almost_equal(actual, desired, decimal=2) actual = ss[125, 125, :] / 1000 npt.assert_array_almost_equal(actual, desired, decimal=2) actual = ss[125, 75, :] / 1000 npt.assert_array_almost_equal(actual, desired, decimal=2) # Test ambient color material.manifest_standard(test_actor, ambient_level=.5, ambient_color=(1, 0, 0)) 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[75, 100, :] / 1000 npt.assert_array_almost_equal(actual, desired, decimal=2) actual = ss[125, 125, :] / 1000 npt.assert_array_almost_equal(actual, desired, decimal=2) actual = ss[125, 75, :] / 1000 desired = np.array([0, 0, 212]) / 1000 npt.assert_array_almost_equal(actual, desired, decimal=2) # Test diffuse level material.manifest_standard(test_actor, diffuse_level=.75) 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[75, 100, :] / 1000 desired = np.array([0, 0, 127]) / 1000 npt.assert_array_almost_equal(actual, desired, decimal=2) actual = ss[125, 125, :] / 1000 desired = np.array([0, 0, 128]) / 1000 npt.assert_array_almost_equal(actual, desired, decimal=2) actual = ss[125, 75, :] / 1000 desired = np.array([0, 0, 64]) / 1000 npt.assert_array_almost_equal(actual, desired, decimal=2) # Test diffuse color material.manifest_standard(test_actor, diffuse_level=.5, diffuse_color=(1, 0, 0)) 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[75, 100, :] / 1000 desired = np.array([0, 0, 85]) / 1000 npt.assert_array_almost_equal(actual, desired, decimal=2) actual = ss[125, 125, :] / 1000 npt.assert_array_almost_equal(actual, desired, decimal=2) actual = ss[125, 75, :] / 1000 desired = np.array([0, 0, 42]) / 1000 npt.assert_array_almost_equal(actual, desired, decimal=2) # Test specular level material.manifest_standard(test_actor, specular_level=1) 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[75, 100, :] / 1000 desired = np.array([170, 170, 255]) / 1000 npt.assert_array_almost_equal(actual, desired, decimal=2) actual = ss[125, 125, :] / 1000 npt.assert_array_almost_equal(actual, desired, decimal=2) actual = ss[125, 75, :] / 1000 desired = np.array([85, 85, 170]) / 1000 npt.assert_array_almost_equal(actual, desired, decimal=2) # Test specular power material.manifest_standard(test_actor, specular_level=1, specular_power=5) 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[75, 100, :] / 1000 desired = np.array([34, 34, 204]) / 1000 npt.assert_array_almost_equal(actual, desired, decimal=2) actual = ss[125, 125, :] / 1000 npt.assert_array_almost_equal(actual, desired, decimal=2) actual = ss[125, 75, :] / 1000 desired = np.array([1, 1, 86]) / 1000 npt.assert_array_almost_equal(actual, desired, decimal=2) # Test specular color material.manifest_standard(test_actor, specular_level=1, specular_color=(1, 0, 0), specular_power=5) 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[75, 100, :] / 1000 desired = np.array([34, 0, 170]) / 1000 npt.assert_array_almost_equal(actual, desired, decimal=2) actual = ss[125, 125, :] / 1000 npt.assert_array_almost_equal(actual, desired, decimal=2) actual = ss[125, 75, :] / 1000 desired = np.array([1, 0, 85]) / 1000 npt.assert_array_almost_equal(actual, desired, decimal=2) scene.clear() # Reset scene # Special case: Contour from roi data = np.zeros((50, 50, 50)) data[20:30, 25, 25] = 1. data[25, 20:30, 25] = 1. test_actor = actor.contour_from_roi(data, color=np.array([1, 0, 1])) scene.add(test_actor) 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[90, 110, :] / 1000 desired = np.array([253, 0, 253]) / 1000 npt.assert_array_almost_equal(actual, desired, decimal=2) actual = ss[90, 60, :] / 1000 desired = np.array([180, 0, 180]) / 1000 npt.assert_array_almost_equal(actual, desired, decimal=2) material.manifest_standard(test_actor) 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[90, 110, :] / 1000 desired = np.array([253, 253, 253]) / 1000 npt.assert_array_almost_equal(actual, desired, decimal=2) actual = ss[90, 60, :] / 1000 desired = np.array([180, 180, 180]) / 1000 npt.assert_array_almost_equal(actual, desired, decimal=2) material.manifest_standard(test_actor, diffuse_color=(1, 0, 1)) 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[90, 110, :] / 1000 desired = np.array([253, 0, 253]) / 1000 npt.assert_array_almost_equal(actual, desired, decimal=2) actual = ss[90, 60, :] / 1000 desired = np.array([180, 0, 180]) / 1000 npt.assert_array_almost_equal(actual, desired, decimal=2)