visualizer_widget_example.rst#
Visualizer Widgets¶
Visualizer widgets allow you to interactively explore a session as you would in a Vapor GUI visualizer. This notebook shows how to use visualizer widgets and how to add additional dynamic parameter inputs.
In [1]:
import example_utils
from vapor import session, renderer, dataset, camera
ses = session.Session()
data = example_utils.OpenExampleDataset(ses)
Warning: sysroot "/Applications/Xcode_12.4.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk" not found (ignoring for now).
Vapor 3.9.2 Python 3.9.19 (/Users/pearse/miniconda3/envs/readTheDocs) OpenGL 4.1 Metal - 83.1
Render an Iso Surface¶
In [2]:
ren = data.NewRenderer(renderer.VolumeIsoRenderer)
ren.SetVariableName(data.GetDataVarNames(3)[0]) # Set to first 2D data variable
ren.SetIsoValues([ren.GetIsoValues()[0]+0.1])
ses.GetCamera().ViewAll()
ses.Show()
UNSUPPORTED (log once): POSSIBLE ISSUE: unit 2 GLD_TEXTURE_INDEX_3D is unloadable and bound to sampler type (Float) - using zero texture because texture unloadable
Create a visualizer to explore the scene¶
Try dragging the image to rotate the view. Hover over the visualizer to see the full controls.
In [3]:
from jupyter_vapor_widget import *
viz = VaporVisualizerWidget(ses)
viz
Out[3]:
Add an interactive iso value slider using ipywidgets¶
In [4]:
tf = ren.GetPrimaryTransferFunction()
dataRange = tf.GetMinMaxMapValue()
def sliderChanged(change):
ren.SetIsoValues([change.new])
viz.Render(fast=True)
slider = widgets.FloatSlider(value=ren.GetIsoValues()[0], min=dataRange[0], max=dataRange[1], step=(dataRange[1]-dataRange[0])/100)
slider.observe(sliderChanged, names='value')
widgets.VBox([
viz,
widgets.HBox([widgets.Label("Iso value:"), slider])
])
Out[4]: