[vtkusers] How to properly display a tiff image

Mike Jackson imikejackson at gmail.com
Wed Apr 16 10:09:51 EDT 2008


For arguments sake, lets say that I have a tiff image that I want to  
display using vtk. The image is 10x10 pixels and consists of rows of  
solid colors. I use a vtkTIFFReader to load the image and then render  
the image. What I am seeing in the display is only 9 rows of colors.  
What should I be using in order to see all 10 rows of colors? Here is  
the basic code:

   vtkTIFFReader* tiff = vtkTIFFReader::New();
   tiff->SetFileName(TIFF_FILE);
   tiff->Update();
   vtkImageData* imageData = tiff->GetOutput();
   vtkRenderWindowInteractor *_iren;
    vtkRenderer  *_renderer;
    vtkRenderWindow  *_renWin;
    vtkInteractorStyleTrackballCamera *_trackball;

    _iren =  vtkRenderWindowInteractor::New() ;
    _renderer = vtkRenderer::New();
    _renWin = vtkRenderWindow::New();
    _renWin->SetPosition(50,50);
    _renWin->SetSize(600, 600);
    _trackball = vtkInteractorStyleTrackballCamera::New();
    _renWin->AddRenderer(_renderer);
    _iren->SetRenderWindow(_renWin);
    double center[3];
    vtkSmartPointer<vtkDataSetMapper> mapper =  
vtkSmartPointer<vtkDataSetMapper>::New();
      mapper->SetInput( imageData );
      //mapper->SetColorModeToMapScalars();
      //mapper->SetScalarModeToUseCellFieldData();
      mapper->SetScalarVisibility(true);
      mapper->SetInterpolateScalarsBeforeMapping(false);
     // mapper->SetLookupTable(lut);
      mapper->SetScalarRange(0.0, 3.0);

      vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New 
();
      actor->SetMapper(mapper);

      actor->GetProperty()->SetOpacity(1.0f);
      //actor->GetProperty()->SetInterpolation( VTK_GOURAUD );
      actor->GetProperty()->SetInterpolation( VTK_FLAT );
      actor->GetProperty()->SetRepresentationToSurface();
     // actor->GetProperty()->SetRepresentationToWireframe();
      imageData->GetCenter(center);
      std::cout << "Center of GPVoxels: " << center[0] << ", " <<  
center[1] << ", " << center[2] << std::endl;
      mapper->GetCenter(center);
      center[0] *= -1.0; center[1] *= -1.0; center[2]  *= -1.0;
      //actor->SetPosition(center);

      _renderer->AddActor(actor);
      bool initialized = false;
      if (!initialized)
       {
          _iren->Initialize();
          _iren->SetInteractorStyle(_trackball);
         // _renderer->TwoSidedLightingOff();
          _renderer->SetBackground(53.0/255.0, 52.0/255.0, 102.0/255.0);
          initialized = true;
        }
      _renderer->GetActiveCamera()->SetPosition(center[0],center[1],  
center[0]*-2.0);
      _renderer->GetActiveCamera()->SetFocalPoint(center);
      _renderer->ResetCamera();
      _renWin->Render();

      _iren->Start();

And I am attaching my test image in addition to the output that I am  
seeing.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: TestImage.tif
Type: application/applefile
Size: 19220 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20080416/70fa659b/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: TestImage.tif
Type: image/tiff
Size: 15092 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20080416/70fa659b/attachment.tif>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Output.png
Type: application/applefile
Size: 70 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20080416/70fa659b/attachment-0001.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Output.png
Type: image/png
Size: 852 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20080416/70fa659b/attachment.png>
-------------- next part --------------

Any help in understanding this is greatly appreciated. I also have  
both VTk books and am actively looking through them for any information.

Thanks.
--
Mike Jackson
imikejackson & gmail * com



More information about the vtkusers mailing list