vtkgdcmViewer2.cxx File Reference

#include <vtkRenderWindowInteractor.h>
#include <vtkImageViewer2.h>
#include <vtkStructuredPoints.h>
#include <vtkStructuredPointsWriter.h>
#include <vtkCommand.h>
#include <vtkRenderer.h>
#include <vtkImageMapToColors.h>
#include <vtkLookupTable.h>
#include "vtkGdcmReader.h"
#include "gdcmDocument.h"

Include dependency graph for vtkgdcmViewer2.cxx:

Go to the source code of this file.

Classes

class  vtkgdcmObserver

Defines

#define vtkFloatingPointType   float

Functions

int main (int argc, char *argv[])


Define Documentation

#define vtkFloatingPointType   float
 

Definition at line 45 of file vtkgdcmViewer2.cxx.


Function Documentation

int main int  argc,
char *  argv[]
 

Definition at line 92 of file vtkgdcmViewer2.cxx.

References vtkGdcmReader::AddFileName(), GDCM_NAME_SPACE::LD_NOSHADOWSEQ, vtkGdcmReader::New(), and vtkGdcmReader::SetFileName().

00093 {
00094    if( argc < 2 )
00095       return 0;
00096   
00097    vtkGdcmReader *reader = vtkGdcmReader::New();
00098    reader->AllowLookupTableOff();
00099 
00100    if( argc == 2 )
00101       reader->SetFileName( argv[1] );
00102    else
00103       for(int i=1; i< argc; i++)
00104          reader->AddFileName( argv[i] );
00105 
00106 // TODO : allow user to choose Load Mode
00107    reader->SetLoadMode(GDCM_NAME_SPACE::LD_NOSHADOWSEQ);  
00108    reader->Update();
00109 
00110    //print debug info:
00111    reader->GetOutput()->Print( cout );
00112 
00113    vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
00114 
00115    vtkImageViewer2 *viewer = vtkImageViewer2::New();
00116 
00117    if( reader->GetLookupTable() )
00118    {
00119       //convert to color:
00120       vtkImageMapToColors *map = vtkImageMapToColors::New ();
00121       map->SetInput (reader->GetOutput());
00122       map->SetLookupTable (reader->GetLookupTable());
00123       map->SetOutputFormatToRGB();
00124       viewer->SetInput ( map->GetOutput() );
00125       map->Delete();
00126    }
00127    else
00128    {
00129    
00130    // For a single medical image, it would be more efficient to use
00131    // 0028|1050 [DS] [Window Center]
00132    // 0028|1051 [DS] [Window Width]
00133    // but vtkgdcmReader doesn't know about them :-(
00134 
00135       vtkFloatingPointType *range = reader->GetOutput()->GetScalarRange();
00136       viewer->SetColorLevel (0.5 * (range[1] + range[0]));
00137       viewer->SetColorWindow (range[1] - range[0]);
00138 
00139       viewer->SetInput ( reader->GetOutput() );
00140    }
00141    viewer->SetupInteractor (iren);
00142   
00143    //vtkFloatingPointType *range = reader->GetOutput()->GetScalarRange();
00144    //viewer->SetColorWindow (range[1] - range[0]);
00145    //viewer->SetColorLevel (0.5 * (range[1] + range[0]));
00146 
00147    // Here is where we setup the observer, 
00148    vtkgdcmObserver *obs = vtkgdcmObserver::New();
00149    obs->ImageViewer = viewer;
00150    iren->AddObserver(vtkCommand::CharEvent,obs);
00151    obs->Delete();
00152 
00153    //viewer->Render();
00154    iren->Initialize();
00155    iren->Start();
00156 
00157    //if you wish you can export dicom to a vtk file  
00158    vtkStructuredPointsWriter *writer = vtkStructuredPointsWriter::New();
00159    writer->SetInput( reader->GetOutput());
00160    writer->SetFileName( "foo.vtk" );
00161    writer->SetFileTypeToBinary();
00162    //writer->Write();
00163 
00164    reader->Delete();
00165    iren->Delete();
00166    viewer->Delete();
00167    writer->Delete();
00168 
00169    return 0;
00170 }


Generated on Fri Aug 24 13:01:16 2007 for gdcm by  doxygen 1.4.6