[vtkusers] giving renderwindow a name
David Doria
daviddoria+vtk at gmail.com
Fri Jan 8 16:43:20 EST 2010
On Fri, Jan 8, 2010 at 4:48 AM, michiel mentink
<michael.mentink at st-hughs.ox.ac.uk> wrote:
> thank you,
> that'll give me something to play with.
>
> Michael
>
> On Thu, Jan 7, 2010 at 7:16 PM, David Doria <daviddoria+vtk at gmail.com>
> wrote:
>>
>> On Thu, Jan 7, 2010 at 11:52 AM, Bryan P. Conrad <conrabp at ortho.ufl.edu>
>> wrote:
>> > Michael,
>> >
>> > I am not sure about how to programmatically align the renderwindows, but
>> > as
>> > for your question about displaying multiple render windows, I think the
>> > problem is that once you call windowinteractor.Start(), the render
>> > window
>> > will block the code from continuing until the interaction is terminated.
>> > You can work around this by calling Render() on each of the windows
>> > before
>> > you call Start(). Based on what it sounds like you are doing, it looks
>> > like
>> > you might be interested in looking at using one render window with
>> > multiple
>> > renderers in separate viewports. This will allow you to display
>> > different
>> > scenes in each renderer, but you will only have to manage one render
>> > window. I have attached examples of both scenarios below:
>> >
>> >
>> >
>> >
>> >
>> > import vtk
>> >
>> >
>> >
>> > def main():
>> >
>> > '''multiple render windows'''
>> >
>> > iren_list = []
>> >
>> > for i in range(4):
>> >
>> > rw = vtk.vtkRenderWindow()
>> >
>> > ren = vtk.vtkRenderer()
>> >
>> > rw.AddRenderer(ren)
>> >
>> > iren = vtk.vtkRenderWindowInteractor()
>> >
>> > iren.SetRenderWindow(rw)
>> >
>> > rw.Render()
>> >
>> > rw.SetWindowName('RW: '+str(i))
>> >
>> > iren_list.append(iren)
>> >
>> > #Create a sphere
>> >
>> > sphereSource = vtk.vtkSphereSource()
>> >
>> > sphereSource.SetCenter(0.0, 0.0, 0.0)
>> >
>> > sphereSource.SetRadius(5)
>> >
>> >
>> >
>> > #Create a mapper and actor
>> >
>> > mapper = vtk.vtkPolyDataMapper()
>> >
>> > mapper.SetInputConnection(sphereSource.GetOutputPort())
>> >
>> > actor = vtk.vtkActor()
>> >
>> > actor.SetMapper(mapper)
>> >
>> > ren.AddActor(actor)
>> >
>> > ren.ResetCamera()
>> >
>> >
>> >
>> > iren_list[-1].Start()
>> >
>> >
>> >
>> >
>> >
>> > def main2():
>> >
>> > '''One render window, multiple viewports'''
>> >
>> > iren_list = []
>> >
>> > rw = vtk.vtkRenderWindow()
>> >
>> > iren = vtk.vtkRenderWindowInteractor()
>> >
>> > iren.SetRenderWindow(rw)
>> >
>> > # Define viewport ranges
>> >
>> > xmins=[0,.5,0,.5]
>> >
>> > xmaxs=[0.5,1,0.5,1]
>> >
>> > ymins=[0,0,.5,.5]
>> >
>> > ymaxs=[0.5,0.5,1,1]
>> >
>> > for i in range(4):
>> >
>> > ren = vtk.vtkRenderer()
>> >
>> > rw.AddRenderer(ren)
>> >
>> > ren.SetViewport(xmins[i],ymins[i],xmaxs[i],ymaxs[i])
>> >
>> >
>> >
>> > #Create a sphere
>> >
>> > sphereSource = vtk.vtkSphereSource()
>> >
>> > sphereSource.SetCenter(0.0, 0.0, 0.0)
>> >
>> > sphereSource.SetRadius(5)
>> >
>> >
>> >
>> > #Create a mapper and actor
>> >
>> > mapper = vtk.vtkPolyDataMapper()
>> >
>> > mapper.SetInputConnection(sphereSource.GetOutputPort())
>> >
>> > actor = vtk.vtkActor()
>> >
>> > actor.SetMapper(mapper)
>> >
>> > ren.AddActor(actor)
>> >
>> > ren.ResetCamera()
>> >
>> >
>> >
>> > rw.Render()
>> >
>> > rw.SetWindowName('RW: Multiple ViewPorts')
>> >
>> > iren.Start()
>> >
>> >
>> >
>> >
>> >
>> > if __name__ == '__main__':
>> >
>> > main()
>> >
>> > main2()
>> >
>> >
>> >
>> >
>> >
>> >
>> >
>> > ____________________________
>> >
>> > Bryan P. Conrad, Ph.D.
>> >
>> > Senior Engineer
>> >
>> >
>> >
>> > Department of Orthopaedics and Rehabilitation
>> >
>> > University of Florida
>> >
>> > PO Box 112727
>> >
>> > Gainesville, FL 32611
>> >
>> > Phone: 352.273.7412
>> >
>> > Fax: 352.273.7407
>> >
>> > ________________________________
>> >
>> > From: vtkusers-bounces at vtk.org [mailto:vtkusers-bounces at vtk.org] On
>> > Behalf
>> > Of michiel mentink
>> > Sent: Thursday, January 07, 2010 6:45 AM
>> > To: David Doria
>> >
>> > Cc: vtkusers at vtk.org
>> > Subject: Re: [vtkusers] giving renderwindow a name
>> >
>> >
>> >
>> > thanks guys, I've the title working now.
>> >
>> > For a touch of perfection; is there a way to automatically set the
>> > window
>> > coordinates so that the windows are aligned wherever you want them?
>> > (i.e. next to each other?)
>> >
>> >
>> > And one last question: after the first render window has been created,
>> > the
>> > program waits for me to press 'q' to continue the program. Is
>> > there a way for the program to continue without pressing 'q'?
>> >
>> > I tried: renwindow->Finalize(); // doesn't do anything
>> >
>> > windowinteractor->TerminateApp(); // this closes the application
>> > altogether
>> > when 'q' is pressed
>> >
>> > windowinteractor->UnRegister(); // error: no matching function call
>> > // note: candidates are:
>> > virtual void vtkRenderWindowInteractor::UnRegister(vtkObjectBase*)
>> >
>> > windowinteractor->CreateOneShotTimer(1); // doesn't release focus
>> >
>> > I'd just like all windows to pop up as soon as possible and be able to
>> > manipulate them with my mouse whenever I'd like to.
>> > At this point I can manipulate all renderwindows fine, I'd just like the
>> > windows to appear without having to press 'q'.
>> >
>> > cheers, Michael
>> >
>> > On Tue, Jan 5, 2010 at 10:42 PM, David Doria <daviddoria+vtk at gmail.com>
>> > wrote:
>> >
>> > On Tue, Jan 5, 2010 at 5:22 PM, Bryan P. Conrad <conrabp at ortho.ufl.edu>
>> > wrote:
>> >> I have only done this in python, not C++, but I think the trick is to
>> >> use
>> >> the method "SetWindowName" and it has to be called *after* the
>> >> renderWindow
>> >> is rendered the first time. See the python code below (copied from
>> >> David's
>> >> C++ example), for a version that works on my machine.
>> >>
>> >> import vtk
>> >>
>> >> def main():
>> >> #Create a sphere
>> >> sphereSource = vtk.vtkSphereSource()
>> >> sphereSource.SetCenter(0.0, 0.0, 0.0)
>> >> sphereSource.SetRadius(5)
>> >>
>> >> #Create a mapper and actor
>> >> mapper = vtk.vtkPolyDataMapper()
>> >> mapper.SetInputConnection(sphereSource.GetOutputPort())
>> >> actor = vtk.vtkActor()
>> >> actor.SetMapper(mapper)
>> >>
>> >> # Setup a renderer, render window, and interactor
>> >> renderer = vtk.vtkRenderer()
>> >> renderWindow = vtk.vtkRenderWindow()
>> >> #renderWindow.SetWindowName("Test")
>> >>
>> >> renderWindow.AddRenderer(renderer);
>> >> renderWindowInteractor = vtk.vtkRenderWindowInteractor()
>> >> renderWindowInteractor.SetRenderWindow(renderWindow)
>> >>
>> >> #Add the actor to the scene
>> >> renderer.AddActor(actor)
>> >> renderer.SetBackground(1,1,1) # Background color white
>> >>
>> >> #Render and interact
>> >> renderWindow.Render()
>> >>
>> >> #*** SetWindowName after renderWindow.Render() is called***
>> >> renderWindow.SetWindowName("Test")
>> >>
>> >> renderWindowInteractor.Start()
>> >>
>> >>
>> >> if __name__ == '__main__':
>> >> main()
>> >>
>> >> ____________________________
>> >> Bryan P. Conrad, Ph.D.
>> >> Senior Engineer
>> >>
>> >> Department of Orthopaedics and Rehabilitation
>> >> University of Florida
>> >> PO Box 112727
>> >> Gainesville, FL 32611
>> >> Phone: 352.273.7412
>> >> Fax: 352.273.7407
>> >>
>> >> -----Original Message-----
>> >> From: vtkusers-bounces at vtk.org [mailto:vtkusers-bounces at vtk.org] On
>> >> Behalf
>> >> Of David Doria
>> >> Sent: Tuesday, January 05, 2010 2:07 PM
>> >> Cc: vtkusers at vtk.org
>> >> Subject: Re: [vtkusers] giving renderwindow a name
>> >>
>> >> On Tue, Jan 5, 2010 at 11:25 AM, michiel mentink
>> >> <michael.mentink at st-hughs.ox.ac.uk> wrote:
>> >>> I'm trying to give a renderwindow a title.
>> >>>
>> >>> I'm using the following code to create a window. So far so good.
>> >>>
>> >>> // create a renderer
>> >>> vtkSmartPointer<vtkRenderer> renderer =
>> >>> vtkSmartPointer<vtkRenderer>::New();
>> >>> renderer->AddActor(actor);
>> >>>
>> >>> // create a render window
>> >>> vtkSmartPointer<vtkRenderWindow> renwin =
>> >>> vtkSmartPointer<vtkRenderWindow>::New();
>> >>> renwin->AddRenderer(renderer);
>> >>>
>> >>>
>> >>> // create an interactor
>> >>> vtkSmartPointer<vtkRenderWindowInteractor> iren =
>> >>> vtkSmartPointer<vtkRenderWindowInteractor>::New();
>> >>> iren->SetRenderWindow(renwin);
>> >>> renwin->SetSize(640, 480);
>> >>>
>> >>> iren->Initialize();
>> >>> iren->Start();
>> >>>
>> >>>
>> >>> ///////////end code////////
>> >>>
>> >>> Before iren->initialize, I tried the following:
>> >>>
>> >>> iren->SetWindowInfo( "window1" );
>> >>> renwin->SetWindowInfo( "window1");
>> >>>
>> >>> and also ->SetWindowId("window1");
>> >>> and ->SetWindowName("window1");
>> >>>
>> >>> but it keeps giving me error messages upon compiling:
>> >>>
>> >>> 'class vtkRenderWindowInteractor' has no member named 'SetWindowInfo'
>> >>> or
>> >>> error: 'renWin' was not declared in this scope
>> >>>
>> >>>
>> >>> It's probably a simple mistake, but I'm still beginning to understand
>> >>> VTK.
>> >>> Can anybody point me in the right direction?
>> >>>
>> >>> Kind regards, Michael
>> >>>
>> >>>
>> >>
>> >> I setup an example if anyone cares to play with it to get it to work:
>> >> http://www.cmake.org/Wiki/VTK/Examples/WindowTitle
>> >>
>> >> Thanks,
>> >>
>> >> David
>> >
>> > Thanks Bryan, that did the trick.
>> >
>> > The example can be found here (c++):
>> >
>> > http://www.cmake.org/Wiki/VTK/Examples/WindowTitle
>> >
>> > and here(python):
>> > http://www.cmake.org/Wiki/VTK/Examples/Python/WindowTitle
>> >
>> > Thanks,
>> >
>> > David
>> > _______________________________________________
>> > 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
>> >
>> >
>>
>> If anyone cares to demo multiple render windows or multiple viewports,
>> I've made a spot for them here:
>>
>> http://www.vtk.org/Wiki/VTK/Examples/MultipleRenderWindows
>> http://www.vtk.org/Wiki/VTK/Examples/MultipleViewports
>>
>> Thanks,
>>
>> David
>> _______________________________________________
>> 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
>
>
All,
I ported these to c++
http://www.vtk.org/Wiki/VTK/Examples/MultipleViewports
http://www.vtk.org/Wiki/VTK/Examples/MultipleRenderWindows
It works, but in MultipleRenderWindows, I don't understand how you can
interact with all of the windows even though Start is only called on
one of them??
Thanks,
David
More information about the vtkusers
mailing list