I’m trying to re-create the vtk example in the following link:
The example hovers over the actors and presents a balloon label. I would like to add this feature in some way to my vtk mesh. However the below does not allow me to interact with the mesh when it renders in the browser window - it only seems to work in a separate vtk window. Any help or advice trying to achieve a hover info feature on vtk in panel would be much appreciated.
import pyvista as pv import panel as pn import numpy as np import vtk pn.extension('vtk') # This creates a polygonal cylinder model with eight circumferential # facets. cylinder = vtk.vtkCylinderSource() cylinder.SetResolution(8) # The mapper is responsible for pushing the geometry into the graphics # library. It may also do color mapping, if scalars or other # attributes are defined. cylinderMapper = vtk.vtkPolyDataMapper() cylinderMapper.SetInputConnection(cylinder.GetOutputPort()) # The actor is a grouping mechanism: besides the geometry (mapper), it # also has a property, transformation matrix, and/or texture map. # Here we set its color and rotate it -22.5 degrees. cylinderActor = vtk.vtkActor() cylinderActor.SetMapper(cylinderMapper) # cylinderActor.GetProperty().SetColor(tomato) # We must set ScalarVisibilty to 0 to use tomato Color cylinderMapper.SetScalarVisibility(0) cylinderActor.RotateX(30.0) cylinderActor.RotateY(-45.0) # Create the graphics structure. The renderer renders into the render # window. ren = vtk.vtkRenderer() renWin = vtk.vtkRenderWindow() renWin.AddRenderer(ren) renderWindowInteractor = vtk.vtkRenderWindowInteractor() renderWindowInteractor.SetRenderWindow(renWin) geom_pane = pn.pane.VTK(renWin, width=500, height=500) # Add the actors to the renderer, set the background and size ren.AddActor(cylinderActor) ren.SetBackground(0.1, 0.2, 0.4) balloonRep = vtk.vtkBalloonRepresentation() balloonRep.SetBalloonLayoutToImageRight() balloonWidget = vtk.vtkBalloonWidget() balloonWidget.SetInteractor(renWin.GetInteractor()) balloonWidget.SetRepresentation(balloonRep) balloonWidget.AddBalloon(cylinderActor, "This is a sphere") balloonWidget.EnabledOn() # Begin mouse interaction # renderWindowInteractor.Start() # renderWindowInteractor.Initialize() geom_pane.show()