[vtkusers] display bmp file

David.Pont at forestresearch.co.nz David.Pont at forestresearch.co.nz
Thu Oct 7 16:25:44 EDT 2004





Hi John,
  the following code fragment might help (presuming vtkBMPReader has
GetDataExtent). Basically get the image dimensions and use to size the
vtkPlaneSource. Different specification of Point0,1, 2 will give different
location of the image relative to the origin, eg: 0,0,0  ImageWidth,0,0
0,ImageHeight,0 would place bottom left corner at the origin. You can also
use other vtkPlaneSource methods, and/or vtkTransform to move the plane
around. This may only be important if you need to place the image relative
to other actors, it sounds like you just need to dimension the plane
correctly.

  Dave P

  int k, tiffExtent[6];
  TIFFReader->GetDataExtent( tiffExtent );
  for( k=0; k<4; k+=2 ) {
      tiffExtent[k] = tiffExtent[k+1]-tiffExtent[k];
  }
  // save width and height
  ImageWidth  = (tiffExtent[0] + 1);    // without +1 get 1023 722, not
1024, 723 for T112U07t1.tif
  ImageHeight = (tiffExtent[2] + 1);

  // define the plane
  // P2----.
  // |     |
  // |  C  |
  // |     |
  // P0---P1

  float w2, h2;

  // set image corners so centered at origin
  w2 = ImageWidth/2.0;
  h2 = ImageHeight/2.0;
  Plane->SetPoint0( -w2, -h2, 0 );
  Plane->SetPoint1(  w2, -h2, 0 );
  Plane->SetPoint2( -w2,  h2, 0 );



"John Mosso" <j-mosso at uniandes.edu.co> wrote on 07/10/2004 16:41:24:

> Greetings!
> I'm VTK freshman (know nothing so far!)
> I have an MFC app and I'm trying to display a bmp file using VTK.
> This is the code I'm using for:
>
>  bmpReader = vtkBMPReader::New();
>  bmpReader->SetFileName("C:\\MyFile.bmp");
>  atext = vtkTexture::New();
>  atext->SetInput(bmpReader->GetOutput());
>  plane = vtkPlaneSource::New();
>  planeMapper = vtkPolyDataMapper::New();
>  planeMapper->SetInput(plane->GetOutput());
>  ActorImage = vtkActor::New();
>  ActorImage->SetMapper(planeMapper);
>  ActorImage->SetTexture(atext);
>  ren->AddActor(ActorImage);
> This code display the file but it does not conserve lenght-heigth
> relationship (it's a square!) and centered; plus, I want to display
> the file starting at the left corner of the window and full size.
> Does anyone have any suggestions?
>
> Thanks in advance.
>
> John Mosso
>
>
>
>
>
>  _______________________________________________
> This is the private VTK discussion list.
> Please keep messages on-topic. Check the FAQ at: <http://public.
> kitware.com/cgi-bin/vtkfaq>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers




More information about the vtkusers mailing list