예제 #1
0
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()
예제 #2
0
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
s1 = scene.root.silhouette().lw(3).c('k')
s2 = skull.silhouette().lw(3).c('k')
scene.add_vtkactor(s1, s2)

scene.render()
예제 #3
0
brainrender.SHADER_STYLE = 'cartoon'

from brainrender.scene import Scene
import numpy as np
from vtkplotter import Plane

scene = Scene(use_default_key_bindings=True)

# Add some actors
root = scene.actors['root']
th = scene.add_brain_regions(['STR', 'TH'], alpha=.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, sx, 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.actors['root'])

sil = root.silhouette().lw(1).c('k')
scene.add_vtkactor(sil)

scene.render(camera='top')
예제 #4
0
hy.wireframe()

# Get center of mass of the two regions
p1 = scene.atlas.get_region_CenterOfMass("MOs")
p2 = scene.atlas.get_region_CenterOfMass("HY")
scene.add_sphere_at_point(p1, radius=200)

# 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
예제 #5
0
from brainrender.colors import makePalette

from morphapi.morphology.morphology import Neuron
from morphapi.api.mouselight import MouseLightAPI, mouselight_structures_identifiers

# ---------------------------- Downloading neurons --------------------------- #
mlapi = MouseLightAPI()

# Fetch metadata for neurons with some in the secondary motor cortex
neurons_metadata = mlapi.fetch_neurons_metadata(filterby='soma',
                                                filter_regions=['MOs'])

# Then we can download the files and save them as a .json file
neurons = mlapi.download_neurons(
    neurons_metadata[:50])  # 50 neurons, might take a while the first time

# ----------------------------- Rendering neurons ---------------------------- #

# Create a custom colormap between 3 colors
colors = makePalette(len(neurons), 'salmon', 'lightgreen')

# Create scene
scene = Scene(add_root=True, display_inset=False)

# Add each neuron with it's color
scene.add_neurons(neurons, alpha=.8, neurite_radius=8, color=colors)

# Cut all actors to expose neurons
scene.cut_actors_with_plane('sagittal')
scene.render()
예제 #6
0
from brainrender.scene import Scene
from brainrender.colors import makePalette

from morphapi.api.mouselight import MouseLightAPI

# ---------------------------- Downloading neurons --------------------------- #
mlapi = MouseLightAPI()

# Fetch metadata for neurons with some in the secondary motor cortex
neurons_metadata = mlapi.fetch_neurons_metadata(filterby="soma",
                                                filter_regions=["MOs"])

# Then we can download the files and save them as a .json file
neurons = mlapi.download_neurons(
    neurons_metadata[:50])  # 50 neurons, might take a while the first time

# ----------------------------- Rendering neurons ---------------------------- #

# Create a custom colormap between 3 colors
colors = makePalette(len(neurons), "salmon", "lightgreen")

# Create scene
scene = Scene(add_root=True, display_inset=False, title="neurons")

# Add each neuron with it's color
scene.add_neurons(neurons, alpha=0.8, neurite_radius=8, color=colors)

# Cut all actors to expose neurons
scene.cut_actors_with_plane("sagittal")
scene.render()
예제 #7
0
"""
    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()

# Add some actors
root = scene.actors['root']
th = scene.add_brain_regions(['STR', 'TH'], alpha=.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
sil = root.silhouette().lw(1).c('k')
sil2 = [act.silhouette().lw(3).c('k') for act in th]
scene.add_vtkactor(sil, *sil2)

scene.render(camera='top')