Skip to content

Commit

Permalink
ENH: Add sample_distance trait
Browse files Browse the repository at this point in the history
  • Loading branch information
thewtex committed Jun 19, 2020
1 parent 93a6b74 commit 3fb9570
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
7 changes: 7 additions & 0 deletions itkwidgets/widget_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,8 @@ class Viewer(ViewerParent):
help="Size limit for 2D image visualization.").tag(sync=False)
size_limit_3d = NDArray(dtype=np.int64, default_value=np.array([192, 192, 192], dtype=np.int64),
help="Size limit for 3D image visualization.").tag(sync=False)
sample_distance = CFloat(default_value=0.25,
help="Normalized volume rendering sample distance.").tag(sync=True)
_scale_factors = NDArray(dtype=np.uint8, default_value=np.array([1, 1, 1], dtype=np.uint8),
help="Image downscaling factors.").tag(sync=True, **array_serialization)
_downsampling = CBool(default_value=False,
Expand Down Expand Up @@ -906,6 +908,11 @@ def view(image=None, # noqa: C901
Size limit for 3D image visualization. If the roi is larger than this
size, it will be downsampled for visualization.
sample_distance: float, default: 0.25
Sampling distance for volume rendering, normalized from 0.0 to 1.0.
Lower values result in a higher quality rendering. High values improve
the framerate.
Returns
-------
viewer : ipywidget
Expand Down
24 changes: 24 additions & 0 deletions js/lib/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ const ViewerModel = widgets.DOMWidgetModel.extend(
z_slice: null,
clicked_slice_point: null,
gradient_opacity: 0.2,
sample_distance: 0.25,
opacity_gaussians: null,
channels: null,
blend_mode: 'composite',
Expand Down Expand Up @@ -733,6 +734,7 @@ const ViewerView = widgets.DOMWidgetView.extend({
if (rendered_image) {
this.shadow_changed()
this.gradient_opacity_changed()
this.sample_distance_changed()
this.channels_changed()
this.blend_mode_changed()
}
Expand Down Expand Up @@ -1010,6 +1012,16 @@ const ViewerView = widgets.DOMWidgetView.extend({
this.model.itkVtkViewer.on('gradientOpacityChanged',
onGradientOpacityChange
)

const onVolumeSampleDistanceChange = (distance) => {
if (distance !== this.model.get('sample_distance')) {
this.model.set('sample_distance', distance)
this.model.save_changes()
}
}
this.model.itkVtkViewer.on('volumeSampleDistanceChanged',
onVolumeSampleDistanceChange
)
} // end use2D

const onCameraChanged = macro.throttle(() => {
Expand Down Expand Up @@ -1080,6 +1092,11 @@ const ViewerView = widgets.DOMWidgetView.extend({
this.gradient_opacity_changed,
this
)
this.model.on(
'change:sample_distance',
this.sample_distance_changed,
this
)
this.model.on('change:blend_mode', this.blend_mode_changed, this)
this.model.on('change:select_roi', this.select_roi_changed, this)
this.model.on('change:_scale_factors', this.scale_factors_changed, this)
Expand Down Expand Up @@ -1583,6 +1600,13 @@ const ViewerView = widgets.DOMWidgetView.extend({
}
},

sample_distance_changed: function () {
const sample_distance = this.model.get('sample_distance')
if (this.model.hasOwnProperty('itkVtkViewer') && !this.model.use2D) {
this.model.itkVtkViewer.setVolumeSampleDistance(sample_distance)
}
},

opacity_gaussians_changed: function () {
const opacity_gaussians = this.model.get('opacity_gaussians')
if (this.model.hasOwnProperty('itkVtkViewer') && !this.model.use2D) {
Expand Down

0 comments on commit 3fb9570

Please sign in to comment.