Display vtkRendererWidgets

Sean Richards somebody at nowhere.com
Tue Jun 29 10:54:03 CEST 2004


"Yi-Yu Chou" <chouyiyu at hotmail.com> writes:

> Dear python users,
>
> I tried to display 4 vtkRendererWidgets arrayed in a 2x2 grid.
> I method that I use is :
>
> root = Tk()
> frame1 = Frame(root).pack(side=TOP)
> frame2 = Frame(root).pack(side=BOTTOM)
> x_pane = vtkTkRenderWidget(frame1,width=200,height=200)
> y_pane = vtkTkRenderWidget(frame1,width=200,height=200)
> z_pane =  vtkTkRenderWidget(frame2,width=200,height=200)
> all_pane =  vtkTkRenderWidget(frame2,width=200,height=200)
>
> x_pane.pack(side=LEFT)
> y_pane.pack(side=RIGHT)
> z_pane.pack(side=LEFT)
> all_pane.pack(side=RIGHT)
> .....................................
> Idealy, the arrangement would be like :
>
> X | Y
> -- | --
> Z | all
>
> However, I got some errors when running my code.
> It seems that I can't use the syntax: vtkTkRendererWidget(frame1)
> (I tried to display only one vtkTkRendererWidget by using
> vtkTkRendererWidget(root), and it worked).
> Any ideas ?
> Thanks in advance  !!!

Not being a VTK guru myself but would it not be easier to just have the
1 vtkTkRendererWidget and then add 4 renderers each displaying to a
separate area of the viewport.

Here is a quick example

--8<--------------------------------------------------------------------

from vtk import *
from vtk.tk.vtkTkRenderWindowInteractor import *
from Tkinter import *

def coneExample1():
    """ Creates a Cone inside a vtkTkRenderWindowInteractor. """
    
    # create root window
    root = Tk()
    root.title("Cone 1")

    win = vtkTkRenderWindowInteractor(root, width=300, height=300)
    win.Initialize()

    def quit(obj=root):
        obj.quit()

    win.AddObserver("ExitEvent", lambda o,e,q=quit: q())

    ren1 = vtk.vtkRenderer()
    win.GetRenderWindow().AddRenderer(ren1)
    ren2 = vtk.vtkRenderer()
    win.GetRenderWindow().AddRenderer(ren2)
    ren3 = vtk.vtkRenderer()
    win.GetRenderWindow().AddRenderer(ren3)
    ren4 = vtk.vtkRenderer()
    win.GetRenderWindow().AddRenderer(ren4)

    cone = vtk.vtkConeSource()
    cone.SetResolution(8)
    
    coneMapper = vtk.vtkPolyDataMapper()
    coneMapper.SetInput(cone.GetOutput())
    
    coneActor = vtk.vtkActor()
    coneActor.SetMapper(coneMapper)

    ren1.AddActor(coneActor)
    ren2.AddActor(coneActor)
    ren3.AddActor(coneActor)
    ren4.AddActor(coneActor)
    ren1.SetViewport(0, 0, 0.5, 0.5)
    ren2.SetViewport(0.5, 0, 1, 0.5)
    ren3.SetViewport(0, 0.5, 0.5, 1)
    ren4.SetViewport(0.5, 0.5, 1, 1)

    # pack the win into the tk root
    win.pack(fill='both', expand=1)
    win.Start()

    # start the tk mainloop
    root.mainloop()
    
if __name__ == "__main__":
    coneExample1()

--8<--------------------------------------------------------------------

Sean
 
-- 
"Hver sin smak", sa vintapperen, han drakk mens de andre sloss.



More information about the Python-list mailing list