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 #include "gdcmDocument.h"
00043
00044 #ifndef vtkFloatingPointType
00045 #define vtkFloatingPointType float
00046 #endif
00047
00048
00049
00050 class vtkgdcmObserver : public vtkCommand
00051 {
00052 public:
00053 virtual char const *GetClassName() const
00054 {
00055 return "vtkgdcmObserver";
00056 }
00057 static vtkgdcmObserver *New()
00058 {
00059 return new vtkgdcmObserver;
00060 }
00061 vtkgdcmObserver()
00062 {
00063 this->ImageViewer = NULL;
00064 }
00065 virtual void Execute(vtkObject *, unsigned long event, void* )
00066 {
00067 if ( this->ImageViewer )
00068 {
00069 if ( event == vtkCommand::CharEvent )
00070 {
00071 #if (VTK_MAJOR_VERSION >= 5)
00072 int max = ImageViewer->GetSliceMax();
00073 int slice = (ImageViewer->GetSlice() + 1 ) % ++max;
00074 ImageViewer->SetSlice( slice );
00075 #else
00076 int max = ImageViewer->GetWholeZMax();
00077 int slice = (ImageViewer->GetZSlice() + 1 ) % ++max;
00078 ImageViewer->SetZSlice( slice );
00079 #endif
00080 #if !( (VTK_MAJOR_VERSION >= 5) || ( VTK_MAJOR_VERSION == 4 && VTK_MINOR_VERSION >= 5 ) )
00081
00082 ImageViewer->GetRenderer()->ResetCameraClippingRange();
00083 #endif
00084 ImageViewer->Render();
00085 }
00086 }
00087 }
00088 vtkImageViewer2 *ImageViewer;
00089 };
00090
00091
00092 int main(int argc, char *argv[])
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
00107 reader->SetLoadMode(GDCM_NAME_SPACE::LD_NOSHADOWSEQ);
00108 reader->Update();
00109
00110
00111 reader->GetOutput()->Print( cout );
00112
00113 vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
00114
00115 vtkImageViewer2 *viewer = vtkImageViewer2::New();
00116
00117 if( reader->GetLookupTable() )
00118 {
00119
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
00131
00132
00133
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
00144
00145
00146
00147
00148 vtkgdcmObserver *obs = vtkgdcmObserver::New();
00149 obs->ImageViewer = viewer;
00150 iren->AddObserver(vtkCommand::CharEvent,obs);
00151 obs->Delete();
00152
00153
00154 iren->Initialize();
00155 iren->Start();
00156
00157
00158 vtkStructuredPointsWriter *writer = vtkStructuredPointsWriter::New();
00159 writer->SetInput( reader->GetOutput());
00160 writer->SetFileName( "foo.vtk" );
00161 writer->SetFileTypeToBinary();
00162
00163
00164 reader->Delete();
00165 iren->Delete();
00166 viewer->Delete();
00167 writer->Delete();
00168
00169 return 0;
00170 }