-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Implement Line actor class * Add Line actor to imports in actors.__init__.py * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Add minimal-ish, reproducible example of the Line actor class * Add Line actor test * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Expand documentation of color specification * Remove reference to atlas resolution * Indicate how path coordinates were pre-computed. * Retain references to instantiated actors. * Replace ABA ID with corresponding abbreviation. * Format array in line with the pre-commit style. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
ffa7ee6
commit e91f9ef
Showing
4 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
|
||
from brainrender import Scene | ||
from brainrender.actors import Points, Line | ||
|
||
# Display the Allen Brain mouse atlas. | ||
scene = Scene(atlas_name="allen_mouse_25um") | ||
|
||
# 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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |