def main(regions, atlas=None, cartoon=False, debug=False, file=None): # Set look if cartoon: brainrender.SHADER_STYLE = "cartoon" # Create scene scene = Scene(atlas=atlas) # Add brain regions if regions is not None and len(regions) > 0: acts = scene.add_brain_regions(list(regions)) # Add silhouettes if cartoon: if isinstance(acts, list): scene.add_silhouette(*acts) else: scene.add_silhouette(acts) # Add data from file if file is not None: if file.endswith(".h5"): scene.add_cells_from_file(file) else: try: scene.add_from_file(file) except Exception as e: raise ValueError( f"Failed to load data from file onto scene: {file}\n{e}" ) # If debug set interactive = Off and close scene if not debug: interactive = True else: interactive = False # Render and close scene.render(interactive=interactive) if debug: scene.close()
""" This example shows how to create a scene that has a cartoony look (good for schematics and illustrations) """ import brainrender brainrender.SHADER_STYLE = "cartoon" # gives actors a flat shading from brainrender.scene import Scene scene = Scene(title="cartoon look") th = scene.add_brain_regions("TH", alpha=0.5) # Create a black line around each actor scene.add_silhouette(scene.root) scene.add_silhouette(th, lw=3) scene.render()
from brainrender.scene import Scene scene = Scene() # Load skull from file skull = scene.add_from_file("Examples/example_files/skull.stl") skull.c("ivory").alpha(1) # Align skull and brain (scene.root) skull_com = skull.centerOfMass() root_com = scene.root.centerOfMass() skull.origin(skull.centerOfMass()) skull.rotateY(90).rotateX(180) skull.x(root_com[0] - skull_com[0]) skull.y(root_com[1] - skull_com[1]) skull.z(root_com[2] - skull_com[2]) skull.x(3500) skull.rotateZ(-25) skull.y(7800) skull.scale([1300, 1500, 1200]) # Cut skull actor to show brain inside scene.cut_actors_with_plane("sagittal", actors=skull) # Improve looks scene.add_silhouette(scene.root, lw=3) scene.add_silhouette(skull, lw=3) scene.render()
) # Text to add s = "BRAINRENDER" # Specify a color for each letter colors = makePalette(len(s), "salmon", "powderblue") x = 0 # use to specify the position of each letter # Add letters one at the time to color them individually for n, letter in enumerate("BRAINRENDER"): if "I" == letter or "N" == letter and n < 5: # make the spacing right x += 0.6 else: x += 1 # Add letter and silhouette to the scene act = Text( letter, depth=0.5, c=colors[n], pos=(x, 0, 0), justify="centered", alpha=1, ) scene.add_silhouette(act, lw=3) scene.render()
# Add a ruler form the brain surface scene.add_ruler_from_surface(p2, unit_scale=0.001) # Add a ruler between the two regions scene.add_actor(ruler(p1, p2, unit_scale=0.001, units="mm")) # Cut with plane stn = scene.add_brain_regions("STR", hemisphere="right").alpha(0.4) scene.cut_actors_with_plane("sagittal", actors=hy) # Fake render scene.render(interactive=False) # Add more regions and silhouettes ca1 = scene.add_brain_regions("CA1", alpha=0.4) scene.add_silhouette(ca1) visp = scene.add_brain_regions("VISp", add_labels=False).lw(1).alpha(0.3) scene.add_sphere_at_point(scene.atlas.get_region_CenterOfMass("VISp"), radius=200) p3 = scene.atlas.get_region_CenterOfMass("VISp") scene.add_sphere_at_point(p3, radius=200) # add labels scene.add_actor_label(ca1, "CA1") # Add some random stuf scene.add_optic_cannula("VISp") scene.add_plane("sagittal") # final render
brainrender.SHADER_STYLE = "cartoon" from brainrender.scene import Scene scene = Scene(use_default_key_bindings=True, title="cut with plane") # Add some actors th = scene.add_brain_regions(["STR", "TH"], alpha=0.5) # Specify position, size and orientation of the plane pos = scene.atlas._root_midpoint sx, sy = 15000, 15000 norm = [0, 1, 1] plane = scene.atlas.get_plane_at_point(pos, norm=norm, sx=sx, sy=sy, color="lightblue") # Cut scene.cut_actors_with_plane( plane, close_actors= False, # set close_actors to True close the holes left by cutting showplane=True, actors=scene.root, ) scene.add_silhouette(scene.root) scene.render(camera="top")
""" This example shows how to cut actors in the scene using a plane oriented along the sagittal axis """ import brainrender brainrender.SHADER_STYLE = "cartoon" from brainrender.scene import Scene scene = Scene(title="cut with plane") # Add some actors th = scene.add_brain_regions(["STR", "TH"], alpha=0.5) # Cut with plane scene.cut_actors_with_plane( "sagittal", showplane=False ) # Set showplane to True if you want to see the plane location # Add a silhouette around each actor to emphasize the cut location scene.add_silhouette(*th, lw=3) scene.render(camera="top")