Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add line actor #334

Merged
merged 14 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions brainrender/actors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
from brainrender.actors.cylinder import Cylinder
from brainrender.actors.volume import Volume
from brainrender.actors.streamlines import Streamlines
from brainrender.actors.line import Line
22 changes: 22 additions & 0 deletions brainrender/actors/line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from vedo import shapes

from brainrender.actor import Actor


class Line(Actor):
def __init__(
self, coordinates, color="black", alpha=1, linewidth=2, name=None
):
"""
Creates an actor representing a single line.

:param coordinates: list, np.ndarray with shape (N, 3) of ap, dv, ml coordinates.
:param color: CSS named color str, hex code, or RGB tuple, e.g. "white", "#ffffff", or (255, 255, 255)
:param alpha: float in range 0.0 to 1.0
:param linewidth: float
:param name: str
"""

# Create mesh and Actor
mesh = shapes.Line(p0=coordinates, lw=linewidth, c=color, alpha=alpha)
Actor.__init__(self, mesh, name=name, br_class="Line")
48 changes: 48 additions & 0 deletions examples/line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import numpy as np
import vedo

vedo.settings.default_backend = "vtk"
adamltyson marked this conversation as resolved.
Show resolved Hide resolved

from brainrender import Scene
from brainrender.actors import Points, Line

# Display the Allen Brain mouse atlas.
scene = Scene(atlas_name="allen_mouse_25um")
adamltyson marked this conversation as resolved.
Show resolved Hide resolved

# Highlight the cerebral cortex.
scene.add_brain_region("CTX", alpha=0.2, color="green")

# Add two points identifying the positions of two cortical neurons.
point_coordinates = np.array([[4575, 5050, 9750], [4275, 2775, 6100]])

points = Points(point_coordinates, radius=100, colors="blue")
scene.add(points)

# Display the shortest path within cortex between the two points.
# The path was pre-calculated with https://github.com/seung-lab/dijkstra3d/.
path_coordinates = np.array(
[
[4575, 5050, 9750],
[4575, 4800, 9500],
[4575, 4550, 9250],
[4575, 4300, 9000],
[4575, 4050, 8750],
[4350, 3800, 8500],
[4225, 3550, 8250],
[4200, 3300, 8000],
[4200, 3100, 7750],
[4200, 2950, 7500],
[4200, 2800, 7250],
[4200, 2700, 7000],
[4200, 2650, 6750],
[4200, 2650, 6500],
[4200, 2650, 6250],
[4275, 2775, 6100],
]
)

line = Line(path_coordinates, linewidth=3, color="black")
scene.add(line)

# Render the scene and display the figure.
scene.render()
24 changes: 24 additions & 0 deletions tests/test_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import numpy as np

from brainrender import Scene
from brainrender.actor import Actor
from brainrender.actors import Line


def test_line():
s = Scene()

line = Line(
np.array(
[
[0, 0, 0],
[1, 1, 1],
[2, 2, 2],
]
)
)

s.add(line)
assert isinstance(line, Actor)

del s
Loading