Skip to content

Commit

Permalink
[VTKVolume] add option to expand the controller (#1631)
Browse files Browse the repository at this point in the history
* [VTKVolume] add option to exapand the controller

* add bidirectionnal connection
  • Loading branch information
xavArtley authored Oct 14, 2020
1 parent 003e8dd commit d4f5b15
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 29 deletions.
2 changes: 2 additions & 0 deletions examples/reference/panes/VTKVolume.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
"\n",
"* **``camera``** (dict): A dictionary reflecting the current state of the VTK camera\n",
"\n",
"* **``controller_expanded``** (bool): A boolean to expand/collapse the volume controller panel in the view. If True the controller is expanded else it is collapsed\n",
"\n",
"* **``orientation_widget``** (bool): A boolean to activate/deactivate the orientation widget in the 3D pane. This widget is clickable and allows to rotate the scene in one of the orthographic projections.\n",
"\n",
"* **``colormap``** (string): Name of the colormap used to transform pixel value in color. All allowed colormaps are referenced in `PRESET_CMAPS` in `panel.pane.vtk.enums`. By default the value is 'erdc_rainbow_bright'\n",
Expand Down
3 changes: 3 additions & 0 deletions panel/models/vtk.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ class VTKVolumePlot(AbstractVTKPlot):

colormap = String(help="Colormap Name")

controller_expanded = Bool(default=True, help="""
If True the volume controller panel options is expanded in the view""")

data = Dict(String, Any)

diffuse = Float(default=0.7)
Expand Down
66 changes: 38 additions & 28 deletions panel/models/vtk/vtkvolume.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,19 @@ export class VTKVolumePlotView extends AbstractVTKView {
this._vtk_renwin.getRenderWindow().render()
})
this.connect(this.model.properties.slice_i.change, () => {
if(this.image_actor_i !== undefined){
if (this.image_actor_i !== undefined) {
this.image_actor_i.getMapper().setISlice(this.model.slice_i)
this._vtk_renwin.getRenderWindow().render()
}
})
this.connect(this.model.properties.slice_j.change, () => {
if(this.image_actor_j !== undefined){
if (this.image_actor_j !== undefined) {
this.image_actor_j.getMapper().setJSlice(this.model.slice_j)
this._vtk_renwin.getRenderWindow().render()
}
})
this.connect(this.model.properties.slice_k.change, () => {
if(this.image_actor_k !== undefined){
if (this.image_actor_k !== undefined) {
this.image_actor_k.getMapper().setKSlice(this.model.slice_k)
this._vtk_renwin.getRenderWindow().render()
}
Expand All @@ -98,24 +98,27 @@ export class VTKVolumePlotView extends AbstractVTKView {
this._set_interpolation(this.model.interpolation)
this._vtk_renwin.getRenderWindow().render()
})
this.connect(this.model.properties.controller_expanded.change, () => {
if (this._controllerWidget != null)
this._controllerWidget.setExpanded(this.model.controller_expanded)
})
}

render(): void {
this._vtk_renwin = null
this._orientationWidget = null
this._axes = null
super.render()
this._create_orientation_widget()
this._set_axes()
if (!this.model.camera)
this._vtk_renwin.getRenderer().resetCamera()
if (!this.model.camera) this._vtk_renwin.getRenderer().resetCamera()
}

invalidate_render(): void {
this._vtk_renwin = null
super.invalidate_render()
}

init_vtk_renwin(): void {
this._vtk_renwin = vtkns.FullScreenRenderWindow.newInstance({
rootContainer: this.el,
Expand All @@ -136,6 +139,7 @@ export class VTKVolumePlotView extends AbstractVTKView {
true
)
this._controllerWidget.setContainer(this.el)
this._controllerWidget.setExpanded(this.model.controller_expanded)
this._connect_js_controls()
this._vtk_renwin.getRenderWindow().getInteractor()
this._vtk_renwin.getRenderWindow().getInteractor().setDesiredUpdateRate(45)
Expand Down Expand Up @@ -186,14 +190,19 @@ export class VTKVolumePlotView extends AbstractVTKView {
}

_connect_js_controls(): void {
const {el: controller_el} = this._controllerWidget.get('el')
if(controller_el !== undefined) {
const controller_button = (controller_el as HTMLElement).querySelector('.js-button')
controller_button!.addEventListener('click', () => this.model.controller_expanded = this._controllerWidget.getExpanded())
}
// Colormap selector
this.colormap_selector.addEventListener("change", () => {
this.model.colormap = this.colormap_selector.value
})
if (!this.model.colormap) this.model.colormap = this.colormap_selector.value
else this.model.properties.colormap.change.emit()

// Shadow selector
// Shadow selector
this.shadow_selector.addEventListener("change", () => {
this.model.shadow = !!Number(this.shadow_selector.value)
})
Expand Down Expand Up @@ -351,11 +360,10 @@ export class VTKVolumePlotView extends AbstractVTKView {
.getActors()
.map((actor: any) => actor.setVisibility(visibility))
}

_set_volume_visibility(visibility: boolean): void {
this.volume.setVisibility(visibility)
}

}

export namespace VTKVolumePlot {
Expand All @@ -378,6 +386,7 @@ export namespace VTKVolumePlot {
slice_k: p.Property<number>
specular: p.Property<number>
specular_power: p.Property<number>
controller_expanded: p.Property<boolean>
}
}

Expand All @@ -394,24 +403,25 @@ export class VTKVolumePlot extends AbstractVTKPlot {
this.prototype.default_view = VTKVolumePlotView

this.define<VTKVolumePlot.Props>({
ambient: [ p.Number, 0.2 ],
colormap: [ p.String ],
data: [ p.Instance ],
diffuse: [ p.Number, 0.7 ],
display_slices: [ p.Boolean, false ],
display_volume: [ p.Boolean, true ],
edge_gradient: [ p.Number, 0.2 ],
interpolation: [ p.Any, 'fast_linear'],
mapper: [ p.Instance ],
render_background: [ p.String, '#52576e' ],
rescale: [ p.Boolean, false ],
sampling: [ p.Number, 0.4 ],
shadow: [ p.Boolean, true ],
slice_i: [ p.Int, 0 ],
slice_j: [ p.Int, 0 ],
slice_k: [ p.Int, 0 ],
specular: [ p.Number, 0.3 ],
specular_power: [ p.Number, 8.0 ],
ambient: [ p.Number, 0.2 ],
colormap: [ p.String ],
data: [ p.Instance ],
diffuse: [ p.Number, 0.7 ],
display_slices: [ p.Boolean, false ],
display_volume: [ p.Boolean, true ],
edge_gradient: [ p.Number, 0.2 ],
interpolation: [ p.Any, 'fast_linear'],
mapper: [ p.Instance ],
render_background: [ p.String, '#52576e' ],
rescale: [ p.Boolean, false ],
sampling: [ p.Number, 0.4 ],
shadow: [ p.Boolean, true ],
slice_i: [ p.Int, 0 ],
slice_j: [ p.Int, 0 ],
slice_k: [ p.Int, 0 ],
specular: [ p.Number, 0.3 ],
specular_power: [ p.Number, 8.0 ],
controller_expanded: [ p.Boolean, true ],
})
}
}
5 changes: 4 additions & 1 deletion panel/pane/vtk/vtk.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,9 @@ class VTKVolume(AbstractVTK):
object gives even in the absence of strong light. It is
constant in all directions.""")

controller_expanded = param.Boolean(default=True, doc="""
If True the volume controller panel options is expanded in the view""")

colormap = param.Selector(default='erdc_rainbow_bright', objects=PRESET_CMAPS, doc="""
Name of the colormap used to transform pixel value in color.""")

Expand Down Expand Up @@ -643,7 +646,7 @@ def _get_model(self, doc, root=None, parent=None, comm=None):
**props)
if root is None:
root = model
self._link_props(model, ['colormap', 'orientation_widget', 'camera', 'mapper'], doc, root, comm)
self._link_props(model, ['colormap', 'orientation_widget', 'camera', 'mapper', 'controller_expanded'], doc, root, comm)
self._models[root.ref['id']] = (model, parent)
return model

Expand Down

0 comments on commit d4f5b15

Please sign in to comment.