[vtkusers] VTK interactor in PyQt

Lic. José M. Rodriguez Bacallao jmrbcu at gmail.com
Thu Nov 19 10:40:10 EST 2009


well using the original QVTKRenderWindowInteractor U need to know that
it does not support reparenting so U need to encapsulate the reactor
in another widget so U can use it with widgets that do reparenting
(QTabWidget, QMainWindow), also, I have noticed that for
QVTKRenderWindowInteractor to work, the widget showing the interactor
must be visible (widget,show()) in order to setup it correctly. This
are my observations and I don't know if they are 100% correct. Well,
here is an example of a single window:

# PyQt4 imports
from PyQt4 import QtGui, QtCore

# vtk imports
from vtk.qt4.QVTKRenderWindowInteractor import QVTKRenderWindowInteractor

class QVtkInteractorWidget(QtGui.QFrame):

   def __init__(self, parent = None):
       super(QVtkInteractorWidget, self).__init__(parent)
       self.setup_ui()

   def setup_ui(self):
       self.setAttribute(QtCore.Qt.WA_ForceUpdatesDisabled)
       self.setAttribute(QtCore.Qt.WA_PaintOnScreen)
       self.setFocusPolicy(QtCore.Qt.StrongFocus)

       self.vbox = QtGui.QVBoxLayout(self)
       self.vbox.setMargin(0)
       self.interactor = QVTKRenderWindowInteractor(self)
       self.vbox.addWidget(self.interactor)
       self.setLayout(self.vbox)


if __name__ == '__main__':
   import sys, vtk, vtkgdcm

   app = QtGui.QApplication(sys.argv)

   mw = QtGui.QMainWindow()
   iwidget = QVtkInteractorWidget(mw)
   mw.setCentralWidget(iwidget)
   mw.show()

   r = vtkgdcm.vtkGDCMImageReader()
   r.SetFileName(sys.argv[1])
   r.Update()

   v = vtk.vtkImageViewer2()
   v.SetupInteractor(iwidget.interactor)
   v.SetRenderWindow(iwidget.interactor.GetRenderWindow())
   v.SetInputConnection(r.GetOutputPort())
   v.Render()
   v.GetRenderer().ResetCamera()

   app.exec_()

there is another QVTKRenderWindowInteractor that instead of subclass
QWIdget, it subclass QGLWidget and this is the interactor I am using
right now, I attach it.

On 11/19/09, Lic. José M. Rodriguez Bacallao <jmrbcu at gmail.com> wrote:
> well using the original QVTKRenderWindowInteractor U need to know that
> it does not support reparenting so U need to encapsulate the reactor
> in another widget so U can use it with widgets that do reparenting
> (QTabWidget, QMainWindow), also, I have noticed that for
> QVTKRenderWindowInteractor to work, the widget showing the interactor
> must be visible (widget,show()) in order to setup it correctly. This
> are my observations and I don't know if they are 100% correct. Well,
> here is an example of a single window:
>
> # PyQt4 imports
> from PyQt4 import QtGui, QtCore
>
> # vtk imports
> from vtk.qt4.QVTKRenderWindowInteractor import QVTKRenderWindowInteractor
>
> class QVtkInteractorWidget(QtGui.QFrame):
>
>     def __init__(self, parent = None):
>         super(QVtkInteractorWidget, self).__init__(parent)
>         self.setup_ui()
>
>     def setup_ui(self):
>         self.setAttribute(QtCore.Qt.WA_ForceUpdatesDisabled)
>         self.setAttribute(QtCore.Qt.WA_PaintOnScreen)
>         self.setFocusPolicy(QtCore.Qt.StrongFocus)
>
>         self.vbox = QtGui.QVBoxLayout(self)
>         self.vbox.setMargin(0)
>         self.interactor = QVTKRenderWindowInteractor(self)
>         self.vbox.addWidget(self.interactor)
>         self.setLayout(self.vbox)
>
>
> if __name__ == '__main__':
>     import sys, vtk, vtkgdcm
>
>     app = QtGui.QApplication(sys.argv)
>
>     mw = QtGui.QMainWindow()
>     iwidget = QVtkInteractorWidget(mw)
>     mw.setCentralWidget(iwidget)
>     mw.show()
>
>     r = vtkgdcm.vtkGDCMImageReader()
>     r.SetFileName(sys.argv[1])
>     r.Update()
>
>     v = vtk.vtkImageViewer2()
>     v.SetupInteractor(iwidget.interactor)
>     v.SetRenderWindow(iwidget.interactor.GetRenderWindow())
>     v.SetInputConnection(r.GetOutputPort())
>     v.Render()
>     v.GetRenderer().ResetCamera()
>
>     app.exec_()
>
> there is another QVTKRenderWindowInteractor that instead of subclass
> QWIdget, it subclass QGLWidget and this is the interactor I am using
> right now, I attach it.
>
>
>
> On 11/19/09, KS Jothybasu <jothybasu at gmail.com> wrote:
>> yes, please
>>
>> Thanks
>>
>> Jothy
>>
>> On Thu, Nov 19, 2009 at 1:30 PM, Lic. José M. Rodriguez Bacallao <
>> jmrbcu at gmail.com> wrote:
>>
>>> As I told U, right now I'm only working with 2D images so I can't send
>>> U some samples but samples of working with PyQt4 and
>>> QVTKRenderWIndowInteractor, yes I can do that, did I send those
>>> samples to U?
>>>
>>> On 11/19/09, KS Jothybasu <jothybasu at gmail.com> wrote:
>>> > Like scrolling through the planes in 3D in imageplanewidget, changing
>>> > the
>>> > window level with mouse etc.., But it works with
>>> vtkrenderwindowInteractor
>>> > outside the application
>>> >
>>> > Could you please send me some sample script of yours?
>>> >
>>> > Thanks
>>> >
>>> > jothy
>>> >
>>> > On Wed, Nov 18, 2009 at 5:23 PM, Lic. José M. Rodriguez Bacallao <
>>> > jmrbcu at gmail.com> wrote:
>>> >
>>> >> in fact this is for 2d images, I'll eventually need to do the same
>>> >> thing as U but right now, I don;t know how to do it.
>>> >> What thing is not working with PyQt4?
>>> >>
>>> >> PS: sorry for my English,  am a Cuban guy
>>> >>
>>> >> On 11/18/09, KS Jothybasu <jothybasu at gmail.com> wrote:
>>> >> > Hi,
>>> >> >
>>> >> > Thanks for your suggestions
>>> >> >
>>> >> > I tried but when I use InteractorStyleImage no rotation is possible
>>> >> (maybe
>>> >> > thats for 2D images). But I want to move the orthogonal planes and
>>> >> > change
>>> >> > the window level with mouse , it perfectly works with
>>> >> > vtkRenderwindow
>>> >> with
>>> >> > vtkrenderwindowinteractor out of the GUI. But with PyQt its not
>>> working,
>>> >> see
>>> >> > the pic below
>>> >> >
>>> >> >
>>> >> > On Wed, Nov 18, 2009 at 3:20 PM, Lic. José M. Rodriguez Bacallao <
>>> >> > jmrbcu at gmail.com> wrote:
>>> >> >
>>> >> >> U need to setup an interactor style:
>>> >> >>
>>> >> >> Ej:
>>> >> >>
>>> >> >> interactor_style = vtk.vtkInteractorStyleImage()
>>> >> >> interactor.SetInteractorStyle(interactor_style)
>>> >> >>
>>> >> >> PS: How do U setup QVTKrenderwindowinteractor to work with PyQt4
>>> >> >>
>>> >> >> On 11/18/09, KS Jothybasu <jothybasu at gmail.com> wrote:
>>> >> >> > Hi,
>>> >> >> >
>>> >> >> > Could anybody please tell me how to setup the interactors
>>> >> >> > properly
>>> in
>>> >> >> > QVTKrenderwindowinteractor. My application renders the image but
>>> >> >> > it
>>> >> does
>>> >> >> the
>>> >> >> > default interaction which it does for cone example even for 3D
>>> >> >> > widgets
>>> >> >> such
>>> >> >> > as vtkImagePlane widget.
>>> >> >> >
>>> >> >> > Thanks
>>> >> >> >
>>> >> >> > Jothy
>>> >> >> >
>>> >> >>
>>> >> >>
>>> >> >> --
>>> >> >> Lic. José M. Rodriguez Bacallao
>>> >> >> Centro de Biofisica Medica
>>> >> >> -----------------------------------------------------------------
>>> >> >> Todos somos muy ignorantes, lo que ocurre es que no todos
>>> >> >> ignoramos
>>> lo
>>> >> >> mismo.
>>> >> >>
>>> >> >> Recuerda: El arca de Noe fue construida por aficionados, el
>>> >> >> titanic
>>> >> >> por profesionales
>>> >> >> -----------------------------------------------------------------
>>> >> >>
>>> >> >
>>> >>
>>> >>
>>> >> --
>>> >> Lic. José M. Rodriguez Bacallao
>>> >> Centro de Biofisica Medica
>>> >> -----------------------------------------------------------------
>>> >> Todos somos muy ignorantes, lo que ocurre es que no todos ignoramos
>>> >> lo
>>> >> mismo.
>>> >>
>>> >> Recuerda: El arca de Noe fue construida por aficionados, el titanic
>>> >> por profesionales
>>> >> -----------------------------------------------------------------
>>> >>
>>> >
>>>
>>>
>>> --
>>> Lic. José M. Rodriguez Bacallao
>>> Centro de Biofisica Medica
>>> -----------------------------------------------------------------
>>> Todos somos muy ignorantes, lo que ocurre es que no todos ignoramos lo
>>> mismo.
>>>
>>> Recuerda: El arca de Noe fue construida por aficionados, el titanic
>>> por profesionales
>>> -----------------------------------------------------------------
>>>
>>
>
>
> --
> Lic. José M. Rodriguez Bacallao
> Centro de Biofisica Medica
> -----------------------------------------------------------------
> Todos somos muy ignorantes, lo que ocurre es que no todos ignoramos lo
> mismo.
>
> Recuerda: El arca de Noe fue construida por aficionados, el titanic
> por profesionales
> -----------------------------------------------------------------
>


-- 
Lic. José M. Rodriguez Bacallao
Centro de Biofisica Medica
-----------------------------------------------------------------
Todos somos muy ignorantes, lo que ocurre es que no todos ignoramos lo mismo.

Recuerda: El arca de Noe fue construida por aficionados, el titanic
por profesionales
-----------------------------------------------------------------
-------------- next part --------------
A non-text attachment was scrubbed...
Name: interactor.py
Type: text/x-python
Size: 13248 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20091119/0567311e/attachment.py>


More information about the vtkusers mailing list