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 <vtkImageViewer.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 #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 vtkImageViewer *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
00097 reader->SetLoadMode(GDCM_NAME_SPACE::LD_NOSHADOWSEQ);
00098 reader->Update();
00099
00100
00101 reader->GetOutput()->Print( cout );
00102
00103 vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
00104
00105 vtkImageViewer *viewer = vtkImageViewer::New();
00106
00107 if( reader->GetLookupTable() )
00108 {
00109
00110 vtkImageMapToColors *map = vtkImageMapToColors::New ();
00111 map->SetInput (reader->GetOutput());
00112 map->SetLookupTable (reader->GetLookupTable());
00113 map->SetOutputFormatToRGB();
00114 viewer->SetInput ( map->GetOutput() );
00115 map->Delete();
00116 }
00117 else
00118 {
00119 vtkFloatingPointType *range = reader->GetOutput()->GetScalarRange();
00120 viewer->SetColorLevel (0.5 * (range[1] + range[0]));
00121 viewer->SetColorWindow (range[1] - range[0]);
00122
00123 viewer->SetInput ( reader->GetOutput() );
00124 }
00125 viewer->SetupInteractor (iren);
00126
00127
00128
00129
00130
00131
00132 vtkgdcmObserver *obs = vtkgdcmObserver::New();
00133 obs->ImageViewer = viewer;
00134 iren->AddObserver(vtkCommand::CharEvent,obs);
00135 obs->Delete();
00136
00137
00138 iren->Initialize();
00139 iren->Start();
00140
00141
00142 vtkStructuredPointsWriter *writer = vtkStructuredPointsWriter::New();
00143 writer->SetInput( reader->GetOutput());
00144 writer->SetFileName( "foo.vtk" );
00145 writer->SetFileTypeToBinary();
00146
00147
00148 reader->Delete();
00149 iren->Delete();
00150 viewer->Delete();
00151 writer->Delete();
00152
00153 return 0;
00154 }