[vtkusers] how to draw more than one object separately?

Obada Mahdi omahdi at gmx.de
Sat Dec 9 05:49:57 EST 2006


Hi!

On Sat, 9 Dec 2006, polinzhuo wrote:
>         I want to draw two objects in a window separately. After object A
> rendered, and then object B is rendered. Need I have two vtkrenderer
> objects? There are two rederer in my Routine, but only one is drawn. How to
> resolve it ? My code below:

Please excuse my confusion: What exactly do you mean by "separately"?

If you just want to have multiple objects in a rendered scene (looked at
by the same camera), you only need one vtkRenderer, and you can add
every object that makes up your scene via vtkRenderer::AddActor() et al.

To display multiple views (with independent cameras) in one window,
however, you do need multiple renderers.  In that case, you might want
to use vtkRenderer::SetViewport() (inherited from vtkViewport) to
specify for each renderer which portion of the render window to occupy.
There is an example in the VTK source tree showing how this is done, at

Examples/Tutorial/Step3/Cxx/Cone3.cxx


Some other suggestions regarding your example:

- Consider using generic versions like vtkRenderer and vtkRenderWindow
   instead of corresponding specialized versions vtkOpenGLActor and
   vtkWin32OpenGLRenderWindow. VTK's object factory mechanism will take
   care of choosing proper versions for you, which makes it a lot easier
   to write portable code.

- Do not call vtkOpenGLRenderWindow::OpenGLInit() directly, but call
   vtkRenderWindowInteractor::Initialize() before invoking its Start()
   method, which will, amongst other things, call OpenGLInit() if
   appropriate.  An additional call to OpenGLInit() probably does not
   hurt, but omitting the latter can cause certain mechanisms to cease
   functioning.


Regards

Obada

> vtkSphereSource *pSphere;
>
> vtkConeSource *pCone;
>
>         pSphere = vtkSphereSource::New();
>
>         pSphere->SetCenter( 10.0 , 0.0 , 0.0 );
>
>         pSphere->SetRadius( 10.0 );
>
>         pSphere->SetStartTheta( 0.0 );
>
>         pSphere->SetEndTheta( 360.0 );
>
>         pSphere->SetThetaResolution( 30.0 );
>
>         pSphere->SetStartPhi( 0.0 );
>
>         pSphere->SetEndPhi( 90.0 );
>
>         pSphere->SetPhiResolution( 30.0 );
>
>
>
>         pCone = vtkConeSource::New();
>
>         pCone->SetCenter( -10.0 , 0.0 , 0.0 );
>
>         pCone->SetRadius( 2.0 );
>
>         pCone->SetHeight(10);
>
>
>
>         vtkPolyDataMapper* mapMest1 = vtkPolyDataMapper::New();
>
>         vtkPolyDataMapper* mapMest2 = vtkPolyDataMapper::New();
>
>         mapMest1->SetInput(pSphere->GetOutput());
>
>         mapMest2->SetInput(pCone->GetOutput());
>
>         meshActor1 = vtkOpenGLActor::New();
>
>         meshActor2 = vtkOpenGLActor::New();
>
>         meshActor1->SetMapper(mapMest1);
>
>         meshActor2->SetMapper(mapMest2);
>
>         meshActor1->GetProperty()->SetColor(1,0,0);
>
>         meshActor2->GetProperty()->SetColor(1,0,0);
>
>
>
>         ren1= vtkOpenGLRenderer::New();
>
>         ren2= vtkOpenGLRenderer::New();
>
>         ren2->AddActor( meshActor2 );
>
>         ren1->AddActor( meshActor1 );
>
>
>
>         renWin = vtkWin32OpenGLRenderWindow::New();
>
>         renWin->OpenGLInit();
>
>
>
>         int wx=150;
>
>         int wy=150;
>
>         renWin->SetSize( wx, wy );
>
>
>
>         renWin->AddRenderer(ren1);
>
>         renWin->AddRenderer(ren2);
>
>
>
>        iren = vtkRenderWindowInteractor::New();
>
>         iren->SetRenderWindow(renWin);
>
>         ren1->Render();
>
>         ren2->Render();
>
>         renWin->Render();
>
>         iren->Start();
>
>



More information about the vtkusers mailing list