4

I working on a PySide/vtk GUI using QVTKRenderWindowInteractor widget class. The widget is working well, unless when I try to add a orientation axis (see image) using vtkOrientationMarkerWidget:

axesActor = vtk.vtkAxesActor();
axes = vtk.vtkOrientationMarkerWidget()
axes.SetOrientationMarker(axesActor)
axes.SetInteractor(self.iren)
self.ren.AddActor(axesActor)
axes.EnabledOn() # <== application freeze-crash
axes.InteractiveOn()

A similar bug has been already reported for ubuntu, showing that the bug is reproduced only with Qt example, while the same example without Qt works well.

Any solution to this behavior ? enter image description here

SAAD
  • 759
  • 1
  • 9
  • 23

1 Answers1

6

Got this answer from Nicholas R. Rypkema :

https://nrr.mit.edu/blog/note-about-vtk-pyqt-and-vtkorientationmarkerwidget

Long story short : this will fix your problem

axesActor = vtk.vtkAxesActor();
self.axes = vtk.vtkOrientationMarkerWidget()
self.axes.SetOrientationMarker(axesActor)
self.axes.SetInteractor(self.iren)
self.ren.AddActor(axesActor)
self.axes.EnabledOn() # <== application freeze-crash
self.axes.InteractiveOn()
GiantCupcake
  • 76
  • 1
  • 2
  • You should add the essential part from the off-site resource to your answer. Also your code snippet is copypasta from OP's post. – m02ph3u5 Jun 22 '17 at 13:59
  • 2
    Thanks, this worked for me! The key is to prevent axes to go out of scope by making it a class member (self.axes). – mululu Jul 07 '17 at 08:26
  • 1
    This solves the problem, as @mululu said, by changing the lifetime of the `vtkOrientationMarkerWidget` instance, by making it a member of the main application class (which subclasses `QtGui.QMainWindow`) where `QVTKRenderWindowInteractor` is defined. Answer accepted ! – SAAD Jul 26 '17 at 13:50
  • I report that this solution also works for solving the same bug when using VTK in C++, i.e. a variable of type vtkSmartPointer should be made a member of a class that lives for the duration of the VTK loop execution. – Greg Kramida Jun 22 '18 at 19:29