Skip to content

Commit 77b4198

Browse files
authored
Merge pull request #371 from thewtex/axes
ENH: Add axes viewer trait
2 parents 93efa15 + 258212a commit 77b4198

File tree

5 files changed

+56
-19
lines changed

5 files changed

+56
-19
lines changed

examples/3DImage.ipynb

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,20 @@
22
"cells": [
33
{
44
"cell_type": "code",
5-
"execution_count": null,
5+
"execution_count": 1,
66
"metadata": {},
7-
"outputs": [],
7+
"outputs": [
8+
{
9+
"name": "stdout",
10+
"output_type": "stream",
11+
"text": [
12+
"Requirement already satisfied: itk-io in /home/matt/bin/miniconda3/envs/itkwidgets/lib/python3.7/site-packages (5.1.0.post3)\n",
13+
"Requirement already satisfied: itk-core==5.1.0.post3 in /home/matt/bin/miniconda3/envs/itkwidgets/lib/python3.7/site-packages (from itk-io) (5.1.0.post3)\n",
14+
"\u001b[33mWARNING: You are using pip version 20.1.1; however, version 20.2 is available.\n",
15+
"You should consider upgrading via the '/home/matt/bin/miniconda3/envs/itkwidgets/bin/python -m pip install --upgrade pip' command.\u001b[0m\n"
16+
]
17+
}
18+
],
819
"source": [
920
"# Install dependencies for this example\n",
1021
"# Note: This does not include itkwidgets, itself\n",
@@ -14,7 +25,7 @@
1425
},
1526
{
1627
"cell_type": "code",
17-
"execution_count": 1,
28+
"execution_count": 2,
1829
"metadata": {},
1930
"outputs": [],
2031
"source": [
@@ -28,7 +39,7 @@
2839
},
2940
{
3041
"cell_type": "code",
31-
"execution_count": 2,
42+
"execution_count": 3,
3243
"metadata": {},
3344
"outputs": [],
3445
"source": [
@@ -41,18 +52,18 @@
4152
},
4253
{
4354
"cell_type": "code",
44-
"execution_count": 7,
55+
"execution_count": 13,
4556
"metadata": {},
4657
"outputs": [
4758
{
4859
"data": {
4960
"application/vnd.jupyter.widget-view+json": {
50-
"model_id": "57448261fbe849c4bacc9af9a83f9f14",
61+
"model_id": "87d82520fc054f12911be983a07bbabd",
5162
"version_major": 2,
5263
"version_minor": 0
5364
},
5465
"text/plain": [
55-
"Viewer(geometries=[], gradient_opacity=0.9, point_sets=[], rendered_image=<itkImagePython.itkImageSS3; proxy o"
66+
"Viewer(axes=True, geometries=[], gradient_opacity=0.9, point_sets=[], rendered_image=<itk.itkImagePython.itkIm"
5667
]
5768
},
5869
"metadata": {},
@@ -61,7 +72,7 @@
6172
],
6273
"source": [
6374
"image = itk.imread(file_name)\n",
64-
"view(image, rotate=True, vmin=4000, vmax=17000, gradient_opacity=0.9)"
75+
"view(image, rotate=True, axes=True, vmin=4000, vmax=17000, gradient_opacity=0.9)"
6576
]
6677
},
6778
{

itkwidgets/widget_viewer.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,10 @@ class Viewer(ViewerParent):
305305
default_value=True,
306306
help="Show annotations.").tag(
307307
sync=True)
308+
axes = CBool(
309+
default_value=False,
310+
help="Display axes.").tag(
311+
sync=True)
308312
mode = CaselessStrEnum(
309313
('x',
310314
'y',
@@ -788,7 +792,7 @@ def view(image=None, # noqa: C901
788792
point_set_representations=[], point_set_sizes=[],
789793
geometries=[],
790794
geometry_colors=[], geometry_opacities=[],
791-
ui_collapsed=False, rotate=False, annotations=True, mode='v',
795+
ui_collapsed=False, rotate=False, annotations=True, axes=False, mode='v',
792796
**kwargs):
793797
"""View the image and/or point sets and/or geometries.
794798
@@ -825,6 +829,9 @@ def view(image=None, # noqa: C901
825829
Display annotations describing orientation and the value of a
826830
mouse-position-based data probe.
827831
832+
axes : bool, default: False
833+
Display axes.
834+
828835
mode: 'x', 'y', 'z', or 'v', default: 'v'
829836
Only relevant for 3D scenes.
830837
Viewing mode:
@@ -1074,6 +1081,7 @@ def view(image=None, # noqa: C901
10741081
point_set_representations=point_set_representations,
10751082
point_set_sizes=point_set_sizes,
10761083
geometries=geometries, geometry_colors=geometry_colors, geometry_opacities=geometry_opacities,
1077-
rotate=rotate, ui_collapsed=ui_collapsed, annotations=annotations, mode=mode,
1084+
rotate=rotate, ui_collapsed=ui_collapsed,
1085+
annotations=annotations, axes=axes, mode=mode,
10781086
**kwargs)
10791087
return viewer

js/lib/viewer.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ const ViewerModel = widgets.DOMWidgetModel.extend(
154154
ui_collapsed: false,
155155
rotate: false,
156156
annotations: true,
157+
axes: true,
157158
mode: 'v',
158159
camera: new Float32Array(9),
159160
background: null
@@ -712,6 +713,7 @@ const ViewerView = widgets.DOMWidgetView.extend({
712713
const rendered_image = this.model.get('rendered_image')
713714
const rendered_label_image = this.model.get('rendered_label_image')
714715
this.annotations_changed()
716+
this.axes_changed()
715717

716718
const onBackgroundChanged = (background) => {
717719
this.model.set('background', background)
@@ -781,6 +783,14 @@ const ViewerView = widgets.DOMWidgetView.extend({
781783
}
782784
this.model.itkVtkViewer.on('toggleAnnotations', onAnnotationsToggle)
783785

786+
const onAxesToggle = (enabled) => {
787+
if (enabled !== this.model.get('axes')) {
788+
this.model.set('axes', enabled)
789+
this.model.save_changes()
790+
}
791+
}
792+
this.model.itkVtkViewer.on('toggleAxes', onAxesToggle)
793+
784794
const onInterpolationToggle = (enabled) => {
785795
if (enabled !== this.model.get('interpolation')) {
786796
this.model.set('interpolation', enabled)
@@ -1214,6 +1224,7 @@ const ViewerView = widgets.DOMWidgetView.extend({
12141224
this.model.on('change:ui_collapsed', this.ui_collapsed_changed, this)
12151225
this.model.on('change:rotate', this.rotate_changed, this)
12161226
this.model.on('change:annotations', this.annotations_changed, this)
1227+
this.model.on('change:axes', this.axes_changed, this)
12171228
this.model.on('change:mode', this.mode_changed, this)
12181229
this.model.on('change:units', this.units_changed, this)
12191230
this.model.on('change:camera', this.camera_changed, this)
@@ -1547,6 +1558,13 @@ const ViewerView = widgets.DOMWidgetView.extend({
15471558
}
15481559
},
15491560

1561+
axes_changed: function () {
1562+
const axes = this.model.get('axes')
1563+
if (this.model.hasOwnProperty('itkVtkViewer')) {
1564+
this.model.itkVtkViewer.setAxesEnabled(axes)
1565+
}
1566+
},
1567+
15501568
mode_changed: function () {
15511569
const mode = this.model.get('mode')
15521570
if (this.model.hasOwnProperty('itkVtkViewer') && !this.model.use2D) {

js/package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

js/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@
6363
"copy-webpack-plugin": "^5.1.1",
6464
"css-element-queries": "^1.2.3",
6565
"itk": "^13.1.1",
66-
"itk-vtk-viewer": "^10.6.0",
66+
"itk-vtk-viewer": "^10.7.2",
6767
"jupyter-dataserializers": "^2.2.0",
6868
"mobx": "^5.15.4",
6969
"regenerator-runtime": "^0.13.5",
70-
"vtk.js": "^14.10.4"
70+
"vtk.js": "^14.12.0"
7171
},
7272
"jupyterlab": {
7373
"extension": "dist/labextension"

0 commit comments

Comments
 (0)