vtkGdcmDemo.cxx

Go to the documentation of this file.
00001 // $Header: /cvs/public/gdcm/vtk/vtkGdcmDemo.cxx,v 1.2 2004/11/09 11:21:33 regrain Exp $
00002 
00003 //----------------------------------------------------------------------------
00004 // A simple straightfoward example of vtkGdcmReader vtk class usage.
00005 //
00006 // The vtkGdcmReader vtk class behaves like any other derived class of
00007 // vtkImageReader. It's usage within a vtk pipeline hence follows the
00008 // classical vtk pattern.
00009 // This example is a really simple Dicom image viewer demo.
00010 // It builds the minimal vtk rendering pipeline in order to display
00011 // (with the native vtk classes) a single Dicom image parsed with gdcm.
00012 //
00013 // Usage: the filename of the Dicom image to display should be given as
00014 //        command line arguments,
00015 //----------------------------------------------------------------------------
00016 
00017 #include <vtkRenderer.h>
00018 #include <vtkRenderWindow.h>
00019 #include <vtkRenderWindowInteractor.h>
00020 #include <vtkPolyDataMapper.h>
00021 #include <vtkActor.h>
00022 #include <vtkImageMapper.h>
00023 #include <vtkImageData.h>
00024 #include <vtkImageViewer.h>
00025 #include <vtkMatrix4x4.h>
00026 #include <vtkLookupTable.h>
00027 #include <vtkMatrixToLinearTransform.h>
00028 #include <vtkTexture.h>
00029 #include <vtkPlaneSource.h>
00030 #include <vtkTextureMapToPlane.h>
00031 #include <vtkDataSetMapper.h>
00032 #include <vtkActor.h>
00033 #include <vtkImageCast.h>
00034 #include <vtkPNGWriter.h>
00035 #include <vtkTexture.h>
00036 
00037 #include "vtkGdcmReader.h"
00038 
00039   
00040 int main( int argc, char *argv[] )
00041 {
00042    vtkGdcmReader *reader = vtkGdcmReader::New();
00043 
00044    if (argc < 2)
00045    {
00046       cerr << "Usage: " << argv[0] << " image.dcm\n";
00047       return 0;
00048    }
00049 
00050    reader->SetFileName( argv[1] );
00051 
00052    reader->UpdateWholeExtent();
00053    vtkImageData* ima = reader->GetOutput();
00054 
00056    int* Size = ima->GetDimensions();
00057    cout << "Dimensions of the picture as read with gdcm: "
00058         << Size[0] << " x " << Size[1] << endl;
00059 
00061    // 
00062    vtkLookupTable* VTKtable = vtkLookupTable::New();
00063    VTKtable->SetNumberOfColors(1000);
00064    VTKtable->SetTableRange(0,1000);
00065    VTKtable->SetSaturationRange(0,0);
00066    VTKtable->SetHueRange(0,1);
00067    VTKtable->SetValueRange(0,1);
00068    VTKtable->SetAlphaRange(1,1);
00069    VTKtable->Build();
00070 
00072    vtkTexture* VTKtexture = vtkTexture::New();
00073    VTKtexture->SetInput(ima);
00074    VTKtexture->InterpolateOn();
00075    VTKtexture->SetLookupTable(VTKtable);
00076 
00078    vtkPlaneSource* VTKplane = vtkPlaneSource::New();
00079    VTKplane->SetOrigin( -0.5, -0.5, 0.0);
00080    VTKplane->SetPoint1(  0.5, -0.5, 0.0);
00081    VTKplane->SetPoint2( -0.5,  0.5, 0.0);
00082 
00084    vtkPolyDataMapper *VTKplaneMapper = vtkPolyDataMapper::New();
00085    VTKplaneMapper->SetInput(VTKplane->GetOutput());
00086 
00088    vtkActor* VTKplaneActor = vtkActor::New();
00089    VTKplaneActor->SetTexture(VTKtexture);
00090    VTKplaneActor->SetMapper(VTKplaneMapper);
00091    VTKplaneActor->PickableOn();
00092 
00094    vtkRenderer        *ren = vtkRenderer::New();
00095    vtkRenderWindow *renwin = vtkRenderWindow::New();
00096    renwin->AddRenderer(ren);
00097    vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
00098    iren->SetRenderWindow(renwin);
00099    ren->AddActor(VTKplaneActor);
00100    ren->SetBackground(0,0,0.5);
00101    renwin->Render();
00102    iren->Start();
00103 
00105    reader->Delete();
00106    VTKtable->Delete();
00107    VTKtexture->Delete();
00108    VTKplane->Delete();
00109    VTKplaneMapper->Delete();
00110    VTKplaneActor->Delete();
00111    ren->Delete();
00112    renwin->Delete();
00113    iren->Delete();
00114 
00115    return(0);
00116 }

Generated on Fri Aug 24 12:53:20 2007 for gdcm by  doxygen 1.4.6