[vtkusers] Adding observer for QVTKWidget's InteractorStyle ?

Alex Malyushytskyy alexmalvtk at gmail.com
Fri Dec 2 22:00:48 EST 2011


> 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 ?

QVTKInteractor is derived from  vtkRenderWindowInteractor:

QVTKInteractor : public QObject, public vtkRenderWindowInteractor


It means it has at least ALL the methods of vtkRenderWindowInteractor + QObject

I have working code in my C++program which adds observer as:

		iren->AddObserver(vtkCommand::CharEvent,
					  this->EventCallbackCommand,
					  this->Priority);


where

vtkRenderWindowInteractor *iren ...

iren =  this->GetRenderWindow()->GetInteractor();

so I guess your script should work as

 self.window.iren.GetInteractor().AddObserver(....)

Regards,
    Alex


On Fri, Dec 2, 2011 at 5:49 AM, chasank <chasank at gmail.com> wrote:
> 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.
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers



More information about the vtkusers mailing list