From 1537b8e5fe3d05282e956b70d3842c8c32c92d9f Mon Sep 17 00:00:00 2001 From: Igor Tatarnikov Date: Wed, 14 Aug 2024 16:49:17 +0100 Subject: [PATCH 1/2] Changed the way the midpoint is calculated from center of mass to center of bounding box --- brainrender/scene.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/brainrender/scene.py b/brainrender/scene.py index dcf4a0a2..7d98c8ab 100644 --- a/brainrender/scene.py +++ b/brainrender/scene.py @@ -288,13 +288,11 @@ def add_brain_region( # slice to keep only one hemisphere if hemisphere == "right": - plane = self.atlas.get_plane( - pos=self.root._mesh.center_of_mass(), norm=(0, 0, 1) - ) + mesh_center = self.root._mesh.bounds().reshape((3, 2)).mean(axis=1) + plane = self.atlas.get_plane(pos=mesh_center, norm=(0, 0, 1)) elif hemisphere == "left": - plane = self.atlas.get_plane( - pos=self.root._mesh.center_of_mass(), norm=(0, 0, -1) - ) + mesh_center = self.root._mesh.bounds().reshape((3, 2)).mean(axis=1) + plane = self.atlas.get_plane(pos=mesh_center, norm=(0, 0, -1)) if hemisphere in ("left", "right"): if not isinstance(actors, list): From 89ffcaf49c60118815f6d18d9618ae44538583e5 Mon Sep 17 00:00:00 2001 From: Igor Tatarnikov Date: Thu, 15 Aug 2024 11:35:41 +0100 Subject: [PATCH 2/2] Added check for symmetrical atlas --- brainrender/scene.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/brainrender/scene.py b/brainrender/scene.py index 7d98c8ab..b6deb655 100644 --- a/brainrender/scene.py +++ b/brainrender/scene.py @@ -287,14 +287,17 @@ def add_brain_region( actors = self.add(*regions) # slice to keep only one hemisphere - if hemisphere == "right": - mesh_center = self.root._mesh.bounds().reshape((3, 2)).mean(axis=1) - plane = self.atlas.get_plane(pos=mesh_center, norm=(0, 0, 1)) - elif hemisphere == "left": - mesh_center = self.root._mesh.bounds().reshape((3, 2)).mean(axis=1) - plane = self.atlas.get_plane(pos=mesh_center, norm=(0, 0, -1)) - if hemisphere in ("left", "right"): + if self.atlas.metadata["symmetric"]: + mesh_center = ( + self.root._mesh.bounds().reshape((3, 2)).mean(axis=1) + ) + else: + mesh_center = self.root._mesh.center_of_mass() + + normal = (0, 0, 1) if hemisphere == "right" else (0, 0, -1) + plane = self.atlas.get_plane(pos=mesh_center, norm=normal) + if not isinstance(actors, list): actors._mesh.cut_with_plane( origin=plane.center,