Skip to content

Commit

Permalink
Compatibility with vedo 2023.5.0 (#277)
Browse files Browse the repository at this point in the history
* Added to changes to conform to vedo 2023.5.0+dev26a

* Further compatibility updates

* Changed function name in bm_cells from camel case to snake case

* Fixed colormap related issue

* Cleaned up return from volume.py::_from_numpy()

* Fixed failing volume test by removing mode=2 for now
  • Loading branch information
IgorTatarnikov authored Nov 16, 2023
1 parent ebde569 commit 02b7565
Show file tree
Hide file tree
Showing 17 changed files with 25 additions and 24 deletions.
2 changes: 1 addition & 1 deletion benchmark/bm_cells.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def get_n_random_points_in_region(region, N):
Z = np.random.randint(region_bounds[4], region_bounds[5], size=10000)
pts = [[x, y, z] for x, y, z in zip(X, Y, Z)]

ipts = region.mesh.insidePoints(pts).points()
ipts = region.mesh.inside_points(pts).coordinates
return np.vstack(random.choices(ipts, k=N))


Expand Down
2 changes: 1 addition & 1 deletion benchmark/bm_napari.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
surfaces = []
for act in scene.clean_actors:
surfaces.append(
(act.points(), act.faces(), np.ones(len(act.points())) * 0.5)
(act.vertices, act.cells, np.ones(len(act.vertices)) * 0.5)
)

# render stuff in napar
Expand Down
4 changes: 2 additions & 2 deletions benchmark/timer.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def __rich_console__(self, console, dimension):
)
for act in self.scene.clean_actors:
try:
points = len(act.points())
points = act.npoints
except AttributeError:
points = 0
actors.add(
Expand Down Expand Up @@ -71,7 +71,7 @@ def __rich_console__(self, console, dimension):
points = []
for act in self.scene.clean_actors:
try:
points.append(len(act.points()))
points.append(act.npoints)
except AttributeError:
pass
tot_points = sum(points)
Expand Down
2 changes: 1 addition & 1 deletion brainrender/_colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import matplotlib.cm as cm_mpl
import numpy as np
from vedo.colors import colors as vcolors
from vedo.colors import getColor
from vedo.colors import get_color as getColor


def map_color(value, name="jet", vmin=None, vmax=None):
Expand Down
10 changes: 5 additions & 5 deletions brainrender/actor.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def make_actor_label(
zoffset=0,
):
"""
Adds a 2D text ancored to a point on the actor's mesh
Adds a 2D text anchored to a point on the actor's mesh
to label what the actor is
:param kwargs: keyword arguments can be passed to determine
Expand Down Expand Up @@ -64,12 +64,12 @@ def make_actor_label(

# Mark a point on Mesh that corresponds to the label location
if radius is not None:
pt = actor.closestPoint(point)
pt = actor.closest_point(point)
pt[2] = -pt[2]
sphere = Sphere(pt, r=radius, c=color, res=8)
sphere.ancor = pt
new_actors.append(sphere)
sphere.computeNormals()
sphere.compute_normals()

return new_actors

Expand Down Expand Up @@ -159,7 +159,7 @@ def center(self):
"""
Returns the coordinates of the mesh's center
"""
return self.mesh.points().mean(axis=0)
return self.mesh.center_of_mass()

@classmethod
def make_actor(cls, mesh, name, br_class):
Expand Down Expand Up @@ -218,7 +218,7 @@ def __rich_console__(self, *args):
f"[{orange}]center of mass:[/{orange}][{amber}] {self.mesh.center_of_mass().astype(np.int32)}"
)
rep.add(
f"[{orange}]number of vertices:[/{orange}][{amber}] {len(self.mesh.points())}"
f"[{orange}]number of vertices:[/{orange}][{amber}] {self.mesh.npoints}"
)
rep.add(
f"[{orange}]dimensions:[/{orange}][{amber}] {np.array(self.mesh.bounds()).astype(np.int32)}"
Expand Down
2 changes: 1 addition & 1 deletion brainrender/actors/cylinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def __init__(self, pos, root, color="powderblue", alpha=1, radius=350):

# Get pos
if isinstance(pos, Mesh):
pos = pos.points().mean(axis=0)
pos = pos.center_of_mass()
elif isinstance(pos, Actor):
pos = pos.center
logger.debug(f"Creating Cylinder actor at: {pos}")
Expand Down
2 changes: 1 addition & 1 deletion brainrender/actors/points.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def __init__(
volume = (
vPoints(data)
.density(dims=dims, radius=radius, **kwargs)
.c("Dark2")
.cmap("Dark2")
.alpha([0, 0.9])
.mode(1)
) # returns a vedo Volume
Expand Down
2 changes: 1 addition & 1 deletion brainrender/actors/ruler.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def ruler(p1, p2, unit_scale=1, units=None, s=50):
dist = mag(p2 - p1) * unit_scale
label = precision(dist, 3) + " " + units
lbl = Text3D(label, pos=midpoint, s=s + 100, justify="center")
lbl.SetOrientation([0, 0, 180])
# lbl.SetOrientation([0, 0, 180])
actors.append(lbl)

# Add spheres add end
Expand Down
4 changes: 2 additions & 2 deletions brainrender/actors/volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,12 @@ def _from_numpy(self, griddata, voxel_size, color, **volume_kwargs):
Creates a vedo.Volume actor from a 3D numpy array
with volume data
"""

return VedoVolume(
griddata,
spacing=[voxel_size, voxel_size, voxel_size],
c=color,
**volume_kwargs,
)
).cmap(color)

def _from_file(self, filepath, voxel_size, color, **volume_kwargs):
"""
Expand Down
2 changes: 1 addition & 1 deletion examples/add_cells.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def get_n_random_points_in_region(region, N):
Z = np.random.randint(region_bounds[4], region_bounds[5], size=10000)
pts = [[x, y, z] for x, y, z in zip(X, Y, Z)]

ipts = region.mesh.inside_points(pts).points()
ipts = region.mesh.inside_points(pts).coordinates
return np.vstack(random.choices(ipts, k=N))


Expand Down
2 changes: 1 addition & 1 deletion examples/add_mesh_from_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
scene.add_brain_region("SCm", alpha=0.2)

# Add from file
scene.add("examples/data/CC_134_1_ch1inj.obj", color="tomato")
scene.add("data/CC_134_1_ch1inj.obj", color="tomato")

# Render!
scene.render()
2 changes: 1 addition & 1 deletion examples/cell_density.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def get_n_random_points_in_region(region, N):
Z = np.random.randint(region_bounds[4], region_bounds[5], size=10000)
pts = [[x, y, z] for x, y, z in zip(X, Y, Z)]

ipts = region.mesh.inside_points(pts).points()
ipts = region.mesh.inside_points(pts).vertices
return np.vstack(random.choices(ipts, k=N))


Expand Down
2 changes: 1 addition & 1 deletion examples/neurons.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
scene = Scene(title="neurons")

# Add a neuron from file
scene.add(Neuron("examples/data/neuron1.swc"))
scene.add(Neuron("data/neuron1.swc"))

# Download neurons data with morphapi
mlapi = MouseLightAPI()
Expand Down
2 changes: 1 addition & 1 deletion examples/screenshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"focalPoint": (7718, 4290, -3507),
"distance": 40610,
}
zoom = 1.5
zoom = 2.5

# If you only want a screenshot and don't want to move the camera
# around the scene, set interactive to False.
Expand Down
3 changes: 2 additions & 1 deletion examples/user_volumetric_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@

# 3. create a Volume vedo actor and smooth
print("Creating volume")
vol = Volume(transformed_stack, origin=scene.root.origin()).smooth_median()
vol = Volume(transformed_stack).permute_axes(2, 1, 0)
vol.smooth_median()


# 4. Extract a surface mesh from the volume actor
Expand Down
4 changes: 2 additions & 2 deletions examples/volumetric_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@

scene = Scene(inset=False)

data = np.load("examples/data/volume.npy")
data = np.load("data/volume.npy")
print(data.shape)

# make a volume actor and add
actor = Volume(
"examples/data/volume.npy",
"data/volume.npy",
voxel_size=200, # size of a voxel's edge in microns
as_surface=False, # if true a surface mesh is rendered instead of a volume
c="Reds", # use matplotlib colormaps to color the volume
Expand Down
2 changes: 1 addition & 1 deletion tests/test_volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ def test_volume():

data = np.load("examples/data/volume.npy")
s.add(Volume(data, voxel_size=200, as_surface=False, c="Reds"))
s.add(Volume(data, voxel_size=200, as_surface=True, c="Reds", mode=2))
s.add(Volume(data, voxel_size=200, as_surface=True, c="Reds"))
del s

0 comments on commit 02b7565

Please sign in to comment.