Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add camera option to Heatmap.render() #49

Merged
merged 2 commits into from
Jun 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
view = self.plot(**kwargs)
return view

def render(self, **kwargs) -> Scene:
def render(self, camera=None) -> Scene:

Check warning on line 137 in brainglobe_heatmap/heatmaps.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_heatmap/heatmaps.py#L137

Added line #L137 was not covered by tests
"""
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 @@
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:

Check warning on line 161 in brainglobe_heatmap/heatmaps.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_heatmap/heatmaps.py#L161

Added line #L161 was not covered by tests
# set camera position and render
if isinstance(self.orientation, str):
if self.orientation == "sagittal":
camera = cameras.sagittal_camera2
elif self.orientation == "horizontal":
camera = "top"

Check warning on line 167 in brainglobe_heatmap/heatmaps.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_heatmap/heatmaps.py#L163-L167

Added lines #L163 - L167 were not covered by tests
else:
camera = self.orientation

Check warning on line 169 in brainglobe_heatmap/heatmaps.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_heatmap/heatmaps.py#L169

Added line #L169 was not covered by tests
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 = {

Check warning on line 173 in brainglobe_heatmap/heatmaps.py

View check run for this annotation

Codecov / codecov/patch

brainglobe_heatmap/heatmaps.py#L171-L173

Added lines #L171 - L173 were not covered by tests
"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
Loading