]> Creatis software - gdcm.git/blob - vtk/vtkGdcmDemo.cxx
Fix bug (Thx, Manu)
[gdcm.git] / vtk / vtkGdcmDemo.cxx
1 // $Header: /cvs/public/gdcm/vtk/vtkGdcmDemo.cxx,v 1.2 2004/11/09 11:21:33 regrain Exp $
2
3 //----------------------------------------------------------------------------
4 // A simple straightfoward example of vtkGdcmReader vtk class usage.
5 //
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.
12 //
13 // Usage: the filename of the Dicom image to display should be given as
14 //        command line arguments,
15 //----------------------------------------------------------------------------
16
17 #include <vtkRenderer.h>
18 #include <vtkRenderWindow.h>
19 #include <vtkRenderWindowInteractor.h>
20 #include <vtkPolyDataMapper.h>
21 #include <vtkActor.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>
32 #include <vtkActor.h>
33 #include <vtkImageCast.h>
34 #include <vtkPNGWriter.h>
35 #include <vtkTexture.h>
36
37 #include "vtkGdcmReader.h"
38
39   
40 int main( int argc, char *argv[] )
41 {
42    vtkGdcmReader *reader = vtkGdcmReader::New();
43
44    if (argc < 2)
45    {
46       cerr << "Usage: " << argv[0] << " image.dcm\n";
47       return 0;
48    }
49
50    reader->SetFileName( argv[1] );
51
52    reader->UpdateWholeExtent();
53    vtkImageData* ima = reader->GetOutput();
54
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;
59
60    ///////// A simple display pipeline:
61    // 
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);
69    VTKtable->Build();
70
71    //// Texture
72    vtkTexture* VTKtexture = vtkTexture::New();
73    VTKtexture->SetInput(ima);
74    VTKtexture->InterpolateOn();
75    VTKtexture->SetLookupTable(VTKtable);
76
77    //// PlaneSource
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);
82
83    //// PolyDataMapper
84    vtkPolyDataMapper *VTKplaneMapper = vtkPolyDataMapper::New();
85    VTKplaneMapper->SetInput(VTKplane->GetOutput());
86
87    //// Actor
88    vtkActor* VTKplaneActor = vtkActor::New();
89    VTKplaneActor->SetTexture(VTKtexture);
90    VTKplaneActor->SetMapper(VTKplaneMapper);
91    VTKplaneActor->PickableOn();
92
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);
101    renwin->Render();
102    iren->Start();
103
104    //// Clean up:
105    reader->Delete();
106    VTKtable->Delete();
107    VTKtexture->Delete();
108    VTKplane->Delete();
109    VTKplaneMapper->Delete();
110    VTKplaneActor->Delete();
111    ren->Delete();
112    renwin->Delete();
113    iren->Delete();
114
115    return(0);
116 }