[vtkusers] Creating multiple views

Rocco Gasteiger post at rocco-gasteiger.de
Wed Jun 2 07:19:21 EDT 2010


Hi Anant,

 

I provide you a simple example where two scene objects are rendered in a
separate render views. Additionally, if you interact in one render window
the scene in the other render window moves correspondingly. 

 

I hope that helps you a little bit. 

 

Best regards, Rocco

 

P.S. Take a look to following VTK-site which provides useful examples
(including multiple viewports and so on):
http://www.vtk.org/Wiki/VTK/Examples

 

#include "vtkConeSource.h"

#include "vtkCubeSource.h"

#include "vtkActor.h"

#include "vtkRenderer.h"

#include "vtkRenderWindow.h"

#include "vtkCamera.h"

#include "vtkRenderWindowInteractor.h"

#include "vtkCommand.h"

#include "vtkCallbackCommand.h"

#include "vtkPolyData.h"

#include "vtkPolyDataMapper.h"

#include "vtkSmartPointer.h"

#include "vtkInteractorStyleSwitch.h"

 

 

static vtkSmartPointer<vtkRenderer> renderer01;

static vtkSmartPointer<vtkRenderer> renderer02;

static vtkSmartPointer<vtkRenderWindow> renderWindow01;

static vtkSmartPointer<vtkRenderWindow> renderWindow02;

 

class vtkMyCameraCallback : public vtkCommand

{

public:

      static vtkMyCameraCallback *New()

      {

            return new vtkMyCameraCallback;

      }

      

      virtual void Execute(vtkObject *caller, unsigned long, void*)

      {

            vtkCamera *camera = static_cast<vtkCamera*>(caller);

            double camPos[3];

            double focalPos[3];

            double upVector[3];

            camera->GetPosition(camPos);

            camera->GetFocalPoint(focalPos);

            camera->GetViewUp(upVector);

            renderer02->SetActiveCamera(camera);

            renderWindow02->Render();

      }     

};

 

int main( int argc, char *argv[] )

{

 

      vtkSmartPointer<vtkConeSource> cone =
vtkSmartPointer<vtkConeSource>::New();

      cone->SetResolution(20);

      cone->Update();

 

      vtkSmartPointer<vtkCubeSource> cube =
vtkSmartPointer<vtkCubeSource>::New();

      

      

      vtkSmartPointer<vtkPolyDataMapper> coneMapper =
vtkSmartPointer<vtkPolyDataMapper>::New();

      coneMapper->SetInput( cone->GetOutput() );

 

      vtkSmartPointer<vtkPolyDataMapper> cubeMapper =
vtkSmartPointer<vtkPolyDataMapper>::New();

      cubeMapper->SetInput( cube->GetOutput() );

      cubeMapper->Update();

      

      // ACTORS   

      vtkSmartPointer<vtkActor> coneActor =
vtkSmartPointer<vtkActor>::New();

      coneActor->SetMapper( coneMapper );

      

      vtkSmartPointer<vtkActor> cubeActor =
vtkSmartPointer<vtkActor>::New();

      cubeActor->SetMapper( cubeMapper );

      

      // RENDERER 

      renderer01= vtkSmartPointer<vtkRenderer>::New();

      renderer02= vtkSmartPointer<vtkRenderer>::New();

      

      renderer01->AddActor(coneActor);         

      renderer02->AddActor(cubeActor);

      

      // RENDER-WINDOW

      renderWindow01 = vtkSmartPointer<vtkRenderWindow>::New();

      vtkSmartPointer<vtkRenderWindowInteractor> windowInteractor01 =
vtkSmartPointer<vtkRenderWindowInteractor>::New();

      vtkSmartPointer<vtkInteractorStyleSwitch> trackballStyle =
vtkSmartPointer<vtkInteractorStyleSwitch>::New();

      trackballStyle->SetCurrentStyleToTrackballCamera();

      windowInteractor01->SetInteractorStyle(trackballStyle);

      windowInteractor01->SetRenderWindow(renderWindow01);

 

      renderWindow01->AddRenderer(renderer01);

 

      renderWindow02 = vtkSmartPointer<vtkRenderWindow>::New();

      renderWindow02->AddRenderer(renderer02);

            

 

      // User event handling

      // Catch camera event   

      vtkSmartPointer<vtkMyCameraCallback> cameraCallback =
vtkSmartPointer<vtkMyCameraCallback>::New();

      renderer01->GetActiveCamera()->AddObserver(vtkCommand::ModifiedEvent,
cameraCallback);

      renderer01->ResetCamera();

      

      windowInteractor01->Initialize();

      windowInteractor01->Start();       

 

      return 0;

}

 

 

 

Von: vtkusers-bounces at vtk.org [mailto:vtkusers-bounces at vtk.org] Im Auftrag
von Shashwath T.R.
Gesendet: Mittwoch, 2. Juni 2010 09:59
An: vtkusers
Betreff: Re: [vtkusers] Creating multiple views

 

Hi,

 

You can use the same actor in multiple renderers, but essentially,
everything else should be recreated.

 

--

Shash

On Wed, Jun 2, 2010 at 6:43 AM, Anant Vemuri <ajar108 at gmail.com> wrote:

Hi,

In VTK, I want to create an object, in two different views, i mean to view
the object from two different directions. I will be moving my object in one
of the two views and I want to see it move correspondingly in another view.
I am familiar with doing this in just one view. But what all things do I
need to recreate in order to accomplish this task? 

I am thinking, I have to create two different windows. Can I use the same
renderer in both these views but with a different active camera or do i need
to have two separate renderers? I am thinking that I don't need to recreate
all the actors and mappers. Is there anything else that I need to do.

Also is there a sample code on VTK wiki or in the VTK source directory with
this kind of an example?

Thank you for the help.


Anant.

_______________________________________________
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

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100602/1d0d81e2/attachment.htm>


More information about the vtkusers mailing list