Scene#

class brainrender.scene.Scene(root=True, atlas_name=None, check_latest=True, inset=True, title=None, screenshots_folder=None, plotter=None, title_color='k')[source]#

Bases: JupyterMixIn, Render

Main scene in brainrender.

Coordinates the actors and the overall appearance.

Methods

add(*items[, names, classes, transform])

General method to add Actors to the scene.

add_brain_region(*regions[, alpha, color, ...])

Dedicated method to add brain regions to render.

add_label(**kwargs)

add_silhouette(**kwargs)

close()

Close the vedo Plotter window.

export(savepath, **kwargs)

Export the scene to a .html file for online rendering.

get_actors([name, br_class])

Return the scene's actors that match some search criteria.

keypress(key)

Handle key presses during interactive rendering.

remove(*actors)

Remove actors from the scene.

render([interactive, camera, zoom, resetcam])

Render the scene.

screenshot([name, scale])

Take a screenshot of the current view and save it to file.

slice(plane[, actors, close_actors, invert])

Slice actors with a plane.

Attributes

axes_indices

axes_lookup

axes_names

clean_actors

Return only actors that are not Text objects and similar.

clean_renderables

Return meshes only for 'clean actors' (i.e. not text).

content

Print an overview of the Actors in the scene.

is_rendered

plotter

renderables

Return the meshes for all actors.

add(*items, names=None, classes=None, transform=True, **kwargs)[source]#

General method to add Actors to the scene.

Whatever the input, it’s turned into an instance of Actor before being added to the scene.

Parameters:
  • *items (Mesh | Assembly | Text2D | Actor | str | Path) – vedo.Mesh, Actor, or (str, Path). If str/path it should be a path to a .obj or .stl file.

  • names (str | list[str | None] | None) – Names to be assigned to the Actors.

  • classes (str | list[str | None] | None) – br_classes to be assigned to the Actors.

  • transform (bool) – If True, apply the axes-orientation transform to new actors.

  • **kwargs (Any) – Parameters to be passed to the individual loading functions (e.g. to load from file and specify the color).

Returns:

The actor(s) added to the scene.

Return type:

Actor or list of Actor

add_brain_region(*regions, alpha=1, color=None, silhouette=None, hemisphere='both', force=False)[source]#

Dedicated method to add brain regions to render.

Parameters:
  • *regions (str | int) – Region names or IDs.

  • alpha (float) – How opaque the regions are rendered.

  • color (str | None) – Uses the atlas default colour if None.

  • silhouette (bool | None) – If true, region Actors will have a silhouette.

  • hemisphere (str) – "both" returns the complete mesh; "left"/"right" return only the corresponding half of the mesh.

  • force (bool) – If true, force adding of region even if already rendered.

Returns:

The actors added to the scene. None if no actors added.

Return type:

Actor or list of Actor or None

property clean_actors: list[Actor]#

Return only actors that are not Text objects and similar.

property clean_renderables: list[Mesh]#

Return meshes only for ‘clean actors’ (i.e. not text).

_mesh is returned to account for internal rotations.

close()#

Close the vedo Plotter window.

Return type:

None

property content: None#

Print an overview of the Actors in the scene.

export(savepath, **kwargs)#

Export the scene to a .html file for online rendering.

Parameters:
  • savepath (str | Path) – Path to the output .html file.

  • **kwargs (Any) – Additional arguments forwarded to render.

Returns:

Absolute path of the saved file.

Return type:

str

Raises:

ValueError – If savepath does not have a .html suffix.

get_actors(name=None, br_class=None)[source]#

Return the scene’s actors that match some search criteria.

Parameters:
  • name (str | int | list[str | int] | None) – Actor name(s) to match.

  • br_class (str | list[str] | None) – Actor br_class(es) to match.

Returns:

The actors in the scene that match the specified search criteria.

Return type:

list of Actor

keypress(key)#

Handle key presses during interactive rendering.

  • s: take a screenshot

  • q / Esc: close the window

  • c: print current camera parameters

Parameters:

key (str) – Key identifier string from vedo.

Return type:

None

remove(*actors)[source]#

Remove actors from the scene.

Parameters:

*actors (Actor) – Actors to remove.

Return type:

None

render(interactive=None, camera=None, zoom=None, resetcam=False, **kwargs)#

Render the scene.

Parameters:
  • interactive (bool | None) – If None, falls back to settings.INTERACTIVE. When True, execution pauses so the user can interact with the scene.

  • camera (str | dict | None) – Camera name or parameter dict. Falls back to settings.DEFAULT_CAMERA if None.

  • zoom (float | None) – Camera zoom level. Falls back to the atlas default if None.

  • resetcam (bool) – Reset the camera between renders.

  • **kwargs (Any) – Additional arguments forwarded to self.plotter.show.

Return type:

None

property renderables: list[Mesh]#

Return the meshes for all actors.

screenshot(name=None, scale=None, **kwargs)#

Take a screenshot of the current view and save it to file.

Screenshots are saved in screenshots_folder (see Scene).

Parameters:
  • name (str | None) – Output filename. Defaults to a timestamped .png if None. Unsupported extensions are silently replaced with .png.

  • scale (float | None) – Resolution multiplier. Values above 1 increase resolution. Falls back to settings.SCREENSHOT_SCALE if None.

  • **kwargs (Any) – Additional arguments forwarded to render.

Returns:

Absolute path of the saved screenshot.

Return type:

str

slice(plane, actors=None, close_actors=False, invert=False)[source]#

Slice actors with a plane.

Parameters:
  • plane (str | Plane) – If a string it needs to be a supported plane from brainglobe’s atlas api (e.g. "frontal"), otherwise a vedo.Plane mesh.

  • actors (Actor | list[Actor] | None) – Actors to be sliced. If None, all actors will be sliced.

  • close_actors (bool) – If true, the openings in the actors’ meshes caused by the cut will be closed.

  • invert (bool) – Invert the slice direction.

Return type:

None