00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "mitkDicomDiffusionImageHeaderReader.h"
00020
00021 #include "mitkGEDicomDiffusionImageHeaderReader.h"
00022 #include "mitkPhilipsDicomDiffusionImageHeaderReader.h"
00023 #include "mitkSiemensDicomDiffusionImageHeaderReader.h"
00024 #include "mitkSiemensMosaicDicomDiffusionImageHeaderReader.h"
00025
00026 void InsertUnique( std::vector<float> & vec, float value )
00027 {
00028 int n = vec.size();
00029 if (n == 0)
00030 {
00031 vec.push_back( value );
00032 return;
00033 }
00034
00035 for (int k = 0; k < n ; k++)
00036 {
00037 if (vec[k] == value)
00038 {
00039 return;
00040 }
00041 }
00042
00043
00044 vec.push_back( value );
00045 return;
00046
00047 }
00048
00049 mitk::DicomDiffusionImageHeaderReader::DicomDiffusionImageHeaderReader()
00050 {
00051 m_SliceOrderIS = true;
00052 m_SingleSeries = true;
00053 }
00054
00055 mitk::DicomDiffusionImageHeaderReader::~DicomDiffusionImageHeaderReader()
00056 {
00057 }
00058
00059 mitk::DicomDiffusionImageHeaderReader::SupportedVendors
00060 mitk::DicomDiffusionImageHeaderReader::GetVendorID()
00061 {
00062
00063
00064
00065 m_GdcmIO = ImageIOType::New();
00066 m_GdcmIO->LoadPrivateTagsOn();
00067 m_GdcmIO->SetMaxSizeLoadEntry( 65536 );
00068
00069 m_VolumeReader = VolumeReaderType::New();
00070 m_VolumeReader->SetImageIO( m_GdcmIO );
00071 m_VolumeReader->SetFileNames( m_DicomFilenames );
00072
00073 try
00074 {
00075 m_VolumeReader->Update();
00076 }
00077 catch (itk::ExceptionObject &excp)
00078 {
00079 std::cerr << "Exception thrown while reading slice" << std::endl;
00080 std::cerr << excp << std::endl;
00081 return SV_UNKNOWN_VENDOR;
00082 }
00083
00084 VolumeReaderType::DictionaryArrayRawPointer inputDict
00085 = m_VolumeReader->GetMetaDataDictionaryArray();
00086
00087 std::string vendor;
00088 itk::ExposeMetaData<std::string> ( *(*inputDict)[0], "0008|0070", vendor );
00089
00090
00091 std::string ImageType;
00092 itk::ExposeMetaData<std::string> ( *(*inputDict)[0], "0008|0008", ImageType );
00093
00094
00095 if ( vendor.find("GE") != std::string::npos )
00096 {
00097
00098 return SV_GE;
00099 }
00100 else if( vendor.find("SIEMENS") != std::string::npos )
00101 {
00102 if ( ImageType.find("MOSAIC") != std::string::npos )
00103 {
00104
00105 return SV_SIEMENS_MOSAIC;
00106 }
00107 else
00108 {
00109
00110 return SV_SIEMENS;
00111 }
00112 }
00113 else if( vendor.find("PHILIPS") != std::string::npos )
00114 {
00115
00116 return SV_PHILIPS;
00117 }
00118 else
00119 {
00120
00121 return SV_UNKNOWN_VENDOR;
00122 }
00123 }
00124
00125
00126 void mitk::DicomDiffusionImageHeaderReader::Update()
00127 {
00128
00129
00130 if(m_DicomFilenames.size())
00131 {
00132
00133 m_Output = mitk::DiffusionImageHeaderInformation::New();
00134 m_Output->m_DicomFilenames = m_DicomFilenames;
00135
00136
00137 switch(GetVendorID())
00138 {
00139 case(SV_GE):
00140 {
00141 GEDicomDiffusionImageHeaderReader::Pointer reader
00142 = GEDicomDiffusionImageHeaderReader::New();
00143 reader->SetSeriesDicomFilenames(this->m_DicomFilenames);
00144 reader->SetGdcmIO(this->m_GdcmIO);
00145 reader->SetVolumeReader(this->m_VolumeReader);
00146 reader->SetOutputPointer(this->m_Output);
00147 reader->Update();
00148 this->m_Output = reader->GetOutput();
00149 break;
00150 }
00151 case(SV_SIEMENS):
00152 {
00153 SiemensDicomDiffusionImageHeaderReader::Pointer reader
00154 = SiemensDicomDiffusionImageHeaderReader::New();
00155 reader->SetSeriesDicomFilenames(this->m_DicomFilenames);
00156 reader->SetGdcmIO(this->m_GdcmIO);
00157 reader->SetVolumeReader(this->m_VolumeReader);
00158 reader->SetOutputPointer(this->m_Output);
00159 reader->Update();
00160 this->m_Output = reader->GetOutput();
00161 break;
00162 }
00163 case(SV_SIEMENS_MOSAIC):
00164 {
00165
00166 SiemensMosaicDicomDiffusionImageHeaderReader::Pointer reader
00167 = SiemensMosaicDicomDiffusionImageHeaderReader::New();
00168 reader->SetSeriesDicomFilenames(this->m_DicomFilenames);
00169 reader->SetGdcmIO(this->m_GdcmIO);
00170 reader->SetVolumeReader(this->m_VolumeReader);
00171 reader->SetOutputPointer(this->m_Output);
00172 reader->Update();
00173 this->m_Output = reader->GetOutput();
00174 break;
00175 }
00176 case(SV_PHILIPS):
00177 {
00178
00179 PhilipsDicomDiffusionImageHeaderReader::Pointer reader
00180 = PhilipsDicomDiffusionImageHeaderReader::New();
00181 reader->SetSeriesDicomFilenames(this->m_DicomFilenames);
00182 reader->SetGdcmIO(this->m_GdcmIO);
00183 reader->SetVolumeReader(this->m_VolumeReader);
00184 reader->SetOutputPointer(this->m_Output);
00185 reader->Update();
00186 this->m_Output = reader->GetOutput();
00187 break;
00188 }
00189 case(SV_UNKNOWN_VENDOR):
00190 {
00191 std::cerr << "diffusion header reader: unknown vendor" << std::endl;
00192 break;
00193 }
00194 }
00195 }
00196 }
00197
00198
00199 mitk::DiffusionImageHeaderInformation::Pointer
00200 mitk::DicomDiffusionImageHeaderReader::GetOutput()
00201 {
00202 return m_Output;
00203 }
00204
00205 void mitk::DicomDiffusionImageHeaderReader::ReadPublicTags()
00206 {
00207 VolumeReaderType::DictionaryArrayRawPointer inputDict
00208 = m_VolumeReader->GetMetaDataDictionaryArray();
00209
00210
00211 m_nSlice = inputDict->size();
00212 std::string tag;
00213
00214 tag.clear();
00215 itk::ExposeMetaData<std::string> ( *(*inputDict)[0], "0008|103e", tag );
00216 this->m_Output->seriesDescription = tag.c_str();
00217
00218 tag.clear();
00219 itk::ExposeMetaData<std::string> ( *(*inputDict)[0], "0020|0011", tag );
00220 this->m_Output->seriesNumber = atoi(tag.c_str());
00221
00222 tag.clear();
00223 itk::ExposeMetaData<std::string> ( *(*inputDict)[0], "0010|0010", tag );
00224 this->m_Output->patientName = tag.c_str();
00225
00226 tag.clear();
00227 itk::ExposeMetaData<std::string> ( *(*inputDict)[0], "0028|0010", tag );
00228 this->m_Output->nRows = atoi( tag.c_str() );
00229
00230 tag.clear();
00231 itk::ExposeMetaData<std::string> ( *(*inputDict)[0], "0028|0011", tag );
00232 this->m_Output->nCols = atoi( tag.c_str() );
00233
00234 tag.clear();
00235 itk::ExposeMetaData<std::string> ( *(*inputDict)[0], "0028|0030", tag );
00236 sscanf( tag.c_str(), "%f\\%f", &this->m_Output->xRes, &this->m_Output->yRes );
00237
00238 tag.clear();
00239 itk::ExposeMetaData<std::string> ( *(*inputDict)[0], "0020|0032", tag );
00240 sscanf( tag.c_str(), "%f\\%f\\%f", &this->m_Output->xOrigin, &this->m_Output->yOrigin, &this->m_Output->zOrigin );
00241
00242 tag.clear();
00243 itk::ExposeMetaData<std::string> ( *(*inputDict)[0], "0018|0050", tag );
00244 this->m_Output->sliceThickness = atof( tag.c_str() );
00245
00246 tag.clear();
00247 itk::ExposeMetaData<std::string> ( *(*inputDict)[0], "0018|0088", tag );
00248 this->m_Output->sliceSpacing = atof( tag.c_str() );
00249
00250
00251
00252 for (int k = 0; k < m_nSlice; k++)
00253 {
00254 tag.clear();
00255 itk::ExposeMetaData<std::string> ( *(*inputDict)[k], "0020|1041", tag);
00256 float sliceLocation = atof( tag.c_str() );
00257 InsertUnique( m_sliceLocations, sliceLocation );
00258 }
00259
00260
00261
00262
00263
00264 tag.clear();
00265 itk::ExposeMetaData<std::string> ( *(*inputDict)[0], "0020|0037", tag );
00266 float xRow, yRow, zRow, xCol, yCol, zCol, xSlice, ySlice, zSlice ;
00267 sscanf( tag.c_str(), "%f\\%f\\%f\\%f\\%f\\%f", &xRow, &yRow, &zRow, &xCol, &yCol, &zCol );
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278 xRow = -xRow;
00279 yRow = -yRow;
00280
00281 xCol = -xCol;
00282 yCol = -yCol;
00283
00284
00285 xSlice = (yRow*zCol-zRow*yCol)*this->m_Output->sliceSpacing;
00286 ySlice = (zRow*xCol-xRow*zCol)*this->m_Output->sliceSpacing;
00287 zSlice = (xRow*yCol-yRow*xCol)*this->m_Output->sliceSpacing;
00288
00289 xRow *= this->m_Output->xRes;
00290 yRow *= this->m_Output->xRes;
00291 zRow *= this->m_Output->xRes;
00292
00293 xCol *= this->m_Output->yRes;
00294 yCol *= this->m_Output->yRes;
00295 zCol *= this->m_Output->yRes;
00296
00297 this->m_Output->xRow = xRow;
00298 this->m_Output->yRow = yRow;
00299 this->m_Output->zRow = zRow;
00300 this->m_Output->xCol = xCol;
00301 this->m_Output->yCol = yCol;
00302 this->m_Output->zCol = zCol;
00303 this->m_Output->xSlice = xSlice;
00304 this->m_Output->ySlice = ySlice;
00305 this->m_Output->zSlice = zSlice;
00306
00307 }
00308
00309
00310
00311
00312
00313
00314 void mitk::DicomDiffusionImageHeaderReader::ReadPublicTags2()
00315 {
00316
00317 if (!m_SliceOrderIS)
00318 {
00319 this->m_Output->xSlice = -this->m_Output->xSlice;
00320 this->m_Output->ySlice = -this->m_Output->ySlice;
00321 this->m_Output->zSlice = -this->m_Output->zSlice;
00322 }
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335 }
00336
00337 void mitk::DicomDiffusionImageHeaderReader::TransformGradients()
00338 {
00339
00340 if ( !m_SliceOrderIS )
00341 {
00342 this->m_Output->DiffusionVector[2] = -this->m_Output->DiffusionVector[2];
00343 }
00344 }
00345