[vtkusers] Adding observer for QVTKWidget's InteractorStyle ?
chasank
chasank at gmail.com
Fri Dec 2 08:49:24 EST 2011
Hi all,
I've binded a vtkImageViewer2 object inside of a QVTKWidget to visualize
medical planes of DICOM datasets. I want to show color level and color
window values whenever user releases right mouse button over QVTKWidget
window. The code below (without Qt) works perfectly
------------------------------------------------------------------
from vtk import *
reader = vtkDICOMImageReader()
reader.SetDirectoryName("C:\\DICOM\\CT\\PHENIX\\COU IV")
reader.Update()
sagittalViewer = vtkImageViewer2()
sagittalViewer.SetInputConnection(reader.GetOutputPort())
sagittalViewer.SetSize(640, 480)
sagittalViewer.SetSliceOrientationToYZ()
maxSaggital = sagittalViewer.GetSliceMax()
sagittalViewer.SetSlice( maxSaggital / 2)
iren = vtk.vtkRenderWindowInteractor()
sagittalViewer.SetupInteractor(iren)
sagittalViewer.SetColorLevel(127.0)
sagittalViewer.SetColorWindow(255.0)
renderer = sagittalViewer.GetRenderer()
camera = renderer.GetActiveCamera()
camera.SetViewUp(0, 0, -1)
camera.SetPosition(1, 0, 0)
camera.SetFocalPoint(0, 0, 0)
camera.ComputeViewPlaneNormal()
renderer.ResetCamera()
renderer.Render()
def LeftButtonReleaseCallback(obj, event):
window = sagittalViewer.GetColorWindow()
level = sagittalViewer.GetColorLevel()
print str("W:" + str(window) + ", L:" + str(level))
iren.GetInteractorStyle().OnLeftButtonUp()
iren.GetInteractorStyle().AddObserver("LeftButtonReleaseEvent",
LeftButtonReleaseCallback)
iren.Initialize()
iren.Start()
-------------------------------------------------------------------------
However when I try it for QVTKWidget
-------------------------------------------------------------------------
self.window.iren =
self.window.sagittalWidget.GetRenderWindow().GetInteractor()
self.window.iren.GetInteractorStyle().AddObserver("LeftButtonReleaseEvent",
self.window.LeftButtonReleaseCallback)
-------------------------------------------------------------------------
gives that error;
-------------------------------------------------------------------------
self.window.iren.GetInteractorStyle().AddObserver("LeftButtonReleaseEvent",
self.window.LeftButtonReleaseCallback)
AttributeError: GetInteractorStyle
-------------------------------------------------------------------------
When I make type checking;
-------------------------------------------------------------------------
iren = self.window.sagittalWidget.GetRenderWindow().GetInteractor()
if isinstance(iren, vtkRenderWindowInteractor):
print "iren is vtkRenderWindowInteractor instance"
else:
print "iren is " + iren.GetClassName() + " instance"
-------------------------------------------------------------------------
it prints the "iren is QVTKInteractor instance" QVTKInteractor does not have
any of methods of vtkRenderWindowInteractor class. How can I add an observer
for InteractorStyle of QVTKInteractor ?
Any ideas ?
--
View this message in context: http://vtk.1045678.n5.nabble.com/Adding-observer-for-QVTKWidget-s-InteractorStyle-tp5041876p5041876.html
Sent from the VTK - Users mailing list archive at Nabble.com.
More information about the vtkusers
mailing list