00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #include <vtkRenderWindowInteractor.h>
00033 #include <vtkImageViewer2.h>
00034 #include <vtkStructuredPoints.h>
00035 #include <vtkStructuredPointsWriter.h>
00036 #include <vtkCommand.h>
00037 #include <vtkRenderer.h>
00038 #include <vtkImageMapToColors.h>
00039 #include <vtkLookupTable.h>
00040
00041 #include "vtkGdcmReader.h"
00042
00043 #ifndef vtkFloatingPointType
00044 #define vtkFloatingPointType float
00045 #endif
00046
00047
00048
00049 class vtkgdcmObserver : public vtkCommand
00050 {
00051 public:
00052 virtual char const *GetClassName() const
00053 {
00054 return "vtkgdcmObserver";
00055 }
00056 static vtkgdcmObserver *New()
00057 {
00058 return new vtkgdcmObserver;
00059 }
00060 vtkgdcmObserver()
00061 {
00062 this->ImageViewer = NULL;
00063 }
00064 virtual void Execute(vtkObject *, unsigned long event, void* )
00065 {
00066 if ( this->ImageViewer )
00067 {
00068 if ( event == vtkCommand::CharEvent )
00069 {
00070 int max = ImageViewer->GetWholeZMax();
00071 int slice = (ImageViewer->GetZSlice() + 1 ) % ++max;
00072 ImageViewer->SetZSlice( slice );
00073 ImageViewer->GetRenderer()->ResetCameraClippingRange();
00074 ImageViewer->Render();
00075 }
00076 }
00077 }
00078 vtkImageViewer2 *ImageViewer;
00079 };
00080
00081
00082 int main(int argc, char *argv[])
00083 {
00084 if( argc < 2 )
00085 return 0;
00086
00087 vtkGdcmReader *reader = vtkGdcmReader::New();
00088 reader->AllowLookupTableOff();
00089
00090 if( argc == 2 )
00091 reader->SetFileName( argv[1] );
00092 else
00093 for(int i=1; i< argc; i++)
00094 reader->AddFileName( argv[i] );
00095
00096 reader->Update();
00097
00098
00099 reader->GetOutput()->Print( cout );
00100
00101 vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
00102
00103 vtkImageViewer2 *viewer = vtkImageViewer2::New();
00104
00105 if( reader->GetLookupTable() )
00106 {
00107
00108 vtkImageMapToColors *map = vtkImageMapToColors::New ();
00109 map->SetInput (reader->GetOutput());
00110 map->SetLookupTable (reader->GetLookupTable());
00111 map->SetOutputFormatToRGB();
00112 viewer->SetInput ( map->GetOutput() );
00113 map->Delete();
00114 }
00115 else
00116 {
00117 double *range = reader->GetOutput()->GetScalarRange();
00118 viewer->SetColorLevel (0.5 * (range[1] + range[0]));
00119 viewer->SetColorWindow (range[1] - range[0]);
00120
00121 viewer->SetInput ( reader->GetOutput() );
00122 }
00123 viewer->SetupInteractor (iren);
00124
00125
00126
00127
00128
00129
00130 vtkgdcmObserver *obs = vtkgdcmObserver::New();
00131 obs->ImageViewer = viewer;
00132 iren->AddObserver(vtkCommand::CharEvent,obs);
00133 obs->Delete();
00134
00135
00136 iren->Initialize();
00137 iren->Start();
00138
00139
00140 vtkStructuredPointsWriter *writer = vtkStructuredPointsWriter::New();
00141 writer->SetInput( reader->GetOutput());
00142 writer->SetFileName( "foo.vtk" );
00143 writer->SetFileTypeToBinary();
00144
00145
00146 reader->Delete();
00147 iren->Delete();
00148 viewer->Delete();
00149 writer->Delete();
00150
00151 return 0;
00152 }