[vtkusers] vtkImageViewer - how to prevent instant program termination under c++?

Kenneth Gage kenneth.gage at gmail.com
Wed May 18 13:08:43 EDT 2005


Dear list members -

I've been trying to use vtkImageViewer for a while now without
success; the render window pops up and disappears without allowing one
time to view the image.  My sample program is based on examples from
the textbook and users guide and appears to run normally according to
gdb.  I KNOW there is something simple and obvious I must be missing
here;

Please help me embarrass myself ;)

I've attached the source file below - I'm running under FC3 on an
athlon system using a recent CVS build of VTK.

-- 
Kenneth Gage
MD-PhD Student
McGowan Institute for Regenerative Medicine
University of Pittsburgh
Pittsburgh, PA 15203-2155

----------------------------------------------------------------------------------------------------------------------
// Include needed header files
#include <vtkImageData.h>
#include <vtkImageViewer.h>

// Begin main program
int main()
{
  // Create texture for mapping to sphere
  vtkImageData *sinusoidImage = vtkImageData::New();
  sinusoidImage->SetDimensions(256,256,1);
  sinusoidImage->SetScalarTypeToFloat();
  sinusoidImage->AllocateScalars();

  int i; int j;
  float *ptr = static_cast<float*>(sinusoidImage->GetScalarPointer());

  for (j=0; j<256; ++j)
    {
      for (i=0; i<256; ++i)
	{
	  *ptr++ = 10.0*sin(0.1*i)*sin(0.1*j);
	}
    }

  // View texture
  vtkImageViewer *imgView = vtkImageViewer::New();
  imgView->SetInput(sinusoidImage);
  imgView->SetColorWindow(20);
  imgView->SetColorLevel(2);
  imgView->Render();

  // Delete and free objects
  sinusoidImage->Delete();
  imgView->Delete();

  // Return zero if all complete
  return 0;
}



More information about the vtkusers mailing list