Skip to content

Commit

Permalink
Merge pull request #49 from carlocastoldi/camera-parm
Browse files Browse the repository at this point in the history
add camera option to Heatmap.render()
  • Loading branch information
alessandrofelder committed Jun 17, 2024
2 parents e15d820 + 305ec52 commit 0780736
Showing 1 changed file with 28 additions and 17 deletions.
45 changes: 28 additions & 17 deletions brainglobe_heatmap/heatmaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,19 @@ def show(self, **kwargs) -> Union[Scene, plt.Figure]:
view = self.plot(**kwargs)
return view

def render(self, **kwargs) -> Scene:
def render(self, camera=None) -> Scene:
"""
Renders the hetamap visualization as a 3D scene in brainrender.
Renders the heatmap visualization as a 3D scene in brainrender.
Parameters:
----------
camera : str or dict, optional
The `brainrender` camera to render the scene.
If not provided, `self.orientation` is used.
Returns:
-------
scene : Scene
The rendered 3D scene.
"""

# set brain regions colors
Expand All @@ -148,22 +158,23 @@ def render(self, **kwargs) -> Scene:
0
].color(color)

# set camera position and render
if isinstance(self.orientation, str):
if self.orientation == "sagittal":
camera = cameras.sagittal_camera2
elif self.orientation == "horizontal":
camera = "top"
if camera is None:
# set camera position and render
if isinstance(self.orientation, str):
if self.orientation == "sagittal":
camera = cameras.sagittal_camera2
elif self.orientation == "horizontal":
camera = "top"
else:
camera = self.orientation
else:
camera = self.orientation
else:
self.orientation = np.array(self.orientation)
com = self.slicer.plane0.center_of_mass()
camera = {
"pos": com - self.orientation * 2 * np.linalg.norm(com),
"viewup": (0, -1, 0),
"clipping_range": (19531, 40903),
}
self.orientation = np.array(self.orientation)
com = self.slicer.plane0.center_of_mass()
camera = {
"pos": com - self.orientation * 2 * np.linalg.norm(com),
"viewup": (0, -1, 0),
"clipping_range": (19531, 40903),
}

self.scene.render(
camera=camera, interactive=self.interactive, zoom=self.zoom
Expand Down

0 comments on commit 0780736

Please sign in to comment.