[vtkusers] Again python debugging

Willi Huber surfersparadise85-vtk at yahoo.com
Thu Jan 17 11:56:10 EST 2013


Dear Users of the VTK world,

I have tried a lot now and my conclusion is that all the problems I am facing have to do with the combination of VTK and Qt. Whenever I let Qt go and I use a usual RenderWindow and do the setup as intended everything is just fine.

I now switched to using the QVTKWidget and tried to rebuild the Examples\GUI\Qt\FourPaneViewer Example of the vtk-source-tree in Python (because of the vtkResliceImageViewer) with just one widget now . All the settings are the same. Also the Observer or rather the Callback is there. Still the same error. I am desperately searching for an answer how to make it work. 


My current code:

==== python code ====
        reader = vtk.vtkMetaImageReader()
        reader.SetFileName( file )
        reader.Update()

        widget = qvtk.QVTKWidget( self.widget )

        layout = QtGui.QVBoxLayout()
        layout.addWidget( widget )

        self.slider = QtGui.QSlider( Qt.Horizontal, self.widget )
        layout.addWidget( self.slider )

        self.widget.setLayout( layout )

        viewer = vtk.vtkResliceImageViewer()
        widget.SetRenderWindow( viewer.GetRenderWindow() )
        viewer.SetupInteractor( widget.GetRenderWindow().GetInteractor() )

        vtk.vtkResliceCursorLineRepresentation.SafeDownCast( viewer.GetResliceCursorWidget().GetRepresentation() ).GetResliceCursorActor().GetCursorAlgorithm().SetReslicePlaneNormal( 2 )
        viewer.SetInputConnection( reader.GetOutputPort() )
        viewer.SetSlice( 50 )
        viewer.SetSliceOrientation( 2 )
        viewer.SetResliceModeToAxisAligned()

        cbk = vtkResliceCursorCallback()

        viewer.GetResliceCursorWidget().AddObserver( 'vtkResliceCursorWidget::ResliceAxesChangedEvent', cbk )
        viewer.GetResliceCursorWidget().AddObserver( 'vtkResliceCursorWidget::WindowLevelEvent', cbk )
        viewer.GetResliceCursorWidget().AddObserver( 'vtkResliceCursorWidget::ResliceThicknessChangedEvent', cbk )
        viewer.GetResliceCursorWidget().AddObserver( 'vtkResliceCursorWidget::ResetCursorEvent', cbk )
        viewer.GetInteractorStyle().AddObserver( 'vtkCommand::WindowLevelEvent', cbk )

        widget.show()

==== end code ====

Where vtkResliceCursorCallback is this:

==== python code ====
class vtkResliceCursorCallback:
   def __init__( self ):
       self.CallDataType = 'string0'

   # Execute method usually
   def __call__( self, obj, event, message ):
       print event

==== end code ====


I used the ErrorObserver of David Gobbi as guide.



Please can anyone help me? Please Please.






>________________________________
> Von: Willi Huber <surfersparadise85-vtk at yahoo.com>
>An: surfersparadise85-vtk at yahoo.com; vtkusers at vtk.org 
>Gesendet: 12:07 Mittwoch, 16.Januar 2013
>Betreff: AW: [vtkusers] Again python debugging
> 
>
>Anyone?
>
>
>
>------------------------------
>Willi Huber schrieb am Di., 15. Jan 2013 04:55 MEZ:
>
>>Hello all,
>>
>>I am trying to do some new stuff and I am again hitting the debugging barriers of vtk in python.
>>
>>My code:
>>
>>        file = "test.mhd"
>>
>>        reader = vtk.vtkMetaImageReader()
>>        reader.SetFileName(file)
>>        reader.Update()  #just for checking because I had an observer attached to reader
>>        
>>
>>        iren = QVTKRenderWindowInteractor(self.widget)
>>        ren = vtk.vtkRenderer()
>>
>>        iren.GetRenderWindow().AddRenderer(ren)
>>
>>                      
>>
>>        viewer = vtk.vtkResliceImageViewer()
>>        viewer.SetRenderWindow(iren.GetRenderWindow())
>>
>>        viewer.SetRenderer(ren)
>>        viewer.SetupInteractor(iren)
>>        viewer.SetInput(reader.GetOutput())
>>        
>>        viewer.SetSlice(50)
>>        viewer.SetColorWindow(2000.0)
>>        viewer.SetColorLevel(1000.0)
>>        
>>        layout = QtGui.QVBoxLayout()
>>
>>        layout.addWidget(iren)
>>        
>>        self.slider = QtGui.QSlider(Qt.Horizontal, self.widget)
>>        layout.addWidget(self.slider)
>>        
>>        self.widget.setLayout(layout)
>>        
>>        iren.Initialize()
>>        iren.Start()
>>
>>I can see the image in the first place.
>>When I use the right mouse button everything is fine and I can zoom in and out but when using the left mouse button the app suddenly freezes and the debugging window of Win7 appears - not the VTK window. It is sth. with a malloc at least this is what the debugger told me or rather stepped in.
>>I tried using the Error Observer suggested by David and mined every object I've access to. I also used the vtk.vtkFileOutputWindow() without any success. No file was written.
>>(The slider isn't currently attached to any object so you can ignore it.) Am I doing sth. wrong with the initialization?
>>
>>Can someone help me with this?
>>
>>Cheers,
>>Willi
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20130117/93353e20/attachment.htm>


More information about the vtkusers mailing list