-
Notifications
You must be signed in to change notification settings - Fork 0
reinvigorate old multichannel PR #9
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -166,6 +166,12 @@ def __init__( | |||||||||||||
| self.viewer.camera.events.zoom.connect(self._on_cursor) | ||||||||||||||
| self.viewer.layers.events.reordered.connect(self._reorder_layers) | ||||||||||||||
| self.viewer.layers.events.removed.connect(self._remove_layer) | ||||||||||||||
| self.viewer.multi_channel_gridcanvas.events.enabled.connect( | ||||||||||||||
| self._on_grid_change | ||||||||||||||
| ) | ||||||||||||||
| self.viewer.multi_channel_gridcanvas.events.stride.connect( | ||||||||||||||
| self._on_grid_change | ||||||||||||||
| ) | ||||||||||||||
| self.destroyed.connect(self._disconnect_theme) | ||||||||||||||
|
|
||||||||||||||
| @property | ||||||||||||||
|
|
@@ -334,7 +340,14 @@ def _map_canvas2world( | |||||||||||||
| of the viewer. | ||||||||||||||
| """ | ||||||||||||||
| nd = self.viewer.dims.ndisplay | ||||||||||||||
| transform = self.view.scene.transform | ||||||||||||||
| # TODO: figure out how to extent this to all grid boxes, main thing is to see which viewbox the mouse is hovering over | ||||||||||||||
| # and to get the transform solely of that viewbox. This would allow compatibility with current code returning one | ||||||||||||||
| # position world. | ||||||||||||||
| if self.viewer.multi_channel_gridcanvas.enabled: | ||||||||||||||
| transform = self.grid_views[0].scene.transform | ||||||||||||||
| else: | ||||||||||||||
| transform = self.view.scene.transform | ||||||||||||||
|
|
||||||||||||||
| # cartesian to homogeneous coordinates | ||||||||||||||
| mapped_position = transform.imap(list(position)) | ||||||||||||||
| if nd == 3: | ||||||||||||||
|
|
@@ -681,3 +694,56 @@ def screenshot(self) -> QImage: | |||||||||||||
| def enable_dims_play(self, *args) -> None: | ||||||||||||||
| """Enable playing of animation. False if awaiting a draw event""" | ||||||||||||||
| self.viewer.dims._play_ready = True | ||||||||||||||
|
|
||||||||||||||
| def _on_grid_change(self): | ||||||||||||||
| """Change grid view""" | ||||||||||||||
| if self.viewer.multi_channel_gridcanvas.enabled: | ||||||||||||||
| grid_shape, n_gridboxes = ( | ||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue (code-quality): Extract code out into method ( |
||||||||||||||
| self.viewer.multi_channel_gridcanvas.actual_shape( | ||||||||||||||
| len(self.layer_to_visual) | ||||||||||||||
| ) | ||||||||||||||
| ) | ||||||||||||||
|
|
||||||||||||||
| self.grid = self.central_widget.add_grid() | ||||||||||||||
| camera = self.camera._view.camera | ||||||||||||||
| self.grid_views = [ | ||||||||||||||
| self.grid.add_view( | ||||||||||||||
| row=y, col=x, camera=camera if y == 0 and x == 0 else None | ||||||||||||||
| ) | ||||||||||||||
| for y in range(grid_shape[0]) | ||||||||||||||
| for x in range(grid_shape[1]) | ||||||||||||||
| if x * y < n_gridboxes | ||||||||||||||
|
Comment on lines
+713
to
+715
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (bug_risk): Review grid view index calculation in the list comprehension. Use (y * grid_shape[1] + x) instead of x * y to compute the grid index and preserve row-major ordering.
Suggested change
|
||||||||||||||
| ] | ||||||||||||||
| self.camera._view = self.grid_views[0] | ||||||||||||||
| self.central_widget.remove_widget(self.view) | ||||||||||||||
| # del self.view | ||||||||||||||
| self.grid_cameras = [ | ||||||||||||||
| VispyCamera( | ||||||||||||||
| self.grid_views[i], self.viewer.camera, self.viewer.dims | ||||||||||||||
| ) | ||||||||||||||
| for i in range(len(self.grid_views[1:])) | ||||||||||||||
| ] | ||||||||||||||
|
|
||||||||||||||
| for ind, layer in enumerate(self.layer_to_visual.values()): | ||||||||||||||
| if ind != 0: | ||||||||||||||
| self.grid_views[ind].camera = self.grid_cameras[ | ||||||||||||||
| ind - 1 | ||||||||||||||
| ]._view.camera | ||||||||||||||
| self.grid_views[ind].camera.link(self.grid_views[0].camera) | ||||||||||||||
| layer.node.parent = self.grid_views[ind].scene | ||||||||||||||
| else: | ||||||||||||||
| for layer in self.layer_to_visual.values(): | ||||||||||||||
| layer.node.parent = self.view.scene | ||||||||||||||
| self.central_widget.remove_widget(self.grid) | ||||||||||||||
| self.central_widget.add_widget(self.view) | ||||||||||||||
| self.camera._view = self.view | ||||||||||||||
|
|
||||||||||||||
| # TODO properly disconnect events of grid and delete all viewboxes | ||||||||||||||
| del self.grid | ||||||||||||||
|
|
||||||||||||||
| for camera in self.grid_cameras: | ||||||||||||||
| camera.disconnect() | ||||||||||||||
| del camera | ||||||||||||||
|
|
||||||||||||||
| # TODO respect 3d camera if enabled | ||||||||||||||
| self.camera._view.camera = self.camera._2D_camera | ||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (complexity): Consider refactoring the
_on_grid_changemethod by extracting the enabling/disabling logic into separate helper functions.Refactor the method by offloading the enabling/disabling logic to helper functions. This will keep the functionality intact while reducing the inline branching and list comprehensions. For example:
Actionable Steps:
_enable_grid_modeand_disable_grid_mode._on_grid_changeinto these helper functions._on_grid_change, simply check the condition and call the appropriate helper.This refactoring decouples responsibilities, making the control flow easier to follow and maintain.