[vtkusers] giving renderwindow a name

David Doria daviddoria+vtk at gmail.com
Tue Jan 5 17:42:15 EST 2010


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



More information about the vtkusers mailing list