You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When running, the custom code in MouseInteractorHighLightActor.onLeftButtonDown never executes, so the functionality does not work and there are no debug prints.
Code
#!/usr/bin/env python# noinspection PyUnresolvedReferencesimportvtkmodules.vtkRenderingOpenGL2fromvtkmodules.vtkCommonColorimportvtkNamedColorsfromvtkmodules.vtkCommonCoreimportvtkMinimalStandardRandomSequencefromvtkmodules.vtkFiltersHybridimportvtkPolyDataSilhouettefromvtkmodules.vtkFiltersSourcesimportvtkSphereSourcefromvtkmodules.vtkInteractionStyleimportvtkInteractorStyleTrackballCamerafromvtkmodules.vtkRenderingCoreimport (
vtkActor,
vtkPolyDataMapper,
vtkPropPicker,
vtkRenderWindow,
vtkRenderWindowInteractor,
vtkRenderer
)
fromtrame.appimportget_serverfromtrame.ui.vuetifyimportSinglePageLayoutfromtrame.widgetsimportvtk, vuetifydefget_program_parameters():
importargparsedescription='Highlighting a selected object with a silhouette.'epilogue='''Click on the object to highlight it.The selected object is highlighted with a silhouette. '''parser=argparse.ArgumentParser(description=description, epilog=epilogue,
formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument('numberOfSpheres', nargs='?', type=int, default=10,
help='The number of spheres, default is 10.')
args=parser.parse_args()
returnargs.numberOfSpheresclassMouseInteractorHighLightActor(vtkInteractorStyleTrackballCamera):
def__init__(self, silhouette=None, silhouetteActor=None):
self.AddObserver("LeftButtonPressEvent", self.onLeftButtonDown)
self.LastPickedActor=Noneself.Silhouette=silhouetteself.SilhouetteActor=silhouetteActordefonLeftButtonDown(self, obj, event):
print("In onLeftButtonDown")
clickPos=self.GetInteractor().GetEventPosition()
# Pick from this location.picker=vtkPropPicker()
picker.Pick(clickPos[0], clickPos[1], 0, self.GetDefaultRenderer())
self.LastPickedActor=picker.GetActor()
# If we picked something before, remove the silhouette actor and# generate a new one.ifself.LastPickedActor:
print(f"You picked: {self.LastPickedActor}")
self.GetDefaultRenderer().RemoveActor(self.SilhouetteActor)
# Highlight the picked actor by generating a silhouetteself.Silhouette.SetInputData(self.LastPickedActor.GetMapper().GetInput())
self.GetDefaultRenderer().AddActor(self.SilhouetteActor)
else:
print("Nothing picked")
# Forward eventsself.OnLeftButtonDown()
returndefSetSilhouette(self, silhouette):
self.Silhouette=silhouettedefSetSilhouetteActor(self, silhouetteActor):
self.SilhouetteActor=silhouetteActordefmain():
numberOfSpheres=get_program_parameters()
colors=vtkNamedColors()
# A renderer and render windowrenderer=vtkRenderer()
renderer.SetBackground(colors.GetColor3d('SteelBlue'))
renderWindow=vtkRenderWindow()
renderWindow.SetSize(640, 480)
renderWindow.AddRenderer(renderer)
# An interactorinteractor=vtkRenderWindowInteractor()
interactor.SetRenderWindow(renderWindow)
randomSequence=vtkMinimalStandardRandomSequence()
# randomSequence.SetSeed(1043618065)# randomSequence.SetSeed(5170)randomSequence.SetSeed(8775070)
# Add spheres to play withforiinrange(numberOfSpheres):
source=vtkSphereSource()
# random position and radiusx=randomSequence.GetRangeValue(-5.0, 5.0)
randomSequence.Next()
y=randomSequence.GetRangeValue(-5.0, 5.0)
randomSequence.Next()
z=randomSequence.GetRangeValue(-5.0, 5.0)
randomSequence.Next()
radius=randomSequence.GetRangeValue(0.5, 1.0)
randomSequence.Next()
source.SetRadius(radius)
source.SetCenter(x, y, z)
source.SetPhiResolution(11)
source.SetThetaResolution(21)
mapper=vtkPolyDataMapper()
mapper.SetInputConnection(source.GetOutputPort())
actor=vtkActor()
actor.SetMapper(mapper)
r=randomSequence.GetRangeValue(0.4, 1.0)
randomSequence.Next()
g=randomSequence.GetRangeValue(0.4, 1.0)
randomSequence.Next()
b=randomSequence.GetRangeValue(0.4, 1.0)
randomSequence.Next()
actor.GetProperty().SetDiffuseColor(r, g, b)
actor.GetProperty().SetDiffuse(0.8)
actor.GetProperty().SetSpecular(0.5)
actor.GetProperty().SetSpecularColor(colors.GetColor3d('White'))
actor.GetProperty().SetSpecularPower(30.0)
renderer.AddActor(actor)
renderer.ResetCamera()
# Create the silhouette pipeline, the input data will be set in the# interactorsilhouette=vtkPolyDataSilhouette()
silhouette.SetCamera(renderer.GetActiveCamera())
# Create mapper and actor for silhouettesilhouetteMapper=vtkPolyDataMapper()
silhouetteMapper.SetInputConnection(silhouette.GetOutputPort())
silhouetteActor=vtkActor()
silhouetteActor.SetMapper(silhouetteMapper)
silhouetteActor.GetProperty().SetColor(colors.GetColor3d("Tomato"))
silhouetteActor.GetProperty().SetLineWidth(5)
# Set the custom type to use for interaction.style=MouseInteractorHighLightActor(silhouette, silhouetteActor)
style.SetDefaultRenderer(renderer)
interactor.SetInteractorStyle(style)
server=get_server(client_type="vue2")
ctrl=server.controllerwithSinglePageLayout(server) aslayout:
layout.title.set_text("Hello trame")
withlayout.content:
withvuetify.VContainer(
fluid=True,
classes="pa-0 fill-height",
):
view=vtk.VtkLocalView(renderWindow)
server.start()
if__name__=="__main__":
main()
Expected behavior
The MouseInteractorHighLightActor sublcass should work like it does in the VTK example linked.
Platform:
I've checked only the following, but I imagine the bug is on all platforms.
Device:
Desktop
Mobile
OS:
Windows
MacOS
Linux
Android
iOS
Browsers Affected:
Chrome
Firefox
Microsoft Edge
Safari
Opera
Brave
IE 11
The text was updated successfully, but these errors were encountered:
VtkLocalView has its own set of interactors that don't match the server. You can see how to configure it here. Also even the VtkRemoteView don't match all the clients events. Some efforts have been made in trame-rca (remote-controlled-area) to properly propagate to the server those events so custom interactors could be used.
Describe the bug
Trying to use
SetInteractorStyle
always seems to fail, I always getvtkInteractorStyleTrackballCamera
. Specifically I can't use a custom subclass.To Reproduce
The script below was taken from https://examples.vtk.org/site/Python/Picking/HighlightWithSilhouette/ with minimal adaptation for trame.
When running, the custom code in
MouseInteractorHighLightActor.onLeftButtonDown
never executes, so the functionality does not work and there are no debug prints.Code
Expected behavior
The
MouseInteractorHighLightActor
sublcass should work like it does in the VTK example linked.Platform:
I've checked only the following, but I imagine the bug is on all platforms.
Device:
OS:
Browsers Affected:
The text was updated successfully, but these errors were encountered: