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

David Doria daviddoria at gmail.com
Tue Nov 9 21:57:56 EST 2010


2010/11/9 LuanKuan <luankuan at hotmail.com>:
> 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.

It should work as you have described there. Note that there is no need
to keep calling SetActor - once it is set, it is set.

Below is a simple demo that moves a sphere. This demonstrates that the
render calls are working properly. I suggest you modify this example
(to create a fully compilable example) with the simplest example that
represents your updating the 3D image. Post it here if it doesn't
work.

#include <vtkSphereSource.h>
#include <vtkPolyData.h>
#include <vtkSmartPointer.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkRenderWindowInteractor.h>

int main(int , char *[])
{
  // Create a sphere
  vtkSmartPointer<vtkSphereSource> sphereSource =
    vtkSmartPointer<vtkSphereSource>::New();
  sphereSource->SetCenter(0.0, 0.0, 0.0);
  sphereSource->SetRadius(5.0);

  vtkSmartPointer<vtkPolyDataMapper> mapper =
    vtkSmartPointer<vtkPolyDataMapper>::New();
  mapper->SetInputConnection(sphereSource->GetOutputPort());

  vtkSmartPointer<vtkActor> actor =
    vtkSmartPointer<vtkActor>::New();
  actor->SetMapper(mapper);

  vtkSmartPointer<vtkRenderer> renderer =
    vtkSmartPointer<vtkRenderer>::New();
  vtkSmartPointer<vtkRenderWindow> renderWindow =
    vtkSmartPointer<vtkRenderWindow>::New();
  renderWindow->AddRenderer(renderer);
  vtkSmartPointer<vtkRenderWindowInteractor> interactor =
    vtkSmartPointer<vtkRenderWindowInteractor>::New();
  interactor->SetRenderWindow(renderWindow);

  renderer->AddActor(actor);

  renderWindow->Render();

  for(int i=0; i<10000; i++)
    {
    actor->SetPosition(static_cast<double>(i)/static_cast<double>(100),0,0);
    renderer->Render();
    interactor->Render();
    }

  interactor->Start();

  return EXIT_SUCCESS;
}

Good luck,

David



More information about the vtkusers mailing list