Skip to content

Commit af9f43c

Browse files
authored
Merge pull request #333 from thewtex/sample-distance
ENH: Add sample_distance trait
2 parents 6d948c7 + 3fb9570 commit af9f43c

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
@@ -243,6 +243,8 @@ class Viewer(ViewerParent):
243243
help="Size limit for 2D image visualization.").tag(sync=False)
244244
size_limit_3d = NDArray(dtype=np.int64, default_value=np.array([192, 192, 192], dtype=np.int64),
245245
help="Size limit for 3D image visualization.").tag(sync=False)
246+
sample_distance = CFloat(default_value=0.25,
247+
help="Normalized volume rendering sample distance.").tag(sync=True)
246248
_scale_factors = NDArray(dtype=np.uint8, default_value=np.array([1, 1, 1], dtype=np.uint8),
247249
help="Image downscaling factors.").tag(sync=True, **array_serialization)
248250
_downsampling = CBool(default_value=False,
@@ -977,6 +979,11 @@ def view(image=None, # noqa: C901
977979
Size limit for 3D image visualization. If the roi is larger than this
978980
size, it will be downsampled for visualization.
979981
982+
sample_distance: float, default: 0.25
983+
Sampling distance for volume rendering, normalized from 0.0 to 1.0.
984+
Lower values result in a higher quality rendering. High values improve
985+
the framerate.
986+
980987
Returns
981988
-------
982989
viewer : ipywidget

js/lib/viewer.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ const ViewerModel = widgets.DOMWidgetModel.extend(
133133
z_slice: null,
134134
clicked_slice_point: null,
135135
gradient_opacity: 0.2,
136+
sample_distance: 0.25,
136137
opacity_gaussians: null,
137138
channels: null,
138139
blend_mode: 'composite',
@@ -737,6 +738,7 @@ const ViewerView = widgets.DOMWidgetView.extend({
737738
if (rendered_image) {
738739
this.shadow_changed()
739740
this.gradient_opacity_changed()
741+
this.sample_distance_changed()
740742
this.channels_changed()
741743
this.blend_mode_changed()
742744
}
@@ -1035,6 +1037,16 @@ const ViewerView = widgets.DOMWidgetView.extend({
10351037
this.model.itkVtkViewer.on('gradientOpacityChanged',
10361038
onGradientOpacityChange
10371039
)
1040+
1041+
const onVolumeSampleDistanceChange = (distance) => {
1042+
if (distance !== this.model.get('sample_distance')) {
1043+
this.model.set('sample_distance', distance)
1044+
this.model.save_changes()
1045+
}
1046+
}
1047+
this.model.itkVtkViewer.on('volumeSampleDistanceChanged',
1048+
onVolumeSampleDistanceChange
1049+
)
10381050
} // end use2D
10391051

10401052
const onCameraChanged = macro.throttle(() => {
@@ -1163,6 +1175,11 @@ const ViewerView = widgets.DOMWidgetView.extend({
11631175
this.gradient_opacity_changed,
11641176
this
11651177
)
1178+
this.model.on(
1179+
'change:sample_distance',
1180+
this.sample_distance_changed,
1181+
this
1182+
)
11661183
this.model.on('change:blend_mode', this.blend_mode_changed, this)
11671184
this.model.on('change:select_roi', this.select_roi_changed, this)
11681185
this.model.on('change:_scale_factors', this.scale_factors_changed, this)
@@ -1716,6 +1733,13 @@ const ViewerView = widgets.DOMWidgetView.extend({
17161733
}
17171734
},
17181735

1736+
sample_distance_changed: function () {
1737+
const sample_distance = this.model.get('sample_distance')
1738+
if (this.model.hasOwnProperty('itkVtkViewer') && !this.model.use2D) {
1739+
this.model.itkVtkViewer.setVolumeSampleDistance(sample_distance)
1740+
}
1741+
},
1742+
17191743
opacity_gaussians_changed: function () {
17201744
const opacity_gaussians = this.model.get('opacity_gaussians')
17211745
if (this.model.hasOwnProperty('itkVtkViewer') && !this.model.use2D) {

0 commit comments

Comments
 (0)