[vtkusers] problem met while using vtkImageWriter
Zhan Zhang
ZhangZ at mail.nlm.nih.gov
Wed Nov 27 13:14:19 EST 2002
Hi,
I have a problem while using the vtkImageWriter in an updating fashion to write a sequence of images from a rendering window. Specifically, I generate a sequence of renderings in a
render window, then, for each rendering, I get the image from the render Window, and save it using vtkImageWriter. But all the saved image files contain the same image--the very first rendering. Could someone tell me how to correct it? Bellow is my code segment, I wrote it within VC++ running on Win2000.
//define a renderer ren_cow
vtkRenderer *ren_cow;
ren_cow=vtkRenderer::New();
ren_cow->AddActor(Actor);
//define a render window
vtkRenderWindow *renWin_cow;
renWin_cow=vtkRenderWindow::New();
renWin_cow->AddRenderer(ren_cow);
//define a WindowToImageFilter
vtkWindowToImageFilter *w2i;
w2i=vtkWindowToImageFilter::New();
w2i->SetInput(renWin_cow);
//define an ImageLuminance filter
vtkImageLuminance *c2g;
c2g=vtkImageLuminance::New();
c2g->SetInput(w2i->GetOutput());
//define an ImageWriter
vtkImageWriter *writer;
writer=vtkImageWriter::New();
writer->SetInput(c2g->GetOutput());
//generate a sequence of views by change camera azimuth
//then for each view write it to an file
for (i=0; i<360; i++){
renWin_cow->Render();
//define file name
sprintf(image_file_name,"C:\\cow%d", i);
writer->SetFileName(image_file_name);
writer->Write();
//update camera
ren_cow->GetActiveCamera()->Azimuth(1);
}
the sequence of renderings shows perfectly in the render window, and I also get a series of image files as cow0, cow1, cow2.....
but these image files are all same as cow0. I change the vtkImageWriter to vtkJPEGWriter, same problem.
I also try to update before using Write() method, such as
w2i->Update();
c2g->Update();
also, end up with same problem.
Hopefully someone can help point out where the problem is. Thanks a lot.
Zhan
More information about the vtkusers
mailing list