Subject: Re: [vtkusers] same camera on different viewpoints

Sergios Goudanis sergiosgoudanis at gmail.com
Thu Jan 10 17:55:48 EST 2008


Some thoughts regarding the same camera on different viewpoints issue:

You may consider using vtkObservers in a custom interactor

assume a vtkCollection RendererCollection with renderers as items in your
custom interactor vtkMyInteractor class
the CurrentRenderer is the renderer to follow.

In the constructor of the vtkMyInteractor we add:

this->MoveCallback= vtkCallbackCommand::New();
this->MoveCallback->SetClientData(this);
this->MoveCallback->SetCallback(vtkMyInteractor::UpdateCamera);


we must add the callback in the section where the interactor becomes
enabled.
this->AddObserver(vtkCommand::AnyEvent, this->MoveCallback, 0.0);

We also must have a static function to call:

static void vtkMyInteractor::UpdateCamera(vtkObject* vtkNotUsed(object),
                                   unsigned long event,
                                   void* clientdata,
                                   void* vtkNotUsed(calldata))
{
    vtkMyInteractor* self = reinterpret_cast<vtkMyInteractor*>( clientdata
);
    self->AdjustCameras();
}

Finally the real code goes here:

void vtkMyInteractor::AdjustCameras()
{
    for (int i = 0; i < RendererCollection->GetNumberOfItems(); i++)
   {
        vtkRenderer *rn = (vtkRenderer *)
RendererCollection->GetItemAsObject(i);

rn->GetActiveCamera()->SetPosition(this->CurrentRenderer->GetPosition());
       ... SetFocalPoint...etc
   }
}

The above will tell the interactor to adjust the other cameras according to
its main renderer camera.
You may also set some cameras to act without zoom or rotation in the
AdjustCameras function

You must remove the observer when the interactor is disabled and/or in the
destructor and have in mind that
the renderers in the RendererCollection must be destroyed AFTER this
interactor is destroyed/disabled otherwise
crashes will occur.

I hope this will help
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20080111/3dfd2165/attachment.htm>


More information about the vtkusers mailing list