From d8dce2d3949443dec8ad589a91bf89f3240bf78a Mon Sep 17 00:00:00 2001 From: IgorTatarnikov Date: Wed, 1 Nov 2023 11:58:27 +0000 Subject: [PATCH] Added to changes to conform to vedo 2023.5.0+dev26a --- brainrender/_colors.py | 2 +- brainrender/actor.py | 12 ++++++------ brainrender/actors/cylinder.py | 2 +- brainrender/actors/points.py | 2 +- brainrender/actors/ruler.py | 2 +- examples/add_mesh_from_file.py | 2 +- examples/cell_density.py | 2 +- examples/neurons.py | 2 +- examples/screenshot.py | 2 +- examples/user_volumetric_data.py | 2 +- examples/volumetric_data.py | 4 ++-- 11 files changed, 17 insertions(+), 17 deletions(-) diff --git a/brainrender/_colors.py b/brainrender/_colors.py index 61f09b6e..e69b6020 100644 --- a/brainrender/_colors.py +++ b/brainrender/_colors.py @@ -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): diff --git a/brainrender/actor.py b/brainrender/actor.py index b3f9cf81..ebbc9feb 100644 --- a/brainrender/actor.py +++ b/brainrender/actor.py @@ -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 @@ -45,7 +45,7 @@ def make_actor_label( color = [0.2, 0.2, 0.2] # Get mesh's highest point - points = actor.mesh.points().copy() + points = actor.mesh.vertices.copy() point = points[np.argmin(points[:, 1]), :] point += np.array(offset) + default_offset point[2] = -point[2] @@ -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 @@ -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): @@ -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)}" diff --git a/brainrender/actors/cylinder.py b/brainrender/actors/cylinder.py index 715b2689..0c1d2223 100644 --- a/brainrender/actors/cylinder.py +++ b/brainrender/actors/cylinder.py @@ -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}") diff --git a/brainrender/actors/points.py b/brainrender/actors/points.py index 5568c095..22cbd089 100644 --- a/brainrender/actors/points.py +++ b/brainrender/actors/points.py @@ -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 diff --git a/brainrender/actors/ruler.py b/brainrender/actors/ruler.py index f4a98f9d..735cec5d 100644 --- a/brainrender/actors/ruler.py +++ b/brainrender/actors/ruler.py @@ -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 diff --git a/examples/add_mesh_from_file.py b/examples/add_mesh_from_file.py index 375e6a72..d6a0bc4a 100644 --- a/examples/add_mesh_from_file.py +++ b/examples/add_mesh_from_file.py @@ -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() diff --git a/examples/cell_density.py b/examples/cell_density.py index fcfa2bfb..2a97fa7c 100644 --- a/examples/cell_density.py +++ b/examples/cell_density.py @@ -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)) diff --git a/examples/neurons.py b/examples/neurons.py index 46d930bb..f1c17a9d 100644 --- a/examples/neurons.py +++ b/examples/neurons.py @@ -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() diff --git a/examples/screenshot.py b/examples/screenshot.py index 6fd7e462..efe6b50a 100644 --- a/examples/screenshot.py +++ b/examples/screenshot.py @@ -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. diff --git a/examples/user_volumetric_data.py b/examples/user_volumetric_data.py index 3dd1c32c..ddfd7f8a 100644 --- a/examples/user_volumetric_data.py +++ b/examples/user_volumetric_data.py @@ -74,7 +74,7 @@ # 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).smooth_median() # 4. Extract a surface mesh from the volume actor diff --git a/examples/volumetric_data.py b/examples/volumetric_data.py index f67a5df6..d3c1fb60 100644 --- a/examples/volumetric_data.py +++ b/examples/volumetric_data.py @@ -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