[vtkusers] Re: displaying an image

Robert Mitchell robmitch at eng.uts.edu.au
Thu Jun 28 20:59:23 EDT 2001


Hi Marie-Eve,

I set up a pipeline to use vtkBMPReader to read a bitmap (whick creates
as output vtkImageData). This is then the input for vtkImageActor which
can be added to a renderer(vtkRenderer):

m_BMPReader = vtkBMPReader::New();
m_ImageActor = vtkImageActor::New();

m_BMPReader->SetFileName("View1.bmp");
m_ImageActor->SetInput(m_BMPReader->GetOutput());

Or, if you mean you have a data file that you want to read in and create
an image explicitly , then create an instance of vtkImageData (like the
output of vtkBMPReader) and fill in the scalars you have: (Someone will
have a better way of doing this but it works for me at the moment)

  unsigned char *point;
  int ijk[3]  = {0,0,0}; // IJK indices of image (where k=0)

    for (int m=0; m<cols; m++) // Loop around columns
    {
      for(int n=0; n<rows; n++) // Loop around rows
      {
        ijk[0]=m;
        ijk[1]=n;

        point = (unsigned char*) ImageData->GetScalarPointer(ijk);
        *point = (unsigned char) {{Put in your own data here}}
      }
    }
Then put this as input into vtkImageActor...

Hope it helps,
Rob

--
Robert Mitchell
Faculty of Engineering
University of Technology, Sydney
+61 2 9514 2317


=======================
you wrote:

I have a file with 256 x 256 color scalars each associated with a pixel
of
an image.  How can I display this image ?
=======================






More information about the vtkusers mailing list