-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #93 from bcalford/main
Live ipywidget functionality
- Loading branch information
Showing
7 changed files
with
199 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,6 @@ __pycache__ | |
src/ipyniivue/static | ||
|
||
launch.json | ||
|
||
# OS Specific | ||
.DS_Store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,166 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "f26da1e3-877f-4893-8baa-8b9460601205", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"!mkdir -p ../images/\n", | ||
"path=\"https://github.com/niivue/niivue/raw/main/demos/images/\"\n", | ||
"!wget {path}mni152.nii.gz -P ../images/\n", | ||
"!wget {path}hippo.nii.gz -P ../images/" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "cda3a5f6-5bed-4190-82a7-057e17fa6635", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import ipywidgets\n", | ||
"\n", | ||
"from ipyniivue import NiiVue, SliceType, WidgetObserver\n", | ||
"\n", | ||
"volumes = [\n", | ||
" { \"path\": \"../images/mni152.nii.gz\", \"colormap\": \"gray\",\n", | ||
" \"visible\": True, \"opacity\": 1.0 },\n", | ||
" { \"path\": \"../images/hippo.nii.gz\", \"colormap\": \"red\",\n", | ||
" \"visible\": True, \"opacity\": 1.0 },\n", | ||
"]\n", | ||
"\n", | ||
"nv = NiiVue(slice_type=SliceType.MULTIPLANAR)\n", | ||
"nv.load_volumes(volumes)\n", | ||
"\n", | ||
"widgetArray = []\n", | ||
"\n", | ||
"widget_slice_type = {\n", | ||
"\n", | ||
" \"widget\": ipywidgets.RadioButtons(\n", | ||
" options=[('Axial', 0), ('Coronal', 1), ('Sagittal', 2),\n", | ||
" ('Multiplanar', 3), ('Render', 4)],\n", | ||
" value=3,\n", | ||
" description='Slice Type:'),\n", | ||
"\n", | ||
" \"object\": nv,\n", | ||
"\n", | ||
" \"attribute\": \"slice_type\"\n", | ||
"}\n", | ||
"widgetArray.append(widget_slice_type)\n", | ||
"\n", | ||
"widget_scan_opacity = {\n", | ||
"\n", | ||
" \"widget\": ipywidgets.FloatSlider(\n", | ||
" value=1.0,\n", | ||
" min=0.0,\n", | ||
" max=1.0,\n", | ||
" step=0.1,\n", | ||
" description='Scan Opacity:',\n", | ||
" orientation='horizontal'),\n", | ||
"\n", | ||
" \"object\": nv.volumes[0],\n", | ||
"\n", | ||
" \"attribute\": \"opacity\"\n", | ||
"}\n", | ||
"widgetArray.append(widget_scan_opacity)\n", | ||
"\n", | ||
"widget_hippo_opacity = {\n", | ||
"\n", | ||
" \"widget\": ipywidgets.FloatSlider(\n", | ||
" value=1.0,\n", | ||
" min=0.0,\n", | ||
" max=1.0,\n", | ||
" step=0.1,\n", | ||
" description='Hippocampus Opacity:',\n", | ||
" orientation='horizontal'),\n", | ||
"\n", | ||
" \"object\": nv.volumes[1],\n", | ||
"\n", | ||
" \"attribute\": \"opacity\"\n", | ||
"}\n", | ||
"widgetArray.append(widget_hippo_opacity)\n", | ||
"\n", | ||
"widget_scan_colormap = {\n", | ||
"\n", | ||
" \"widget\": ipywidgets.Select(\n", | ||
" options=['Gray', 'Red', 'Blue', 'Green'],\n", | ||
" value='Gray',\n", | ||
" description='Scan Colormap:'),\n", | ||
"\n", | ||
" \"object\": nv.volumes[0],\n", | ||
"\n", | ||
" \"attribute\": \"colormap\"\n", | ||
"}\n", | ||
"widgetArray.append(widget_scan_colormap)\n", | ||
"\n", | ||
"widget_hippo_colormap = {\n", | ||
"\n", | ||
" \"widget\": ipywidgets.Select(\n", | ||
" options=['Red', 'Blue', 'Green', 'Gray'],\n", | ||
" value='Red',\n", | ||
" description='Hippocampus Colormap:'),\n", | ||
"\n", | ||
" \"object\": nv.volumes[1],\n", | ||
"\n", | ||
" \"attribute\": \"colormap\"\n", | ||
"}\n", | ||
"widgetArray.append(widget_hippo_colormap)\n", | ||
"\n", | ||
"for widget in widgetArray:\n", | ||
" WidgetObserver(**widget)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "cce13351-2f24-49fb-b8f6-4bac07f7b2dc", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"nv" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "66b82692-c7b0-471d-8134-f399cf9ac399", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"for widget in widgetArray:\n", | ||
" display(widget[\"widget\"])" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "4c94695d-b936-472e-a4f1-7dc216833388", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3 (ipykernel)", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.12.3" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters