Hi,
I posted this in support last week but with no luck. I am re-posting here as this is a potential bug based on differing results on Linux/Mac and with and without PyQt rendering.
I have trouble with vtkImageTracerWidget on Mac. The code below shows an image (zeros) and a vtkImageTracerWidget is active on to (so you can draw an outline). This works on Linux, but on Mac the ImagetracerWidget appears to not receive the mouse events and the mouse just adjusts window level in the image as if the ImageTracerWidget was not enabled.
It may be related to PyQt since it does work for Mac without Qt - using just vtk.vtkRenderWindow().
I was hoping that someone would have an idea of how to troubleshoot further!
Thanks!
Soren
#!/usr/bin/env python3
import vtk
import numpy as np
from PyQt5.QtWidgets import QApplication, QMainWindow, QFrame, QVBoxLayout
import sys
from vtk.qt.QVTKRenderWindowInteractor import QVTKRenderWindowInteractor
from vtk.util import numpy_support
class MainWindow(QMainWindow):
def __init__(self, parent=None):
QMainWindow.__init__(self, parent)
self.frame = QFrame()
self.vl = QVBoxLayout()
self.vtkWidget = QVTKRenderWindowInteractor(self)
self.vl.addWidget(self.vtkWidget)
self.frame.setLayout(self.vl)
self.setCentralWidget(self.frame)
self.ren = vtk.vtkRenderer()
self.ren.SetBackground(0., .0, 1)
self.ren.GetActiveCamera().SetPosition(0, 0, 1)
self.ren.GetActiveCamera().SetViewUp(0, 1, 0)
self.vtkWidget.GetRenderWindow().AddRenderer(self.ren)
self.iren = self.vtkWidget.GetRenderWindow().GetInteractor()
style = vtk.vtkInteractorStyleImage()
style.SetInteractionModeToImage3D()
self.iren.SetInteractorStyle(style)
self.imageVTK = vtk.vtkImageData()
self.imageactor = vtk.vtkImageActor()
self.imageactor.SetInputData(self.imageVTK)
#
self.imageVTK.SetOrigin((0, 0, 0))
self.imageVTK.SetSpacing(1, 1, 1)
rgb_data=np.zeros((256,256,3),np.uint8)
self.imageVTK.SetDimensions((rgb_data.shape[1], rgb_data.shape[0], 1))
self.montage_VTKdata = numpy_support.numpy_to_vtk(num_array=np.flip(rgb_data, axis=0).ravel(),
deep=True)
self.montage_VTKdata.SetNumberOfComponents(3)
self.imageVTK.GetPointData().SetScalars(self.montage_VTKdata)
self.ren.AddActor(self.imageactor)
self.tracer = vtk.vtkImageTracerWidget()
self.tracer.GetLineProperty().SetLineWidth(1)
self.tracer.GetGlyphSource().SetRotationAngle(45.0)
self.tracer.GetGlyphSource().SetScale(3.0)
self.tracer.GetGlyphSource().Modified()
self.tracer.SetViewProp(self.imageactor)
self.tracer.SetCaptureRadius(15.0)
self.tracer.SetInputData(self.imageVTK)
self.tracer.ProjectToPlaneOn()
self.tracer.SnapToImageOff()
self.tracer.AutoCloseOn()
self.tracer.SetInteractor(self.iren)
self.tracer.PlaceWidget()
self.tracer.On()
self.imageactor.Update()
self.ren.ResetCamera()
self.show()
self.iren.Initialize()
self.iren.Start()
if __name__ == "__main__":
app = QApplication(sys.argv)
window = MainWindow()
sys.exit(app.exec_())