Skip to content
This repository has been archived by the owner on Mar 17, 2024. It is now read-only.

feat: Minimal reactive volume viewer #4

Merged
merged 3 commits into from
Feb 21, 2024
Merged

Conversation

manzt
Copy link
Collaborator

@manzt manzt commented Feb 21, 2024

Implements proposed API in niivue/ipyniivue#51 using the example from basic multi-planar as an example.

from ipyniivue_experimental import AnyNiivue, SliceType

volumes = [
  { "path": "images/mni152.nii.gz", "colormap": "gray", "visible": True, "opacity": 1.0 },
  { "path": "images/hippo.nii.gz", "colormap": "red", "visible": True, "opacity": 1 },
]
nv = AnyNiivue(slice_type=SliceType.MULTIPLANAR)
nv.load_volumes(volumes)
nv

The volumes are reactive for colormap and opacity. Meaning the above will change interactively with:

v.volumes[0].colormap = "blue"
nv.volumes[0].opacity = 0.2

Finally, I added a script in script/generate_options_mixin.py to generate the _options_mixin.py file. This takes the defaults for all the viewer options and exposes reactive getters/setters for the values.

Thus, you can change viewer-level properties like slice_type programatically:

nv.slice_type = SliceType.SAGITTAL # updates view

Comment on lines +1 to +2
# This file is automatically generated by scripts/generate_options_mixin.py
# Do not edit this file directly
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this file is automatically generated with getters/setters for the front-end properties.

@manzt
Copy link
Collaborator Author

manzt commented Feb 21, 2024

Screen Recording 2024-02-20 at 11 25 42 PM

@manzt
Copy link
Collaborator Author

manzt commented Feb 21, 2024

The default values for the OptionsMixin come from niivue DEFAULT_OPTIONS. I think that several of these properties don't really make sense on the Python side. One thing that would be nice is to annotate those options on the JS comments with extra metadata if we should ignore, and then this whole process can be automated (deriving from the JS as the source of truth).

@kolibril13
Copy link
Collaborator

Just tested this notebook, and I'm impressed with what you implemented here!
image

Also, the auto-generated generate_options_mixin works nicely, I've tried a few options from there.

As this pr is quite large, I suggest that we merge this one soon, and then discuss further steps on discord.

Feel free to also delete the current notebooks and add the Untitled1.ipynb that you show in the demo.

@manzt
Copy link
Collaborator Author

manzt commented Feb 21, 2024

I think we can add the demo later. I prefer not to check in notebooks right now as they cause many issues with version control. Ideally, we should have the examples from niivue/ipyniivue#50 organized nicely into some notebooks like (examples, etc).

@manzt
Copy link
Collaborator Author

manzt commented Feb 21, 2024

@kolibril13 I don't have write access to this repo so I cannot merge.

@kolibril13 kolibril13 merged commit 7bf3515 into niivue:main Feb 21, 2024
@kolibril13
Copy link
Collaborator

Nice, Ive merged this pr now from the GitHub app. I will add you as a repo admin once I am back home

@manzt manzt deleted the manzt/basic branch February 21, 2024 13:23
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants