Skip to content

Commit 3fb9570

Browse files
committed
ENH: Add sample_distance trait
1 parent 93a6b74 commit 3fb9570

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

itkwidgets/widget_viewer.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,8 @@ class Viewer(ViewerParent):
238238
help="Size limit for 2D image visualization.").tag(sync=False)
239239
size_limit_3d = NDArray(dtype=np.int64, default_value=np.array([192, 192, 192], dtype=np.int64),
240240
help="Size limit for 3D image visualization.").tag(sync=False)
241+
sample_distance = CFloat(default_value=0.25,
242+
help="Normalized volume rendering sample distance.").tag(sync=True)
241243
_scale_factors = NDArray(dtype=np.uint8, default_value=np.array([1, 1, 1], dtype=np.uint8),
242244
help="Image downscaling factors.").tag(sync=True, **array_serialization)
243245
_downsampling = CBool(default_value=False,
@@ -906,6 +908,11 @@ def view(image=None, # noqa: C901
906908
Size limit for 3D image visualization. If the roi is larger than this
907909
size, it will be downsampled for visualization.
908910
911+
sample_distance: float, default: 0.25
912+
Sampling distance for volume rendering, normalized from 0.0 to 1.0.
913+
Lower values result in a higher quality rendering. High values improve
914+
the framerate.
915+
909916
Returns
910917
-------
911918
viewer : ipywidget

js/lib/viewer.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ const ViewerModel = widgets.DOMWidgetModel.extend(
132132
z_slice: null,
133133
clicked_slice_point: null,
134134
gradient_opacity: 0.2,
135+
sample_distance: 0.25,
135136
opacity_gaussians: null,
136137
channels: null,
137138
blend_mode: 'composite',
@@ -733,6 +734,7 @@ const ViewerView = widgets.DOMWidgetView.extend({
733734
if (rendered_image) {
734735
this.shadow_changed()
735736
this.gradient_opacity_changed()
737+
this.sample_distance_changed()
736738
this.channels_changed()
737739
this.blend_mode_changed()
738740
}
@@ -1010,6 +1012,16 @@ const ViewerView = widgets.DOMWidgetView.extend({
10101012
this.model.itkVtkViewer.on('gradientOpacityChanged',
10111013
onGradientOpacityChange
10121014
)
1015+
1016+
const onVolumeSampleDistanceChange = (distance) => {
1017+
if (distance !== this.model.get('sample_distance')) {
1018+
this.model.set('sample_distance', distance)
1019+
this.model.save_changes()
1020+
}
1021+
}
1022+
this.model.itkVtkViewer.on('volumeSampleDistanceChanged',
1023+
onVolumeSampleDistanceChange
1024+
)
10131025
} // end use2D
10141026

10151027
const onCameraChanged = macro.throttle(() => {
@@ -1080,6 +1092,11 @@ const ViewerView = widgets.DOMWidgetView.extend({
10801092
this.gradient_opacity_changed,
10811093
this
10821094
)
1095+
this.model.on(
1096+
'change:sample_distance',
1097+
this.sample_distance_changed,
1098+
this
1099+
)
10831100
this.model.on('change:blend_mode', this.blend_mode_changed, this)
10841101
this.model.on('change:select_roi', this.select_roi_changed, this)
10851102
this.model.on('change:_scale_factors', this.scale_factors_changed, this)
@@ -1583,6 +1600,13 @@ const ViewerView = widgets.DOMWidgetView.extend({
15831600
}
15841601
},
15851602

1603+
sample_distance_changed: function () {
1604+
const sample_distance = this.model.get('sample_distance')
1605+
if (this.model.hasOwnProperty('itkVtkViewer') && !this.model.use2D) {
1606+
this.model.itkVtkViewer.setVolumeSampleDistance(sample_distance)
1607+
}
1608+
},
1609+
15861610
opacity_gaussians_changed: function () {
15871611
const opacity_gaussians = this.model.get('opacity_gaussians')
15881612
if (this.model.hasOwnProperty('itkVtkViewer') && !this.model.use2D) {

0 commit comments

Comments
 (0)