Skip to content

Commit

Permalink
docs(example): fix plane and box
Browse files Browse the repository at this point in the history
  • Loading branch information
jourdain committed Aug 26, 2024
1 parent 8e66961 commit 0d0cd02
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
24 changes: 14 additions & 10 deletions examples/vtk/widgets_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

from vtkmodules.vtkCommonColor import vtkNamedColors
from vtkmodules.vtkFiltersSources import vtkConeSource
from vtkmodules.vtkInteractionWidgets import vtkBoxWidget
from vtkmodules.vtkInteractionWidgets import vtkBoxWidget2
from vtkmodules.vtkCommonTransforms import vtkTransform
from vtkmodules.vtkRenderingCore import (
vtkActor,
Expand All @@ -23,10 +23,10 @@
WASM = "USE_WASM" in os.environ


def boxCallback(obj, event):
def box_callback(obj, event):
t = vtkTransform()
obj.GetTransform(t)
obj.GetProp3D().SetUserTransform(t)
obj.representation.GetTransform(t)
box_callback.actor.user_transform = t


def create_vtk_pipeline():
Expand All @@ -40,6 +40,7 @@ def create_vtk_pipeline():
coneActor = vtkActor()
coneActor.SetMapper(coneMapper)
coneActor.GetProperty().SetColor(colors.GetColor3d("BurlyWood"))
coneMapper.Update()

# A renderer and render window
renderer = vtkRenderer()
Expand All @@ -56,16 +57,17 @@ def create_vtk_pipeline():
interactor.GetInteractorStyle().SetCurrentStyleToTrackballCamera()

# A Box widget
boxWidget = vtkBoxWidget()
boxWidget = vtkBoxWidget2()
boxWidget.SetInteractor(interactor)
boxWidget.SetProp3D(coneActor)
boxWidget.SetPlaceFactor(1.25) # Make the box 1.25x larger than the actor
boxWidget.PlaceWidget()
boxWidget.representation.SetPlaceFactor(1.0)
boxWidget.representation.PlaceWidget(coneActor.bounds)

boxWidget.On()

# Connect the event to a function
if not WASM:
boxWidget.AddObserver("InteractionEvent", boxCallback)
box_callback.actor = coneActor
boxWidget.AddObserver("InteractionEvent", box_callback)

return renwin, boxWidget

Expand Down Expand Up @@ -96,7 +98,9 @@ def _ui(self):
self.html_view = vtklocal.LocalView(self.render_window)
self.html_view.register_widget(self.widget)
else:
self.html_view = vtk_widgets.VtkRemoteView(self.render_window)
self.html_view = vtk_widgets.VtkRemoteView(
self.render_window, interactive_ratio=1
)

return layout

Expand Down
1 change: 1 addition & 0 deletions examples/vtk/widgets_plane.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ def _ui(self):
):
if WASM:
self.html_view = vtklocal.LocalView(self.render_window)
self.html_view.register_widget(self.widget)
else:
self.html_view = vtk_widgets.VtkRemoteView(self.render_window)

Expand Down

0 comments on commit 0d0cd02

Please sign in to comment.