[vtkusers] General problems using VTK widgets in PyQt

Eric E. Monson emonson at cs.duke.edu
Fri Jan 25 10:56:42 EST 2013


Hey again,

Okay, I got it to work by taking that other Qt example and playing around a bit. It works in the sense of not crashing, but the callbacks aren't all worked out. At least part of the problem I was having must have been something getting garbage collected, because this morning I was getting crashes until I added self. to all the VTK objects in my view class. I didn't take the time to figure out which objects had been problematic.

There are two versions, one uses QVTKRendWindowInteractor (reslice_view.py) and the other uses QVTKWidget (reslice_widget.py). The latter probably requires SIP Python wrapping, although I can't remember for sure. I'm using VTK 5.10. Code may not be super clean.

Good luck,
-Eric



On Jan 24, 2013, at 3:45 PM, Eric E. Monson <emonson at cs.duke.edu> wrote:

> Hey Willi,
> 
> I don't have the time or knowledge to address the problem, but I played around for a while with it and I can verify that I can't get it to work, either. The only similar thing I've run into in the past is that it was sometimes tricky to get the vtkContextView() stuff (like the VTK Charts) working in Python with PyQt4 with the QVTKWidget() or QVTKRenderWindowInteractor() – very picky with respect to setting interactor and render windows… So, there's some small chance there's just some magic order in which things need to be set. The only tip I have is to try translating the C++ Qt ImagePlaneWidget example over to Python and see if you have more luck starting with that code:
> 
> http://vtk.org/gitweb?p=VTK.git;a=blob;f=Examples/GUI/Qt/FourPaneViewer/QtVTKRenderWindows.cxx
> 
> It is a little surprising, though, that nobody would have this widget working with Python and PyQt4, so hopefully someone else will chime in with a working example.
> 
> Good luck,
> -Eric
> 
> · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · · ·
> Eric E Monson
> Duke Visualization Technology Group
> 
> 
> On Jan 22, 2013, at 10:52 AM, Willi Huber <surfersparadise85-vtk at yahoo.com> wrote:
> 
>> Still no one interested in this topic?
>> 
>> I also tried it with the Enthought Suite. No chance. The same error. I compiled VTK myself. No chance. Do I have to compile VTK in a special way? 
>> 
>> I have debugged into the error and it always occurs when vtkCallbackCommand::Execute is called (this is the callback registered by the widget):
>> 
>>  	ntdll.dll!77b9013d() 	
>>  	[Unten angegebene Rahmen sind möglicherweise nicht korrekt und/oder fehlen, keine Symbole geladen für ntdll.dll]	
>>  	ntdll.dll!77b9013d() 	
>>  	KernelBase.dll!763015e9() 	
>>  	ntdll.dll!77be74df() 	
>>  	ntdll.dll!77be73bc() 	
>>  
>> 	ntdll.dll!77be7261() 	
>>  	ntdll.dll!77bcb459() 	
>>  	ntdll.dll!77bcb42b() 	
>>  	ntdll.dll!77bcb3ce() 	
>>  	ntdll.dll!77b80133() 	
>> >	vtkCommon.dll!vtkCallbackCommand::Execute(vtkObject * caller=0x04262ed0, unsigned long event=26, void * callData=0x00000000)  Zeile 42 + 0x15 Bytes	C++
>>  	vtkCommon.dll!vtkSubjectHelper::InvokeEvent(unsigned long event=26, void * callData=0x00000000, vtkObject * self=0x04262ed0)  Zeile 605	C++
>>  	vtkCommon.dll!vtkObject::InvokeEvent(unsigned long event=37718944, void * callData=0x01d51030)  Zeile 773	C++
>> 
>> This is the code:
>> 
>> 	self.widget = QVTKRenderWindowInteractor( self )
>> 
>> 	######VTK#####
>> 	from vtk.util.misc import vtkGetDataRoot
>> 	VTK_DATA_ROOT = vtkGetDataRoot()
>> 
>> 	# Start by loading some data.
>> 	v16 = tvtk.Volume16Reader()
>> 	v16.data_dimensions = ( 64, 64 )
>> 	v16.data_byte_order = 'little_endian'
>> 	v16.file_prefix = VTK_DATA_ROOT + "/Data/headsq/quarter"
>> 	v16.image_range = ( 1, 93 )
>> 	v16.data_spacing = ( 3.2, 3.2, 1.5 )
>> 	v16.update()
>> 
>> 	xMin, xMax, yMin, yMax, zMin, zMax = v16.output.whole_extent
>> 
>> 	spacing = v16.output.spacing
>> 	sx, sy, sz = spacing
>> 
>> 	origin = v16.output.origin
>> 	ox, oy, oz = origin
>> 
>> 	# An outline is shown for context.
>> 	outline = tvtk.OutlineFilter()
>> 	outline.input_connection = v16.output_port
>> 
>> 	outlineMapper = tvtk.PolyDataMapper()
>> 	outlineMapper.input_connection = outline.output_port
>> 
>> 	outlineActor = tvtk.Actor()
>> 	outlineActor.mapper = outlineMapper
>> 
>> 	# The shared picker enables us to use 3 planes at one time
>> 	# and gets the picking order right
>> 	picker = tvtk.CellPicker()
>> 	picker.tolerance = 0.005
>> 
>> 	# The 3 image plane widgets are used to probe the dataset.
>> 	planeWidgetX = tvtk.ImagePlaneWidget()
>> 	planeWidgetX.display_text = 'on'
>> 	planeWidgetX.input = v16.output
>> 
>> 	planeWidgetX.plane_orientation = 'x'
>> 	planeWidgetX.slice_index = 32
>> 	planeWidgetX.set_picker( picker )
>> 	# planeWidgetX.SetKeyPressActivationValue( "x" )
>> 	prop1 = planeWidgetX.plane_property
>> 	prop1.color = ( 1, 0, 0 )
>> 
>> 
>> 	# Create the RenderWindow and Renderer
>> 	ren = tvtk.Renderer()
>> 	self.widget.GetRenderWindow().AddRenderer( tvtk.to_vtk( ren ) )
>> 
>> 	# Add the outline actor to the renderer, set the background color and size
>> 	ren.add_actor( outlineActor )
>> 	self.widget.GetRenderWindow().SetSize( 600, 600 )
>> 	ren.background = ( 0.1, 0.1, 0.2 )
>> 
>> 	interactor = self.widget.GetRenderWindow().GetInteractor()
>> 
>> 	planeWidgetX.interactor = tvtk.to_tvtk( interactor )
>> 	planeWidgetX.on()
>> 
>> Try mouse over the window and it suddenly crashes.
>> So if one might be gentle an advice would be helpful. Maybe its a simple problme but I can't see it.
>> 
>> Thanks in advance,
>> Willi
>> Von: Willi Huber <surfersparadise85-vtk at yahoo.com>
>> An: "vtkusers at vtk.org" <vtkusers at vtk.org> 
>> Gesendet: 20:39 Montag, 21.Januar 2013
>> Betreff: [vtkusers] General problems using VTK widgets in PyQt
>> 
>> Hello all,
>> 
>> I 've come across a problem that occurs with all so far tested VTK widgets in combination with Python and PyQt.
>> I was trying to embedd a lot of widgets (vtkResliceImageViewer, vtkImageViewer, vtkImagePlaneWidget, ...) into my application without success. Every time I have the problem that if an event (like MouseMove oder LeftButtonDown) is handled by one of these widgets the whole app crashes without any information why.
>> I know so far that it is definitely in combination with events that are handled by the widgets. Whenever I delete the observer for such an event the previously problematic action doesn't crash the app anymore.
>> 
>> I am curious why this is only happening with PyQt and not with Tk as this are the samples I tried. Next I want to debug into this problem using either Visual Studio or gdb. Has anyone had such problems using widgets in these combinations? Is it only a problem with pythonxy as this is what I was using all the time.
>> 
>> Would be nice if someone could assist me with this problem since this could be a major one.
>> 
>> Cheers,
>> Willi
>> 
>> _______________________________________________
>> 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
>> 
>> 
>> _______________________________________________
>> 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
> 
> _______________________________________________
> 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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20130125/f90cb480/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: reslice_widget.py
Type: text/x-python-script
Size: 3815 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20130125/f90cb480/attachment.bin>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20130125/f90cb480/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: reslice_view.py
Type: text/x-python-script
Size: 4003 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20130125/f90cb480/attachment-0001.bin>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20130125/f90cb480/attachment-0002.htm>


More information about the vtkusers mailing list