8000 Vtk/vtk improvements by xavArtley · Pull Request #2826 · holoviz/panel · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
nan opacity volume slices and update vtkjs
  • Loading branch information
xavArtley committed Oct 15, 2021
commit a9d309e5d00df3ff39d48b8179d24993b9b75c58
4 changes: 3 additions & 1 deletion panel/models/vtk.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from ..io.resources import bundled_files
from ..util import classproperty

vtk_cdn = "https://unpkg.com/vtk.js@14.16.4/dist/vtk.js"
vtk_cdn = "https://unpkg.com/vtk.js@20.0.1/vtk.js"

class VTKAxes(Model):
"""
Expand Down Expand Up @@ -135,6 +135,8 @@ class VTKVolumePlot(AbstractVTKPlot):

mapper = Dict(String, Any)

nan_opacity = Float(default=1)

render_background = String(default='#52576e')

rescale = Bool(default=False)
Expand Down
3 changes: 2 additions & 1 deletion panel/models/vtk/vtklayout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export abstract class AbstractVTKView extends PanelHTMLBoxView {

info_div.click()
}

_init_annotations_container(): void {
if (!this._annotations_container) {
this._annotations_container = document.createElement("div")
Expand Down Expand Up @@ -237,6 +237,7 @@ export abstract class AbstractVTKView extends PanelHTMLBoxView {
remove(): void {
this._unsubscribe_camera_cb()
window.removeEventListener("resize", this._vtk_renwin.resize)
this._vtk_renwin.getRenderWindow().getInteractor().delete()
this._vtk_renwin.delete()
super.remove()
}
Expand Down
24 changes: 18 additions & 6 deletions panel/models/vtk/vtkvolume.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ export class VTKVolumePlotView extends AbstractVTKView {
if (this._controllerWidget != null)
this._controllerWidget.setExpanded(this.model.controller_expanded)
})
this.connect(this.model.properties.nan_opacity.change, () => {
const scalar_opacity = this.image_actor_i.getProperty().getScalarOpacity()
scalar_opacity.get(["nodes"]).nodes[0].y = this.model.nan_opacity
scalar_opacity.modified()
this._vtk_renwin.getRenderWindow().render()
})
}

render(): void {
Expand Down Expand Up @@ -263,9 +269,14 @@ export class VTKVolumePlotView extends AbstractVTKView {

// set_color and opacity
const piecewiseFunction = vtkns.PiecewiseFunction.newInstance()
piecewiseFunction.removeAllPoints()
piecewiseFunction.addPoint(0, 1)
const lookupTable = this.volume.getProperty().getRGBTransferFunction(0)
const range = this.volume.getMapper().getInputData().getPointData().getScalars().getRange()
piecewiseFunction.removeAllPoints()
console.log(this.model.nan_opacity)
piecewiseFunction.addPoint(range[0]-1, this.model.nan_opacity)
piecewiseFunction.addPoint(range[0], 1)
piecewiseFunction.addPoint(range[1], 1)

const property = image_actor_i.getProperty()
image_actor_j.setProperty(property)
image_actor_k.setProperty(property)
Expand Down Expand Up @@ -360,10 +371,9 @@ export class VTKVolumePlotView extends AbstractVTKView {
}

_set_slices_visibility(visibility: boolean): void {
this._vtk_renwin
.getRenderer()
.getActors()
.map((actor: any) => actor.setVisibility(visibility))
this.image_actor_i.setVisibility(visibility)
this.image_actor_j.setVisibility(visibility)
this.image_actor_k.setVisibility(visibility)
}

_set_volume_visibility(visibility: boolean): void {
Expand All @@ -382,6 +392,7 @@ export namespace VTKVolumePlot {
edge_gradient: p.Property<number>
interpolation: p.Property<Interpolation>
mapper: p.Property<ColorMapper>
nan_opacity: p.Property<number>
render_background: p.Property<string>
rescale: p.Property<boolean>
sampling: p.Property<number>
Expand Down Expand Up @@ -417,6 +428,7 @@ export class VTKVolumePlot extends AbstractVTKPlot {
edge_gradient: [ Number, 0.2 ],
interpolation: [ Interpolation, 'fast_linear'],
mapper: [ Struct({palette: Array(String), low: Number, high: Number}) ],
nan_opacity: [ Number, 1 ],
render_background: [ String, '#52576e' ],
rescale: [ Boolean, false ],
sampling: [ Number, 0.4 ],
Expand Down
7 changes: 5 additions & 2 deletions panel/pane/vtk/vtk.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,9 @@ class VTKVolume(AbstractVTK):
max_data_size = param.Number(default=(256 ** 3) * 2 / 1e6, doc="""
Maximum data size transfert allowed without subsampling""")

nan_opacity = param.Number(default=1., bounds=(0., 1.), doc="""
Opacity applied to nan values in slices""")

origin = param.Tuple(default=None, length=3, allow_None=True)

render_background = param.Color(default='#52576e', doc="""
Expand Down Expand Up @@ -617,7 +620,7 @@ def _get_model(self, doc, root=None, parent=None, comm=None):
model = VTKVolumePlot(**props)
if root is None:
root = model
self._link_props(model, ['colormap', 'orientation_widget', 'camera', 'mapper', 'controller_expanded'], doc, root, comm)
self._link_props(model, ['colormap', 'orientation_widget', 'camera', 'mapper', 'controller_expanded', 'nan_opacity'], doc, root, comm)
self._models[root.ref['id']] = (model, parent)
return model

Expand Down Expand Up @@ -683,7 +686,7 @@ def _volume_from_array(self, sub_array):
dims=sub_array.shape,
spacing=self._sub_spacing,
origin=self.origin,
data_range=(sub_array.min(), sub_array.max()),
data_range=(np.nanmin(sub_array), np.nanmax(sub_array)),
dtype=sub_array.dtype.name)

def _get_volume_data(self):
Expand Down
0