diff --git a/benchmark/bm_cells.py b/benchmark/bm_cells.py index 6170d8e5..4af2f5f1 100644 --- a/benchmark/bm_cells.py +++ b/benchmark/bm_cells.py @@ -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)) diff --git a/benchmark/bm_napari.py b/benchmark/bm_napari.py index d802d458..7968ed8f 100644 --- a/benchmark/bm_napari.py +++ b/benchmark/bm_napari.py @@ -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 diff --git a/benchmark/timer.py b/benchmark/timer.py index e6eb560a..2422a9d6 100644 --- a/benchmark/timer.py +++ b/benchmark/timer.py @@ -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( @@ -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) 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..82257165 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 @@ -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/brainrender/actors/volume.py b/brainrender/actors/volume.py index 4f49ce75..cd5da987 100644 --- a/brainrender/actors/volume.py +++ b/brainrender/actors/volume.py @@ -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): """ diff --git a/examples/add_cells.py b/examples/add_cells.py index 42dcfb3b..a52b0c59 100644 --- a/examples/add_cells.py +++ b/examples/add_cells.py @@ -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)) 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..09f80a14 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..19b18e1e 100644 --- a/examples/user_volumetric_data.py +++ b/examples/user_volumetric_data.py @@ -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 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 diff --git a/tests/test_volume.py b/tests/test_volume.py index cb67ff73..d239d52e 100644 --- a/tests/test_volume.py +++ b/tests/test_volume.py @@ -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