[vtkusers] Problem upgrading from VTK 3.2 to VTK 4.0

Joey Mukherjee joey at phobos.space.swri.edu
Thu Feb 21 11:40:40 EST 2002


I am upgrading my application from VTK 3.2 to VTK 4.0, and one feature that was 
removed was the SaveFileAsPPM and now it uses vtkWindowToImageFilter and 
vtkPNMWriter.

My problem is I am trying to make an animation so I do a rotation over one of 
the axes and after each rotation, I save the file as a PPM.

Unfortunately, the vtkWindowToImageFilter/vtkPNMWriter only writes the first 
image and not the new re-rendered ones.

However, if I do a New for the vtkWindowToImageFilter/vtkPNMWriter in the loop, 
everything works, but is slow. 

I feel an Update somewhere might solve the problem, but I can not tell where.  
Is there a way to do this without having to create the 
vtkWindowToImageFilter/vtkPNMWriter each time?

Also, I am using the VTK 4.0 release, not the nightly, so if this has already 
been changed, please let me know.

Here is the code for what I am trying to do:

    float delta = 360.0 / nsteps;
    int n = 0;
    char filename [255];
    vtkCamera    *camera = _renderer->GetActiveCamera();

    _renWin->SetSize (hsize, vsize);

    vtkWindowToImageFilter *w2if = vtkWindowToImageFilter::New ();
    w2if->SetInput (_renWin);

    vtkPNMWriter *pnmw = vtkPNMWriter::New ();
    pnmw->SetInput (w2if->GetOutput ());

    while (n < nsteps) {
        n++;
        sprintf (filename, "%s_%03d.ppm", basename, n);
        _renWin->Render ();


// I expected this to work, but it doesn't

        w2if->Update ();
              
        pnmw->SetFileName (filename);
        pnmw->Write ();

        switch (whichAxis) {
            case 0 : camera->Azimuth (delta); break;
            case 1 : camera->Elevation (delta); break;
            case 2 : camera->SetRoll (delta); break;
        }
    }
    pnmw->Delete ();
    w2if->Delete ();

Joey

+--------------------------------------------------------------------------+
+                                                                          +
+     Joey Mukherjee                 "The price of freedom is eternal      +
+     joey at swri.org                   vigilance, or $12.50 as seen on      +
+                                     E-Bay...                             +
+                                                                          +
+--------------------------------------------------------------------------+





More information about the vtkusers mailing list