1 // $Header: /cvs/public/gdcm/vtk/vtkGdcmDemo.cxx,v 1.2 2004/11/09 11:21:33 regrain Exp $
3 //----------------------------------------------------------------------------
4 // A simple straightfoward example of vtkGdcmReader vtk class usage.
6 // The vtkGdcmReader vtk class behaves like any other derived class of
7 // vtkImageReader. It's usage within a vtk pipeline hence follows the
8 // classical vtk pattern.
9 // This example is a really simple Dicom image viewer demo.
10 // It builds the minimal vtk rendering pipeline in order to display
11 // (with the native vtk classes) a single Dicom image parsed with gdcm.
13 // Usage: the filename of the Dicom image to display should be given as
14 // command line arguments,
15 //----------------------------------------------------------------------------
17 #include <vtkRenderer.h>
18 #include <vtkRenderWindow.h>
19 #include <vtkRenderWindowInteractor.h>
20 #include <vtkPolyDataMapper.h>
22 #include <vtkImageMapper.h>
23 #include <vtkImageData.h>
24 #include <vtkImageViewer.h>
25 #include <vtkMatrix4x4.h>
26 #include <vtkLookupTable.h>
27 #include <vtkMatrixToLinearTransform.h>
28 #include <vtkTexture.h>
29 #include <vtkPlaneSource.h>
30 #include <vtkTextureMapToPlane.h>
31 #include <vtkDataSetMapper.h>
33 #include <vtkImageCast.h>
34 #include <vtkPNGWriter.h>
35 #include <vtkTexture.h>
37 #include "vtkGdcmReader.h"
40 int main( int argc, char *argv[] )
42 vtkGdcmReader *reader = vtkGdcmReader::New();
46 cerr << "Usage: " << argv[0] << " image.dcm\n";
50 reader->SetFileName( argv[1] );
52 reader->UpdateWholeExtent();
53 vtkImageData* ima = reader->GetOutput();
55 ///////// Display image size on terminal:
56 int* Size = ima->GetDimensions();
57 cout << "Dimensions of the picture as read with gdcm: "
58 << Size[0] << " x " << Size[1] << endl;
60 ///////// A simple display pipeline:
62 vtkLookupTable* VTKtable = vtkLookupTable::New();
63 VTKtable->SetNumberOfColors(1000);
64 VTKtable->SetTableRange(0,1000);
65 VTKtable->SetSaturationRange(0,0);
66 VTKtable->SetHueRange(0,1);
67 VTKtable->SetValueRange(0,1);
68 VTKtable->SetAlphaRange(1,1);
72 vtkTexture* VTKtexture = vtkTexture::New();
73 VTKtexture->SetInput(ima);
74 VTKtexture->InterpolateOn();
75 VTKtexture->SetLookupTable(VTKtable);
78 vtkPlaneSource* VTKplane = vtkPlaneSource::New();
79 VTKplane->SetOrigin( -0.5, -0.5, 0.0);
80 VTKplane->SetPoint1( 0.5, -0.5, 0.0);
81 VTKplane->SetPoint2( -0.5, 0.5, 0.0);
84 vtkPolyDataMapper *VTKplaneMapper = vtkPolyDataMapper::New();
85 VTKplaneMapper->SetInput(VTKplane->GetOutput());
88 vtkActor* VTKplaneActor = vtkActor::New();
89 VTKplaneActor->SetTexture(VTKtexture);
90 VTKplaneActor->SetMapper(VTKplaneMapper);
91 VTKplaneActor->PickableOn();
93 //// Final rendering with simple interactor:
94 vtkRenderer *ren = vtkRenderer::New();
95 vtkRenderWindow *renwin = vtkRenderWindow::New();
96 renwin->AddRenderer(ren);
97 vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
98 iren->SetRenderWindow(renwin);
99 ren->AddActor(VTKplaneActor);
100 ren->SetBackground(0,0,0.5);
107 VTKtexture->Delete();
109 VTKplaneMapper->Delete();
110 VTKplaneActor->Delete();