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 7 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: str
:param alpha: float
:param linewidth: float
:param name: str
paulbrodersen marked this conversation as resolved.
Show resolved Hide resolved
"""

# Create mesh and Actor
mesh = shapes.Line(p0=coordinates, lw=linewidth, c=color, alpha=alpha)
Actor.__init__(self, mesh, name=name, br_class="Line")
45 changes: 45 additions & 0 deletions examples/line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
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 at 25 micrometer resolution.
adamltyson marked this conversation as resolved.
Show resolved Hide resolved
scene = Scene(atlas_name="allen_mouse_25um")
adamltyson marked this conversation as resolved.
Show resolved Hide resolved

# Highlight the cerebral cortex; 688 is the corresponding Allen Brain Atlas ID.
scene.add_brain_region(688, alpha=0.2, color="green")
adamltyson marked this conversation as resolved.
Show resolved Hide resolved

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

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

# Display the shortest path within cortex boundaries between the two points.
paulbrodersen marked this conversation as resolved.
Show resolved Hide resolved
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],
]
)

scene.add(Line(path_coordinates, linewidth=3, color="black"))
adamltyson marked this conversation as resolved.
Show resolved Hide resolved

# 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