scene

Contents

Scene

1
The code below aims to create a scene to which actors can be added or removed, changed etc..
2
It also facilitates the interaction with the scene (e.g. moving the camera) and the creation of
3
snapshots or animated videos.
4
The class Scene is based on the Plotter class of vedo: https://github.com/marcomusy/vedo/blob/master/vedo/plotter.py
5
and other classes within the same package.
Copied!

__init__ [#48]

Check the source code online
1
def __init__(self, brain_regions=None, regions_aba_color=False,
2
neurons=None, tracts=None, add_root=None, verbose=True,
3
ignore_jupyter=False, display_inset=None, base_dir=None, camera=None,
4
screenshot_kwargs={}, use_default_key_bindings=False, title=None,
5
atlas=None, atlas_kwargs=dict(), **kwargs):
Copied!
  docstring:
1
Creates and manages a Plotter instance
2
3
:param brain_regions: list of brain regions acronyms to be added to
4
the rendered scene (default value None)
5
6
:param regions_aba_color: if True, use the Allen Brain Atlas regions
7
colors (default value None)
8
9
:param neurons: path to JSON or SWC file with data of neurons to be
10
rendered [or list of files] (default value None)
11
12
:param tracts: list of JSON files with tractography data to be
13
rendered (default value None)
14
15
:param add_root: if False a rendered outline of the whole brain is
16
added to the scene (default value None)
17
18
:param verbose: if False less feedback is printed to screen (default
19
value True)
20
21
:param display_insert: if False the inset displaying the brain's
22
outline is not rendered (but the root is added to the scene) (default
23
value None)
24
25
:param base_dir: path to directory to use for saving data (default
26
value None)
27
28
:param camera: name of the camera parameters setting to use (controls
29
the orientation of the rendered scene)
30
31
:param kwargs: can be used to pass path to individual data folders.
32
See brainrender/Utils/paths_manager.py
33
34
:param screenshot_kwargs: pass a dictionary with keys:
35
36
- 'folder' -> str, path to folder where to save screenshots
37
38
- 'name' -> str, filename to prepend to screenshots files
39
40
- 'format' -> str, 'png', 'svg' or 'jpg'
41
42
- scale -> float, values > 1 yield higher resultion screenshots
43
44
:param use_default_key_bindings: if True the defualt keybindings from
45
vedo are used, otherwise
46
47
a custom function that can be used to take screenshots with the
48
parameter above.
49
50
:param title: str, if a string is passed a text is added to the top of
51
the rendering window as a title
52
53
:param atlas: str, class. Default None. If a string is passed it
54
whould be the name of a valide
55
56
brainglobe_api atlas. Alternative a class object can be passed, this
57
should support the functionality
58
59
expected of an atlas class.
60
61
if no atlas is passed the allen brain atlas for the adult mouse brain
62
is used. If a string with the atlas
63
64
name is passed it will try to load the corresponding brainglobe atlas.
65
66
:param atlas_kwargs: dictionary used to pass extra arguments to atlas
67
class
68
69
:param ignore_jupyter: bool, if False brainrender auto-detects if the
70
user is using jupyter and adjusts to it
Copied!

_check_point_in_region [#237]

Check the source code online
1
def _check_point_in_region(self, point, region_actor):
Copied!
  docstring:
1
Checks if a point of defined coordinates is within the mesh of a given
2
actorr
3
4
:param point: 3-tuple or list of xyz coordinates
5
6
:param region_actor: vedo actor
Copied!

_get_inset [#249]

Check the source code online
1
def _get_inset(self, **kwargs):
Copied!
  docstring:
1
Handles the rendering of the inset showing the outline of the whole
2
brain (root) in a corner of the scene.
3
4
:param **kwargs:
Copied!

get_n_random_points_in_region [#277]

Check the source code online
1
def get_n_random_points_in_region(self, region, N, hemisphere=None):
Copied!
  docstring:
1
Gets N random points inside (or on the surface) of the mesh defining a
2
brain region.
3
4
:param region: str, acronym of the brain region.
5
6
:param N: int, number of points to return.
Copied!

edit_actors [#312]

Check the source code online
1
def edit_actors(self, actors, **kwargs):
Copied!
  docstring:
1
edits a list of actors (e.g. render as wireframe or solid)
2
3
:param actors: list of actors
4
5
:param **kwargs:
Copied!

mirror_actor_hemisphere [#325]

Check the source code online
1
def mirror_actor_hemisphere(self, actors):
Copied!
  docstring:
1
Mirrors actors from one hemisphere to the next
Copied!

cut_actors_with_plane [#338]

Check the source code online
1
def cut_actors_with_plane(self, plane, actors=None, showplane=False,
2
returncut=False, close_actors=False, **kwargs):
Copied!
  docstring:
no docstring

get_cells_in_region [#405]

Check the source code online
1
def get_cells_in_region(self, cells, region):
Copied!
  docstring:
1
Selects the cells that are in a list of user provided regions from a
2
dataframe of cell locations
3
4
:param cells: pd.DataFrame of cells x,y,z coordinates
Copied!

add_root [#432]

Check the source code online
1
def add_root(self, render=True, **kwargs):
Copied!
  docstring:
1
adds the root the scene (i.e. the whole brain outline)
2
3
:param render: (Default value = True)
4
5
:param **kwargs:
Copied!

add_brain_regions [#456]

Check the source code online
1
def add_brain_regions(self, *args, **kwargs):
Copied!
  docstring:
1
Adds brain regions meshes to scene.
2
3
Check the atlas' method to know how it works
Copied!

add_neurons [#481]

Check the source code online
1
def add_neurons(self, *args, **kwargs):
Copied!
  docstring:
1
Adds rendered morphological data of neurons reconstructions.
2
3
Check the atlas' method to know how it works
Copied!

add_neurons_synapses [#499]

Check the source code online
1
def add_neurons_synapses(self, *args, **kwargs):
Copied!
  docstring:
1
Adds the location of pre or post synapses for a neuron (or list of
2
neurons).
3
4
Check the atlas' method to know how it works.
Copied!

add_tractography [#514]

Check the source code online
1
def add_tractography(self, *args, **kwargs):
Copied!
  docstring:
1
Renders tractography data and adds it to the scene.
2
3
Check the function definition in ABA for more details
Copied!

add_streamlines [#524]

Check the source code online
1
def add_streamlines(self, *args, **kwargs):
Copied!
  docstring:
1
Render streamline data.
2
3
Check the function definition in ABA for more details
Copied!

add_actor [#534]

Check the source code online
1
def add_actor(self, *actors, store=None):
Copied!
  docstring:
1
Add a vtk actor to the scene
2
3
:param actor:
4
5
:param store: one of the items in self.actors to use to store the
6
actor
7
8
being created. It needs to be a list
Copied!

add_mesh_silhouette [#558]

Check the source code online
1
def add_mesh_silhouette(self, *actors, lw=1, color='k', **kwargs):
Copied!
  docstring:
1
Given a list of actors it adds a colored silhouette
2
3
to them.
Copied!

add_from_file [#566]

Check the source code online
1
def add_from_file(self, *filepaths, **kwargs):
Copied!
  docstring:
1
Add data to the scene by loading them from a file. Should handle .obj,
2
.vtk and .nii files.
3
4
:param filepaths: path to the file. Can pass as many arguments as
5
needed
6
7
:param **kwargs:
Copied!

add_sphere_at_point [#582]

Check the source code online
1
def add_sphere_at_point(self, pos=[0, 0, 0], radius=100,
2
color='black', alpha=1, **kwargs):
Copied!
  docstring:
1
Adds a shere at a location specified by the user
2
3
:param pos: list of x,y,z coordinates (Default value = [0, 0, 0])
4
5
:param radius: int, radius of the sphere (Default value = 100)
6
7
:param color: color of the sphere (Default value = "black")
8
9
:param alpha: transparency of the sphere (Default value = 1)
10
11
:param **kwargs:
Copied!

add_cells_from_file [#600]

Check the source code online
1
def add_cells_from_file(self, filepath, hdf_key='hdf', color='red',
2
radius=25, res=3, alpha=1):
Copied!
  docstring:
1
Load location of cells from a file (csv and HDF) and render as spheres
2
aligned to the root mesh.
3
4
:param filepath: str path to file
5
6
:param hdf_key: str (Default value = None)
7
8
:param color: str, color of spheres used to render the cells (Default
9
value = "red")
10
11
:param radius: int, radius of spheres used to render the cells
12
(Default value = 25)
13
14
:param res: int, resolution of spheres used to render the cells
15
(Default value = 3)
16
17
:param alpha: float, transparency of spheres used to render the cells
18
(Default value = 1)
Copied!

add_cells [#664]

Check the source code online
1
def add_cells(self, coords, color='red', color_by_region=False,
2
color_by_metadata=None, radius=25, res=3, alpha=1, col_names=None,
3
regions=None, verbose=True):
Copied!
  docstring:
1
Renders cells given their coordinates as a collection of spheres.
2
3
:param coords: pandas dataframe with x,y,z coordinates
4
5
:param color: str, color of spheres used to render the cells (Default
6
value = "red").
7
8
Alternatively a list of colors specifying the color of each cell.
9
10
:param radius: int, radius of spheres used to render the cells
11
(Default value = 25)
12
13
:param res: int, resolution of spheres used to render the cells
14
(Default value = 3)
15
16
:param alpha: float, transparency of spheres used to render the cells
17
(Default value = 1)
18
19
:param color_by_region: bool. If true the cells are colored according
20
to the color of the brain region they are in
21
22
:param color_by_metadata: str, if the name of a column of the coords
23
dataframe is passed, cells are colored according
24
25
to their value for that column. If color_by_metadata is passed and a
26
dictionary is passed
27
28
to 'color' at the same time, the dictionary will be used to specify
29
the colors used. Therefore
30
31
`color` should map values in the metadata column to colors
32
33
:param regions: if a list of brain regions acronym is passed, only
34
cells in these regions will be added to the scene
35
36
:param col_names: list of strings with names of pandas dataframe
37
columns. If passed it should be a list of 3 columns
38
39
which have the x, y, z coordinates. If not passed, it is assumed that
40
the columns are ['x', 'y', 'z']
Copied!

add_optic_cannula [#768]

Check the source code online
1
def add_optic_cannula(self, target_region=None, pos=None, x_offset=0,
2
y_offset=0, z_offset=(- 500), use_line=False, **kwargs):
Copied!
  docstring:
1
Adds a cylindrical vtk actor to scene to render optic cannulas. By
2
default
3
4
this is a semi-transparent blue cylinder centered on the center of
5
mass of
6
7
a specified target region and oriented vertically.
8
9
:param target_region: str, acronym of target region to extract
10
coordinates
11
12
of implanted fiber. By defualt the fiber will be centered on the
13
center
14
15
of mass of the target region but the offset arguments can be used to
16
17
fine tune the position. Alternative pass a 'pos' argument with XYZ
18
coords.
19
20
:param pos: list or tuple or np.array with X,Y,Z coordinates. Must
21
have length = 3.
22
23
:param x_offset, y_offset, z_offset: int, used to fine tune the
24
coordinates of
25
26
the implanted cannula.
27
28
:param **kwargs: used to specify which hemisphere the cannula is and
29
parameters
30
31
of the rendered cylinder: color, alpha, rotation axis...
Copied!

add_text [#838]

Check the source code online
1
def add_text(self, text, **kwargs):
Copied!
  docstring:
1
Adds a 2D text to the scene. Default params are to crate a large black
2
3
text at the top of the rendering window.
4
5
:param text: str with text to write
6
7
:param kwargs: keyword arguments accepted by vedo.shapes.Text2D
Copied!

add_actor_label [#857]

Check the source code online
1
def add_actor_label(self, actors, labels, **kwargs):
Copied!
  docstring:
1
Adds a 2D text ancored to a point on the actor's mesh
2
3
to label what the actor is
4
5
:param kwargs: key word arguments can be passed to determine
6
7
text appearance and location:
8
9
- size: int, text size. Default 300
10
11
- color: str, text color. A list of colors can be passed
12
13
if None the actor's color is used. Default None.
14
15
- xoffset, yoffset, zoffset: integers that shift the label position
16
17
- radius: radius of sphere used to denote label anchor. Set to 0 or
18
None to hide.
Copied!

add_line_at_point [#935]

Check the source code online
1
def add_line_at_point(self, point, replace_coord, bounds, **kwargs):
Copied!
  docstring:
1
Adds a line oriented on a given axis at a point
2
3
:param point:list or 1d np array with coordinates of point where
4
crosshair is centered
5
6
:param replace_coord: index of the coordinate to replace (i.e. along
7
which axis is the line oriented)
8
9
:param bounds: list of two floats with lower and upper bound for line,
10
determins the extent of the line
11
12
:param kwargs: dictionary with arguments to specify how lines should
13
look like
Copied!

add_rostrocaudal_line_at_point [#958]

Check the source code online
1
def add_rostrocaudal_line_at_point(self, point, **kwargs):
Copied!
  docstring:
1
Add a line at a point oriented along the trostrocaudal axis
2
3
:param point:list or 1d np array with coordinates of point where
4
crosshair is centered
5
6
:param line_kwargs: dictionary with arguments to specify how lines
7
should look like
Copied!

add_dorsoventral_line_at_point [#968]

Check the source code online
1
def add_dorsoventral_line_at_point(self, point, **kwargs):
Copied!
  docstring:
1
Add a line at a point oriented along the mdorsoventralediolateral axis
2
3
:param point:list or 1d np array with coordinates of point where
4
crosshair is centered
5
6
:param line_kwargs: dictionary with arguments to specify how lines
7
should look like
Copied!

add_mediolateral_line_at_point [#978]

Check the source code online
1
def add_mediolateral_line_at_point(self, point, **kwargs):
Copied!
  docstring:
1
Add a line at a point oriented along the mediolateral axis
2
3
:param point:list or 1d np array with coordinates of point where
4
crosshair is centered
5
6
:param line_kwargs: dictionary with arguments to specify how lines
7
should look like
Copied!

add_crosshair_at_point [#988]

Check the source code online
1
def add_crosshair_at_point(self, point, ml=True, dv=True, ap=True,
2
show_point=True, line_kwargs={}, point_kwargs={}):
Copied!
  docstring:
1
Add a crosshair (set of orthogonal lines meeting at a point)
2
3
centered on a given point.
4
5
:param point: list or 1d np array with coordinates of point where
6
crosshair is centered
7
8
:param ml: bool, if True a line oriented on the mediolateral axis is
9
added
10
11
:param dv: bool, if True a line oriented on the dorsoventral axis is
12
added
13
14
:param ap: bool, if True a line oriented on the anteriorposterior or
15
rostsrocaudal axis is added
16
17
:param show_point: bool, if True a sphere at the loation of the point
18
is shown
19
20
:param line_kwargs: dictionary with arguments to specify how lines
21
should look like
22
23
:param point_kwargs: dictionary with arguments to specify how the
24
point should look
Copied!

add_plane [#1031]

Check the source code online
1
def add_plane(self, plane, **kwargs):
Copied!
  docstring:
1
Adds one or more planes to the scene.
2
3
For more details on how to build custom planes, check:
4
5
brainrender/atlases/base.py -> Base.get_plane_at_point
6
7
method.
8
9
:param plane: either a string with the name of one of
10
11
the predifined planes ['sagittal', 'coronal', 'horizontal']
12
13
or an instance of the Plane class from vedo.shapes
Copied!

add_probe_from_sharptrack [#1070]

Check the source code online
1
def add_probe_from_sharptrack(self, probe_points_file,
2
points_kwargs={}, **kwargs):
Copied!
  docstring:
1
Visualises the position of an implanted probe in the brain.
2
3
Uses the location of points along the probe extracted with SharpTrack
4
5
[https://github.com/cortex-lab/allenCCF].
6
7
It renders the position of points along the probe and a line fit
8
through them.
9
10
Code contributed by @tbslv on github.
11
12
:param probe_points_file: str, path to a .mat file with probe points
13
coordinates
14
15
:param points_kwargs: dict, used to specify how probe points should
16
look like (e.g color, alpha...)
17
18
:param kwargs: keyword arguments used to specify how the probe should
19
look like (e.g. color, alpha...)
Copied!

apply_render_style [#1138]

Check the source code online
1
def apply_render_style(self):
Copied!
  docstring:
no docstring

get_actors [#1157]

Check the source code online
1
def get_actors(self):
Copied!
  docstring:
no docstring

render [#1179]

Check the source code online
1
def render(self, interactive=True, video=False, camera=None,
2
zoom=None, **kwargs):
Copied!
  docstring:
1
Takes care of rendering the scene
Copied!

close [#1261]

Check the source code online
1
def close(self):
Copied!
  docstring:
no docstring

export_for_web [#1264]

Check the source code online
1
def export_for_web(self, filepath='brexport.html'):
Copied!
  docstring:
1
This function is used to export a brainrender scene
2
3
for hosting it online. It saves an html file that can
4
5
be opened in a web browser to show an interactive brainrender scene
Copied!

keypress [#1310]

Check the source code online
1
def keypress(self, key):
Copied!
  docstring:
no docstring

take_screenshot [#1343]

Check the source code online
1
def take_screenshot(self):
Copied!
  docstring:
no docstring

DualScene

1
Copied!

__init__ [#1356]

Check the source code online
1
def __init__(self, *args, **kwargs):
Copied!
  docstring:
no docstring

render [#1359]

Check the source code online
1
def render(self, _interactive=True):
Copied!
  docstring:
1
Copied!

close [#1396]

Check the source code online
1
def close(self):
Copied!
  docstring:
no docstring

MultiScene

1
Copied!

__init__ [#1403]

Check the source code online
1
def __init__(self, N, scenes=None, *args, **kwargs):
Copied!
  docstring:
no docstring

render [#1416]

Check the source code online
1
def render(self, _interactive=True, **kwargs):
Copied!
  docstring:
1
:param _interactive: (Default value = True)
2
3
:param **kwargs:
Copied!

close [#1467]

Check the source code online
1
def close(self):
Copied!
  docstring:
no docstring
Last modified 1yr ago