[vtkusers] Render a image in a loop while it is updating

Jim Peterson jimcp at cox.net
Wed Nov 10 07:00:46 EST 2010


LuanKaun,
you do not want to have any render functions in a loop in your program,
the way I achieve animation is to add observer callbacks to the renderer
for startevent and endevent. in the start event, I update the respective
polydata objects to whatever new data is available and use the
modified() method on each modified polydata so that the update call from
within the renderer will reflect the new data.
These two callbacks combined with the interactor SetStillUpdateRate()
and SetDesiredUpdateRate() methods produce a self running animation in
my experience.
I had not done a simple example, but I Will see if I can make a version
of the cone tutorial (probably in Java) to demonstrate animated vtk.

Hope that helps,
Jim

LuanKuan wrote:
> Hi, vtk users
>
> I am a beginner.
>
> I just want to render a 3d image in the same vtkRenderWindow without
> creating a new one.
>
> I create vtkrenderer and vtkrenderwindow before the loop.
>
> The 3d image is updated and rendered in the loop.
>
> In the result, only the first 3d image is rendered in the
> vtkrenderwindow. Then, the rendered 3d image can not change while it
> is updating.
>
> My code is as fellows, please tell me how to correct it or give me
> some examples.
>
> thank you.
>
>
> vtkRenderer *aRenderer = vtkRenderer::New();
> vtkRenderWindow *renWin = vtkRenderWindow::New();
> renWin->AddRenderer(aRenderer);
> vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
> iren->SetRenderWindow(renWin);
>
> vtkContourFilter *contours = vtkContourFilter::New();
> vtkPolyDataMapper *contmap = vtkPolyDataMapper::New();
> vtkActor *contact = vtkActor::New();
>
> vtkCamera *aCamera = vtkCamera::New();
> aCamera->ParallelProjectionOn();
> aRenderer->SetActiveCamera(aCamera);
> aRenderer->ResetCamera();
> aRenderer->SetBackground(0.725,0.725,1);
> renWin->SetSize(1024, 768);
> aRenderer->ResetCameraClippingRange ();
> iren ->Initialize();
>
> // loop
> for (int i=iFirstFrame; i<iNumFrames; i++)
> {
> ......
> interpolate bmpimage into volumeimage;
> ......
> volumeimage->update();
> contours->SetInput(volumeimage);
> contours->SetValue(0,gval);
> contmap->SetInput(contours->GetOutput());
> contmap->SetScalarRange(100,220);
> contact->SetMapper(contmap);
> aRenderer->AddActor(contact);
> aRenderer->Render();
> iren->Render();
> }
> iren->Start();
>




More information about the vtkusers mailing list