[vtkusers] black output images using vtkWindowToImageFilter

mhsurfer at gmx.net mhsurfer at gmx.net
Mon Jun 12 18:57:08 EDT 2006


problem: 
I only get black output images (300x300) using vtkWindowToImageFilter. For my 
first tests I used the sphere example from the webpages (see below).

setup:
Linux Box running Debian/SID (Kanotix), kernel 2.6.16
Ati X300 using fglrx 8.25.18
vtk packages from Debian/SID 4.4.2-10
g++ 4.0.4 20060507 (prerelease) (Debian 4.0.3-3)

compiled using:
g++ -Wno-deprecated /usr/lib/libvtk*.so sphere.cpp

// sphere.cpp:
#include <vtk/vtkSphereSource.h>
#include <vtk/vtkPolyDataMapper.h>
#include <vtk/vtkActor.h>
#include <vtk/vtkRenderWindow.h>
#include <vtk/vtkRenderer.h>
#include <vtk/vtkRenderWindowInteractor.h>
#include <vtk/vtkProperty.h>
#include <vtk/vtkWindowToImageFilter.h>
#include <vtk/vtkJPEGWriter.h>
int main ()
{
  // create sphere geometry
  vtkSphereSource *sphere = vtkSphereSource::New();
  sphere->SetRadius(1.0);
  sphere->SetThetaResolution(18);
  sphere->SetPhiResolution(18);

  // map to graphics library
  vtkPolyDataMapper *map = vtkPolyDataMapper::New();
  map->SetInput(sphere->GetOutput());

  // actor coordinates geometry, properties, transformation
  vtkActor *aSphere = vtkActor::New();
  aSphere->SetMapper(map);
  aSphere->GetProperty()->SetColor(0,0,1); // sphere color blue

  // a renderer and render window
  vtkRenderer *ren1 = vtkRenderer::New();
  vtkRenderWindow *renWin = vtkRenderWindow::New();
  renWin->AddRenderer(ren1);

  // an interactor
  vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
  iren->SetRenderWindow(renWin);

  // add the actor to the scene
  ren1->AddActor(aSphere);
  ren1->SetBackground(1,1,1); // Background color white

  // NEW: prepare image output
  vtkWindowToImageFilter *w2if = vtkWindowToImageFilter::New();
  w2if->SetInput( renWin);
  vtkJPEGWriter *writeJPEG = vtkJPEGWriter::New();
  writeJPEG->SetInput (w2if->GetOutput() );
  writeJPEG->SetQuality(100);
  writeJPEG->SetFileName("out.jpg");
  writeJPEG->ProgressiveOff();
  
  // render an image (lights and cameras are created automatically)
  renWin->Render();

  // NEW: do image output
  w2if->Modified();
  writeJPEG->Write();

  // begin mouse interaction
  iren->Start();
}




More information about the vtkusers mailing list