[vtkusers] Problem with vtkTkRenderWidget and CrystalEyes stereo

Jens Thomas j.m.h.thomas at dl.ac.uk
Mon Jul 10 12:33:25 EDT 2006


Hi,
Michael Scarpa wrote:
> Jens Thomas wrote:
>   
>> Hi,
>>
>> I'm trying to get vtk to use CrystalEyes stereo with a
>> vtkTkRenderWidget, but am hitting a problem in that the render window I
>> create is not stereo capapble, and I therefore get the error message:
>>
>> vtkXOpenGLRenderWindow (0x8351740): Adjusting stereo mode on a window
>> that does not support stereo type CrystalEyes is not possible.
>>
>> I call vtkTkRenderWidget with the "stereo=1" flag to generate a widget
>> with a renderwindow that is stereo capable, and then call the
>> GetRenderWindow method on the widget to get the RenderWindow. However,
>> the RenderWindow I get back is not stereo capable, as illustrated by the
>> error message above. This is despite the fact that the window that is
>> initially created within vtkTkRenderWidget is stereo capable.
>>
>> I checked this with a print statement in the file:
>>
>> VTK/Wrapping/Python/vtk/tk/vtkTkRenderWidget.py
>>
>> at line 89, where it checks the keyword dictionary as shown below:
>>
>> try:  # was a stereo rendering context requested?
>>             if kw['stereo']:
>>                print "Setting stereo"
>>                renderWindow.StereoCapableWindowOn()
>>                print renderWindow
>>                del kw['stereo']
>>         except KeyError:
>>             pass
>>
>> At the point of the print statement, the window is stereo capapble.
>>
>> It therefore seems that the window returned by the GetRenderWindow is
>> not the same one as was first created.
>>
>> If I create the render window directly, and avoid the vtkTkRenderWidget
>> side of things, it appears to work o.k.
>>
>> I've pasted in an example below that demonstrates the problem - setting
>> the tk variable to 0 or 1 turns off the Tk code and shows that it
>> appears to work if you don't use the  vtkTkRenderWidget code.
>>
>> Any suggestions/help would be greatly appreciated.
>>
>> Best wishes,
>>
>> Jens
>>
>>
>> from Tkinter import *
>> from vtk import *
>> from vtk.tk.vtkTkRenderWidget import *
>>
>> # Set the tk variable to 0 to eschew the Tk code
>> tk=1
>> if tk:
>>     # Make a root window
>>     root = Tk()
>>     # Add a vtkTkRenderWidget
>>     renderWidget = vtkTkRenderWidget(root,stereo=1)
>>     renderWidget.pack()
>>     # Get the render window from the widget
>>     renWin = renderWidget.GetRenderWindow()
>>     print "renWin is"
>>     print renWin
>> else:
>>     renWin = vtk.vtkRenderWindow()
>>     renWin.StereoCapableWindowOn()
>>     print "renWin is"
>>     print renWin
>>     iren = vtk.vtkRenderWindowInteractor()
>>     iren.SetRenderWindow(renWin)
>>
>> renWin.SetStereoTypeToCrystalEyes()
>> #renWin.SetStereoTypeToRedBlue()
>> renWin.StereoRenderOn()
>>
>> # Next, do the VTK stuff
>> ren = vtkRenderer()
>> renWin.AddRenderer(ren)
>> cone = vtkConeSource()
>> cone.SetResolution(16)
>> coneMapper = vtkPolyDataMapper()
>> coneMapper.SetInput(cone.GetOutput())
>> coneActor = vtkActor()
>> coneActor.SetMapper(coneMapper)
>> ren.AddActor(coneActor)
>>
>>
>> # start up the event loop
>> if tk:
>>     root.mainloop()
>> else:
>>     iren.Initialize()
>>     renWin.Render()
>>     iren.Start()
>>     
>
> Have you tried the same things with vtkTkRenderWindowInteractor instead
> of vtkTkRenderWidget? With the former, you can create your own
> vtkRenderWindow instance and provide it to the widget for use.  It
> would be interesting to see if you encounter the same problem in this
> case, since you can create your own render window and set its
> capabilities yourself before handing it over to Tk.
>
> Kind regards,
>
> Michael
>
>
>   
I've been playing around with this a bit more and have got a little 
further, although I'm still stuck.

You can actually create your own window with the vtkTkRenderWidget and 
pass it in too, so I tried this and still had the same problem. I've 
therefore tried to remove Python from the equation by writing a Tcl 
script that does exactly the same thing (well, I think it does - I've 
never used Tcl before) . It seems that the vtkTkRenderWidget doesn't 
accept a -stereo argument, so I have to create the render window myself 
and then pass it in.

However, even doing this, the code demonstrates exactly the same 
problems as calling the routine from Python, so it seems that the 
problem resides in the Tcl/Tk side of things. I've pasted the code into 
the tail of this email in case anyone wants to try it.

I've tried this with the VTK 5.0 on Windows, Mac OSX and Linux, and 
things seem to work fine on Windows and Mac OSX, but not under Linux - 
and unfortunately, it's Linux that I need this to work on.

I've tried this on Linux running Suse 9.3 on a Pentium with tcl 8.4.9-7 
and tk 8.4.9-9, as well as a RHEL 3 on a Intel Xeon with tcl 8.3.5-92.4 
and tk 8.3.5-92.4, so it doesn't appear to be specific to a brand of 
Linux/version of Tk/Tcl.

If anyone can suggest where I go from here, I'd be most grateful to hear 
from you!

Best wishes,

Jens


package require vtk
package require vtkinteraction

# Create the render window to pass to the vtkTkRenderWidget
vtkRenderWindow renWin1
renWin1 StereoCapableWindowOn
# At this point the window is stereo capable
puts stdout [renWin1 Print]

set renderWidget [vtkTkRenderWidget .ren -width 400 -height 400 -r renWin1]
::vtk::bind_tk_render_widget $renderWidget
wm protocol . WM_DELETE_WINDOW ::vtk::cb_exit
pack $renderWidget

# Return the render window from the vtkTkRenderWidget
set renWin [$renderWidget GetRenderWindow]

# This should be the same window as was created before, but it is not 
stereo capapble
puts stdout [$renWin Print]

$renWin SetStereoTypeToCrystalEyes
$renWin StereoRenderOn

vtkRenderer ren
$renWin AddRenderer ren
vtkConeSource cone
cone SetResolution 16
vtkPolyDataMapper coneMapper
coneMapper SetInput [cone GetOutput]
vtkActor coneActor
coneActor SetMapper coneMapper
ren AddActor coneActor

$renderWidget Render
tkwait window .




More information about the vtkusers mailing list