00001 /*========================================================================= 00002 Copyright (c) German Cancer Research Center, Division of Medical and 00003 Biological Informatics. All rights reserved. 00004 See MITKCopyright.txt or https://www.mitk.org/copyright.html for details. 00005 00006 This software is distributed WITHOUT ANY WARRANTY; without even 00007 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00008 PURPOSE. See the above copyright notices for more information. 00009 00010 =========================================================================*/ 00011 00012 00013 #include "mitkSiemensDicomDiffusionImageHeaderReader.h" 00014 #include "gdcmGlobal.h" 00015 //#include <gdcmVersion.h> 00016 00017 #if GDCM_MAJOR_VERSION >= 2 00018 #define DGDCM2 00019 #endif 00020 00021 #ifndef DGDCM2 00022 00023 #include "gdcm.h" 00024 00025 #else 00026 00027 #include "gdcmFile.h" 00028 #include "gdcmImageReader.h" 00029 #include "gdcmDictEntry.h" 00030 #include "gdcmDicts.h" 00031 #include "gdcmTag.h" 00032 00033 #endif 00034 00035 mitk::SiemensDicomDiffusionImageHeaderReader::SiemensDicomDiffusionImageHeaderReader() 00036 { 00037 } 00038 00039 mitk::SiemensDicomDiffusionImageHeaderReader::~SiemensDicomDiffusionImageHeaderReader() 00040 { 00041 } 00042 00043 int mitk::SiemensDicomDiffusionImageHeaderReader::ExtractSiemensDiffusionInformation( std::string tagString, std::string nameString, std::vector<double>& valueArray, int startPos ) 00044 { 00045 std::string::size_type atPosition = tagString.find( nameString, startPos ); 00046 if ( atPosition == std::string::npos) 00047 { 00048 return 0; 00049 } 00050 else 00051 { 00052 std::string infoAsString = tagString.substr( atPosition, tagString.size()-atPosition+1 ); 00053 const char * infoAsCharPtr = infoAsString.c_str(); 00054 00055 int vm = *(infoAsCharPtr+64); 00056 std::string vr = infoAsString.substr( 68, 4 ); 00057 //int syngodt = *(infoAsCharPtr+72); 00058 //int nItems = *(infoAsCharPtr+76); 00059 //int localDummy = *(infoAsCharPtr+80); 00060 00061 int offset = 84; 00062 for (int k = 0; k < vm; k++) 00063 { 00064 int itemLength = *(infoAsCharPtr+offset+4); 00065 int strideSize = static_cast<int> (ceil(static_cast<double>(itemLength)/4) * 4); 00066 std::string valueString = infoAsString.substr( offset+16, itemLength ); 00067 valueArray.push_back( atof(valueString.c_str()) ); 00068 offset += 16+strideSize; 00069 } 00070 return vm; 00071 } 00072 } 00073 00074 int mitk::SiemensDicomDiffusionImageHeaderReader::ExtractSiemensDiffusionGradientInformation( std::string tagString, std::string nameString, std::vector<double>& valueArray ) 00075 { 00076 int nItems = 0; 00077 std::string::size_type pos = -1; 00078 while(nItems != 3) 00079 { 00080 nItems = ExtractSiemensDiffusionInformation( tagString, nameString, valueArray, pos+1 ); 00081 pos = tagString.find( nameString, pos+1 ); 00082 if ( pos == std::string::npos ) 00083 { 00084 break; 00085 } 00086 } 00087 return nItems; 00088 } 00089 00090 // do the work 00091 void mitk::SiemensDicomDiffusionImageHeaderReader::Update() 00092 { 00093 00094 // check if there are filenames 00095 if(m_DicomFilenames.size()) 00096 { 00097 // adapted from slicer 00098 // DicomToNrrdConverter.cxx 00099 00100 VolumeReaderType::DictionaryArrayRawPointer 00101 inputDict = m_VolumeReader->GetMetaDataDictionaryArray(); 00102 00103 #ifndef DGDCM2 00104 00105 // relevant Siemens private tags 00106 gdcm::DictEntry SiemensDictBValue( 0x0019, 0x100c, "IS", "1", "B Value of diffusion weighting" ); 00107 gdcm::DictEntry SiemensDictDiffusionDirection( 0x0019, 0x100e, "FD", "3", "Diffusion Gradient Direction" ); 00108 gdcm::DictEntry SiemensDictDiffusionMatrix( 0x0019, 0x1027, "FD", "6", "Diffusion Matrix" ); 00109 gdcm::DictEntry SiemensDictShadowInfo( 0x0029, 0x1010, "OB", "1", "Siemens DWI Info" ); 00110 00111 //if(gdcm::Global::GetDicts()->GetDefaultPubDict()->GetEntry(SiemensMosiacParameters.GetKey()) == 0) 00112 // gdcm::Global::GetDicts()->GetDefaultPubDict()->AddEntry(SiemensMosiacParameters); 00113 //if(gdcm::Global::GetDicts()->GetDefaultPubDict()->GetEntry(SiemensDictNMosiac.GetKey()) == 0) 00114 // gdcm::Global::GetDicts()->GetDefaultPubDict()->AddEntry(SiemensDictNMosiac); 00115 // 00116 00117 if(gdcm::Global::GetDicts()->GetDefaultPubDict()->GetEntry(SiemensDictBValue.GetName())==0) 00118 gdcm::Global::GetDicts()->GetDefaultPubDict()->AddEntry(SiemensDictBValue); 00119 if(gdcm::Global::GetDicts()->GetDefaultPubDict()->GetEntry(SiemensDictDiffusionDirection.GetName()) == 0) 00120 gdcm::Global::GetDicts()->GetDefaultPubDict()->AddEntry(SiemensDictDiffusionDirection); 00121 if(gdcm::Global::GetDicts()->GetDefaultPubDict()->GetEntry(SiemensDictDiffusionMatrix.GetName()) == 0) 00122 gdcm::Global::GetDicts()->GetDefaultPubDict()->AddEntry(SiemensDictDiffusionMatrix); 00123 if(gdcm::Global::GetDicts()->GetDefaultPubDict()->GetEntry(SiemensDictShadowInfo.GetName()) == 0) 00124 gdcm::Global::GetDicts()->GetDefaultPubDict()->AddEntry(SiemensDictShadowInfo); 00125 00126 #else 00127 00128 // gdcm::DictEntry SiemensDictBValue( "0019,100c", "B Value of diffusion weighting", gdcm::VR::IS, gdcm::VM::VM1 ); 00129 // gdcm::DictEntry SiemensDictDiffusionDirection( "0019,100e", "Diffusion Gradient Direction", gdcm::VR::FD, gdcm::VM::VM3 ); 00130 // gdcm::DictEntry SiemensDictDiffusionMatrix( "0019,1027", "Diffusion Matrix", gdcm::VR::FD, gdcm::VM::VM6 ); 00131 // gdcm::DictEntry SiemensDictShadowInfo( "0029,1010", "Siemens DWI Info", gdcm::VR::OB, gdcm::VM::VM1 ); 00132 00133 // //if(gdcm::Global::GetInstance().GetDicts().GetPublicDict().GetDictEntry(gdcm::Tag(0x0019,0x100c)) == 0) 00134 // gdcm::Global::GetInstance().GetDicts().GetPublicDict().AddDictEntry(gdcm::Tag(0x0019,0x100c),SiemensDictBValue); 00135 // if(gdcm::Global::GetDicts()->GetDefaultPubDict()->GetEntry(SiemensDictDiffusionDirection.GetName()) == 0) 00136 // gdcm::Global::GetDicts()->GetDefaultPubDict()->AddEntry(SiemensDictDiffusionDirection); 00137 // if(gdcm::Global::GetDicts()->GetDefaultPubDict()->GetEntry(SiemensDictDiffusionMatrix.GetName()) == 0) 00138 // gdcm::Global::GetDicts()->GetDefaultPubDict()->AddEntry(SiemensDictDiffusionMatrix); 00139 // if(gdcm::Global::GetDicts()->GetDefaultPubDict()->GetEntry(SiemensDictShadowInfo.GetName()) == 0) 00140 // gdcm::Global::GetDicts()->GetDefaultPubDict()->AddEntry(SiemensDictShadowInfo); 00141 00142 #endif 00143 00144 ReadPublicTags(); 00145 00146 //int mMosaic; // number of raws in each mosaic block; 00147 //int nMosaic; // number of columns in each mosaic block 00148 00149 float x0, y0, z0; 00150 float x1, y1, z1; 00151 std::string tag; 00152 tag.clear(); 00153 itk::ExposeMetaData<std::string> ( *(*inputDict)[0], "0020|0032", tag ); 00154 sscanf( tag.c_str(), "%f\\%f\\%f", &x0, &y0, &z0 ); 00155 //MITK_INFO << "Slice 0: " << tag << std::endl; 00156 tag.clear(); 00157 00158 // assume volume interleaving, i.e. the second dicom file stores 00159 // the second slice in the same volume as the first dicom file 00160 if((*inputDict).size() > 1) 00161 { 00162 itk::ExposeMetaData<std::string> ( *(*inputDict)[1], "0020|0032", tag ); 00163 sscanf( tag.c_str(), "%f\\%f\\%f", &x1, &y1, &z1 ); 00164 //MITK_INFO << "Slice 1: " << tag << std::endl; 00165 x1 -= x0; y1 -= y0; z1 -= z0; 00166 x0 = x1*this->m_Output->xSlice + y1*this->m_Output->ySlice + z1*this->m_Output->zSlice; 00167 if (x0 < 0) 00168 { 00169 m_SliceOrderIS = false; 00170 } 00171 } 00172 00173 ReadPublicTags2(); 00174 00175 int nStride = 1; 00176 //MITK_INFO << orthoSliceSpacing << std::endl; 00177 this->m_Output->nSliceInVolume = m_sliceLocations.size(); 00178 //nVolume = nSlice/this->m_Output->nSliceInVolume; 00179 //MITK_INFO << "Number of Slices: " << m_nSlice << std::endl; 00180 //MITK_INFO << "Number of Volume: " << nVolume << std::endl; 00181 //MITK_INFO << "Number of Slices in each volume: " << this->m_Output->nSliceInVolume << std::endl; 00182 nStride = this->m_Output->nSliceInVolume; 00183 00184 MITK_INFO << m_DicomFilenames[0] << std::endl; 00185 MITK_INFO << "Dims " << this->m_Output->nRows << "x" 00186 << this->m_Output->nCols << "x" << this->m_Output->nSliceInVolume << " " << std::endl; 00187 00188 for (int k = 0; k < m_nSlice; k += nStride ) 00189 { 00190 00191 #ifndef DGDCM2 00192 00193 gdcm::File *header0 = new gdcm::File; 00194 gdcm::BinEntry* binEntry; 00195 00196 header0->SetMaxSizeLoadEntry(65536); 00197 header0->SetFileName( m_DicomFilenames[k] ); 00198 header0->SetLoadMode( gdcm::LD_ALL ); 00199 header0->Load(); 00200 00201 // copy information stored in 0029,1010 into a string for parsing 00202 gdcm::DocEntry* docEntry = header0->GetFirstEntry(); 00203 while(docEntry) 00204 { 00205 if ( docEntry->GetKey() == "0029|1010" ) 00206 { 00207 binEntry = dynamic_cast<gdcm::BinEntry*> ( docEntry ); 00208 int binLength = binEntry->GetFullLength(); 00209 tag.resize( binLength ); 00210 uint8_t * tagString = binEntry->GetBinArea(); 00211 00212 for (int n = 0; n < binLength; n++) 00213 { 00214 tag[n] = *(tagString+n); 00215 } 00216 break; 00217 } 00218 docEntry = header0->GetNextEntry(); 00219 } 00220 00221 #else 00222 00223 gdcm::ImageReader reader; 00224 reader.SetFileName( m_DicomFilenames[k].c_str() ); 00225 if( !reader.Read() ) 00226 { 00227 itkExceptionMacro(<< "Cannot read requested file"); 00228 } 00229 const gdcm::File &f = reader.GetFile(); 00230 const gdcm::DataSet &ds = f.GetDataSet(); 00231 00232 // gdcm::DataSet ds = header0->GetDataSet(); 00233 gdcm::DataSet::ConstIterator it = ds.Begin(); 00234 00235 // Copy of the header->content 00236 // copy information stored in 0029,1010 into a string for parsing 00237 for(; it != ds.End(); ++it) 00238 { 00239 const gdcm::DataElement &ref = *it; 00240 if (ref.GetTag() == gdcm::Tag(0x0029,0x1010)) { 00241 tag = std::string(ref.GetByteValue()->GetPointer(),ref.GetByteValue()->GetLength()); 00242 } 00243 } 00244 00245 #endif 00246 00247 // parse B_value from 0029,1010 tag 00248 std::vector<double> valueArray(0); 00249 vnl_vector_fixed<double, 3> vect3d; 00250 int nItems = ExtractSiemensDiffusionInformation(tag, "B_value", valueArray); 00251 if (nItems != 1 || valueArray[0] == 0) // did not find enough information 00252 { 00253 tag.clear(); 00254 MITK_INFO << "Reading diffusion info from 0019|100c and 0019|100e tags" << std::endl; 00255 bool success = false; 00256 #ifndef DGDCM2 00257 success = itk::ExposeMetaData<std::string> ( *(*inputDict)[0], "0019|100c", tag ); 00258 this->m_Output->bValue = atof( tag.c_str() ); 00259 #else 00260 for(it = ds.Begin(); it != ds.End(); ++it) 00261 { 00262 const gdcm::DataElement &ref = *it; 00263 if (ref.GetTag() == gdcm::Tag(0x0019,0x100c)) { 00264 tag = std::string(ref.GetByteValue()->GetPointer(),ref.GetByteValue()->GetLength()); 00265 this->m_Output->bValue = atof( tag.c_str() ); 00266 success = true; 00267 } 00268 } 00269 #endif 00270 tag.clear(); 00271 if(success) 00272 { 00273 if(this->m_Output->bValue == 0) 00274 { 00275 MITK_INFO << "BV: 0 (Baseline image)"; 00276 continue; 00277 } 00278 #ifndef DGDCM2 00279 success = itk::ExposeMetaData<std::string> ( *(*inputDict)[k], "0019|100e", tag); 00280 #else 00281 success = false; 00282 for(it = ds.Begin(); it != ds.End(); ++it) 00283 { 00284 const gdcm::DataElement &ref = *it; 00285 if (ref.GetTag() == gdcm::Tag(0x0019,0x100e)) { 00286 tag = std::string(ref.GetByteValue()->GetPointer(),ref.GetByteValue()->GetLength()); 00287 success = true; 00288 } 00289 } 00290 #endif 00291 if(success) 00292 { 00293 memcpy( &vect3d[0], tag.c_str()+0, 8 ); 00294 memcpy( &vect3d[1], tag.c_str()+8, 8 ); 00295 memcpy( &vect3d[2], tag.c_str()+16, 8 ); 00296 vect3d.normalize(); 00297 this->m_Output->DiffusionVector = vect3d; 00298 TransformGradients(); 00299 MITK_INFO << "BV: " << this->m_Output->bValue; 00300 MITK_INFO << " GD: " << this->m_Output->DiffusionVector; 00301 continue; 00302 } 00303 } 00304 } 00305 else 00306 { 00307 MITK_INFO << "Reading diffusion info from 0029,1010 tag" << std::endl; 00308 this->m_Output->bValue = valueArray[0]; 00309 00310 if(this->m_Output->bValue == 0) 00311 { 00312 MITK_INFO << "BV: 0 (Baseline image)"; 00313 continue; 00314 } 00315 00316 valueArray.resize(0); 00317 nItems = ExtractSiemensDiffusionGradientInformation(tag, "DiffusionGradientDirection", valueArray); 00318 if (nItems == 3) 00319 { 00320 vect3d[0] = valueArray[0]; 00321 vect3d[1] = valueArray[1]; 00322 vect3d[2] = valueArray[2]; 00323 vect3d.normalize(); 00324 this->m_Output->DiffusionVector = vect3d; 00325 TransformGradients(); 00326 MITK_INFO << "BV: " << this->m_Output->bValue; 00327 MITK_INFO << " GD: " << this->m_Output->DiffusionVector; 00328 continue; 00329 } 00330 } 00331 00332 MITK_ERROR << "No diffusion info found, forcing to BASELINE image." << std::endl; 00333 this->m_Output->bValue = 0.0; 00334 vect3d.fill( 0.0 ); 00335 this->m_Output->DiffusionVector = vect3d; 00336 00337 } 00338 } 00339 } 00340 00341 //header = new mitk::DWIHeader(nRows, nCols, xRes, yRes, xOrigin,yOrigin, 00342 // zOrigin, sliceThickness, sliceSpacing,nSliceInVolume, xRow, yRow, 00343 // zRow, xCol,yCol, zCol, xSlice, ySlice, zSlice,bValues[0], DiffusionVectors[0], 00344 // vendor,SliceMosaic); 00345 00346 00347 // 00349 //void DicomDiffusionImageHeaderReader::Update() 00350 //{ 00351 // 00352 // // check if there are filenames 00353 // if(m_DicomFilenames.IsNotNull() 00354 // && m_DicomFilenames->size() > 0) 00355 // { 00356 // // adapted from namic-sandbox 00357 // // DicomToNrrdConverter.cxx 00358 // 00359 // bool SliceOrderIS = true; 00360 // bool SingleSeries = true; 00361 // 00362 // VolumeReaderType::DictionaryArrayRawPointer inputDict 00363 // = m_VolumeReader->GetMetaDataDictionaryArray(); 00364 // 00365 // if ( vendor.find("GE") != std::string::npos ) 00366 // { 00367 // // for GE data 00368 // if(gdcm::Global::GetDicts()->GetDefaultPubDict()->GetEntry(GEDictBValue.GetKey()) == 0) 00369 // gdcm::Global::GetDicts()->GetDefaultPubDict()->AddEntry(GEDictBValue); 00370 // if(gdcm::Global::GetDicts()->GetDefaultPubDict()->GetEntry(GEDictXGradient.GetKey()) == 0) 00371 // gdcm::Global::GetDicts()->GetDefaultPubDict()->AddEntry(GEDictXGradient); 00372 // if(gdcm::Global::GetDicts()->GetDefaultPubDict()->GetEntry(GEDictYGradient.GetKey()) == 0) 00373 // gdcm::Global::GetDicts()->GetDefaultPubDict()->AddEntry(GEDictYGradient); 00374 // if(gdcm::Global::GetDicts()->GetDefaultPubDict()->GetEntry(GEDictZGradient.GetKey()) == 0) 00375 // gdcm::Global::GetDicts()->GetDefaultPubDict()->AddEntry(GEDictZGradient); 00376 // } 00377 // else if( vendor.find("SIEMENS") != std::string::npos ) 00378 // { 00379 // // for Siemens data 00380 // if(gdcm::Global::GetDicts()->GetDefaultPubDict()->GetEntry(SiemensMosiacParameters.GetKey()) == 0) 00381 // gdcm::Global::GetDicts()->GetDefaultPubDict()->AddEntry(SiemensMosiacParameters); 00382 // if(gdcm::Global::GetDicts()->GetDefaultPubDict()->GetEntry(SiemensDictNMosiac.GetKey()) == 0) 00383 // gdcm::Global::GetDicts()->GetDefaultPubDict()->AddEntry(SiemensDictNMosiac); 00384 // if(gdcm::Global::GetDicts()->GetDefaultPubDict()->GetEntry(SiemensDictBValue.GetKey()) == 0) 00385 // gdcm::Global::GetDicts()->GetDefaultPubDict()->AddEntry(SiemensDictBValue); 00386 // if(gdcm::Global::GetDicts()->GetDefaultPubDict()->GetEntry(SiemensDictDiffusionDirection.GetKey()) == 0) 00387 // gdcm::Global::GetDicts()->GetDefaultPubDict()->AddEntry(SiemensDictDiffusionDirection); 00388 // if(gdcm::Global::GetDicts()->GetDefaultPubDict()->GetEntry(SiemensDictDiffusionMatrix.GetKey()) == 0) 00389 // gdcm::Global::GetDicts()->GetDefaultPubDict()->AddEntry(SiemensDictDiffusionMatrix); 00390 // if(gdcm::Global::GetDicts()->GetDefaultPubDict()->GetEntry(SiemensDictShadowInfo.GetKey()) == 0) 00391 // gdcm::Global::GetDicts()->GetDefaultPubDict()->AddEntry(SiemensDictShadowInfo); 00392 // 00393 // } 00394 // else if( vendor.find("PHILIPS") != std::string::npos ) 00395 // { 00396 // // for philips data 00397 // } 00398 // else 00399 // { 00400 // std::cerr << "Unrecognized vendor.\n" << std::endl; 00401 // } 00402 // 00403 // ReadPublicTags(); 00404 // 00405 // int mMosaic; // number of raws in each mosaic block; 00406 // int nMosaic; // number of columns in each mosaic block 00407 // int nSliceInVolume; 00408 // 00409 // // figure out slice order and mosaic arrangement. 00410 // if ( vendor.find("GE") != std::string::npos || 00411 // (vendor.find("SIEMENS") != std::string::npos && !SliceMosaic) ) 00412 // { 00413 // float x0, y0, z0; 00414 // float x1, y1, z1; 00415 // tag.clear(); 00416 // itk::ExposeMetaData<std::string> ( *(*inputDict)[0], "0020|0032", tag ); 00417 // sscanf( tag.c_str(), "%f\\%f\\%f", &x0, &y0, &z0 ); 00418 // MITK_INFO << "Slice 0: " << tag << std::endl; 00419 // tag.clear(); 00420 // 00421 // // assume volume interleaving, i.e. the second dicom file stores 00422 // // the second slice in the same volume as the first dicom file 00423 // itk::ExposeMetaData<std::string> ( *(*inputDict)[1], "0020|0032", tag ); 00424 // sscanf( tag.c_str(), "%f\\%f\\%f", &x1, &y1, &z1 ); 00425 // MITK_INFO << "Slice 1: " << tag << std::endl; 00426 // x1 -= x0; y1 -= y0; z1 -= z0; 00427 // x0 = x1*xSlice + y1*ySlice + z1*zSlice; 00428 // if (x0 < 0) 00429 // { 00430 // SliceOrderIS = false; 00431 // } 00432 // } 00433 // else if ( vendor.find("SIEMENS") != std::string::npos && SliceMosaic ) 00434 // { 00435 // MITK_INFO << "Siemens SliceMosaic......" << std::endl; 00436 // 00437 // SliceOrderIS = false; 00438 // 00439 // // for siemens mosaic image, figure out mosaic slice order from 0029|1010 00440 // tag.clear(); 00441 // gdcm::File *header0 = new gdcm::File; 00442 // gdcm::BinEntry* binEntry; 00443 // 00444 // header0->SetMaxSizeLoadEntry(65536); 00445 // header0->SetFileName( filenames[0] ); 00446 // header0->SetLoadMode( gdcm::LD_ALL ); 00447 // header0->Load(); 00448 // 00449 // // copy information stored in 0029,1010 into a string for parsing 00450 // gdcm::DocEntry* docEntry = header0->GetFirstEntry(); 00451 // while(docEntry) 00452 // { 00453 // if ( docEntry->GetKey() == "0029|1010" ) 00454 // { 00455 // binEntry = dynamic_cast<gdcm::BinEntry*> ( docEntry ); 00456 // int binLength = binEntry->GetFullLength(); 00457 // tag.resize( binLength ); 00458 // uint8_t * tagString = binEntry->GetBinArea(); 00459 // 00460 // for (int k = 0; k < binLength; k++) 00461 // { 00462 // tag[k] = *(tagString+k); 00463 // } 00464 // break; 00465 // } 00466 // docEntry = header0->GetNextEntry(); 00467 // } 00468 // 00469 // // parse SliceNormalVector from 0029,1010 tag 00470 // std::vector<double> valueArray(0); 00471 // int nItems = ExtractSiemensDiffusionInformation(tag, "SliceNormalVector", valueArray); 00472 // if (nItems != 3) // did not find enough information 00473 // { 00474 // MITK_INFO << "Warning: Cannot find complete information on SliceNormalVector in 0029|1010\n"; 00475 // MITK_INFO << " Slice order may be wrong.\n"; 00476 // } 00477 // else if (valueArray[2] > 0) 00478 // { 00479 // SliceOrderIS = true; 00480 // } 00481 // 00482 // // parse NumberOfImagesInMosaic from 0029,1010 tag 00483 // valueArray.resize(0); 00484 // nItems = ExtractSiemensDiffusionInformation(tag, "NumberOfImagesInMosaic", valueArray); 00485 // if (nItems == 0) // did not find enough information 00486 // { 00487 // MITK_INFO << "Warning: Cannot find complete information on NumberOfImagesInMosaic in 0029|1010\n"; 00488 // MITK_INFO << " Resulting image may contain empty slices.\n"; 00489 // } 00490 // else 00491 // { 00492 // nSliceInVolume = static_cast<int>(valueArray[0]); 00493 // mMosaic = static_cast<int> (ceil(sqrt(valueArray[0]))); 00494 // nMosaic = mMosaic; 00495 // } 00496 // MITK_INFO << "Mosaic in " << mMosaic << " X " << nMosaic << " blocks (total number of blocks = " << valueArray[0] << ").\n"; 00497 // } 00498 // else 00499 // { 00500 // } 00501 // 00502 // ReadPublicTags2(); 00503 // 00504 // //////////////////////////////////////////////////////////// 00505 // // vendor dependent tags. 00506 // // read in gradient vectors and determin nBaseline and nMeasurement 00507 // 00508 // if ( vendor.find("GE") != std::string::npos ) 00509 // { 00510 // nSliceInVolume = sliceLocations.size(); 00511 // nVolume = nSlice/nSliceInVolume; 00512 // 00513 // // assume volume interleaving 00514 // MITK_INFO << "Number of Slices: " << nSlice << std::endl; 00515 // MITK_INFO << "Number of Volume: " << nVolume << std::endl; 00516 // MITK_INFO << "Number of Slices in each volume: " << nSliceInVolume << std::endl; 00517 // 00518 // for (int k = 0; k < nSlice; k += nSliceInVolume) 00519 // { 00520 // tag.clear(); 00521 // bool exist = itk::ExposeMetaData<std::string> ( *(*inputDict)[k], "0043|1039", tag); 00522 // float b = atof( tag.c_str() ); 00523 // bValues.push_back(b); 00524 // 00525 // vnl_vector_fixed<double, 3> vect3d; 00526 // if (!exist || b == 0) 00527 // { 00528 // vect3d.fill( 0 ); 00529 // DiffusionVectors.push_back(vect3d); 00530 // DiffusionVectorsOrig.push_back(vect3d); 00531 // continue; 00532 // } 00533 // 00534 // vect3d.fill( 0 ); 00535 // tag.clear(); 00536 // itk::ExposeMetaData<std::string> ( *(*inputDict)[k], "0019|10bb", tag); 00537 // vect3d[0] = atof( tag.c_str() ); 00538 // 00539 // tag.clear(); 00540 // itk::ExposeMetaData<std::string> ( *(*inputDict)[k], "0019|10bc", tag); 00541 // vect3d[1] = atof( tag.c_str() ); 00542 // 00543 // tag.clear(); 00544 // itk::ExposeMetaData<std::string> ( *(*inputDict)[k], "0019|10bd", tag); 00545 // vect3d[2] = atof( tag.c_str() ); 00546 // 00547 // DiffusionVectorsOrig.push_back(vect3d); 00548 // vect3d.normalize(); 00549 // DiffusionVectors.push_back(vect3d); 00550 // } 00551 // } 00552 // else if ( vendor.find("SIEMENS") != std::string::npos ) 00553 // { 00554 // 00555 // int nStride = 1; 00556 // if ( !SliceMosaic ) 00557 // { 00558 // MITK_INFO << orthoSliceSpacing << std::endl; 00559 // nSliceInVolume = sliceLocations.size(); 00560 // nVolume = nSlice/nSliceInVolume; 00561 // MITK_INFO << "Number of Slices: " << nSlice << std::endl; 00562 // MITK_INFO << "Number of Volume: " << nVolume << std::endl; 00563 // MITK_INFO << "Number of Slices in each volume: " << nSliceInVolume << std::endl; 00564 // nStride = nSliceInVolume; 00565 // } 00566 // else 00567 // { 00568 // MITK_INFO << "Data in Siemens Mosaic Format\n"; 00569 // nVolume = nSlice; 00570 // MITK_INFO << "Number of Volume: " << nVolume << std::endl; 00571 // MITK_INFO << "Number of Slices in each volume: " << nSliceInVolume << std::endl; 00572 // nStride = 1; 00573 // } 00574 // 00575 // 00576 // for (int k = 0; k < nSlice; k += nStride ) 00577 // { 00578 // 00579 // gdcm::File *header0 = new gdcm::File; 00580 // gdcm::BinEntry* binEntry; 00581 // 00582 // header0->SetMaxSizeLoadEntry(65536); 00583 // header0->SetFileName( filenames[k] ); 00584 // header0->SetLoadMode( gdcm::LD_ALL ); 00585 // header0->Load(); 00586 // 00587 // // copy information stored in 0029,1010 into a string for parsing 00588 // gdcm::DocEntry* docEntry = header0->GetFirstEntry(); 00589 // while(docEntry) 00590 // { 00591 // if ( docEntry->GetKey() == "0029|1010" ) 00592 // { 00593 // binEntry = dynamic_cast<gdcm::BinEntry*> ( docEntry ); 00594 // int binLength = binEntry->GetFullLength(); 00595 // tag.resize( binLength ); 00596 // uint8_t * tagString = binEntry->GetBinArea(); 00597 // 00598 // for (int n = 0; n < binLength; n++) 00599 // { 00600 // tag[n] = *(tagString+n); 00601 // } 00602 // break; 00603 // } 00604 // docEntry = header0->GetNextEntry(); 00605 // } 00606 // 00607 // // parse B_value from 0029,1010 tag 00608 // std::vector<double> valueArray(0); 00609 // vnl_vector_fixed<double, 3> vect3d; 00610 // int nItems = ExtractSiemensDiffusionInformation(tag, "B_value", valueArray); 00611 // if (nItems != 1 || valueArray[0] == 0) // did not find enough information 00612 // { 00613 // MITK_INFO << "Warning: Cannot find complete information on B_value in 0029|1010\n"; 00614 // bValues.push_back( 0.0 ); 00615 // vect3d.fill( 0.0 ); 00616 // DiffusionVectors.push_back(vect3d); 00617 // DiffusionVectorsOrig.push_back(vect3d); 00618 // continue; 00619 // } 00620 // else 00621 // { 00622 // bValues.push_back( valueArray[0] ); 00623 // } 00624 // 00625 // // parse DiffusionGradientDirection from 0029,1010 tag 00626 // valueArray.resize(0); 00627 // nItems = ExtractSiemensDiffusionInformation(tag, "DiffusionGradientDirection", valueArray); 00628 // if (nItems != 3) // did not find enough information 00629 // { 00630 // MITK_INFO << "Warning: Cannot find complete information on DiffusionGradientDirection in 0029|1010\n"; 00631 // vect3d.fill( 0 ); 00632 // DiffusionVectors.push_back(vect3d); 00633 // DiffusionVectorsOrig.push_back(vect3d); 00634 // } 00635 // else 00636 // { 00637 // vect3d[0] = valueArray[0]; 00638 // vect3d[1] = valueArray[1]; 00639 // vect3d[2] = valueArray[2]; 00640 // DiffusionVectorsOrig.push_back(vect3d); 00641 // vect3d.normalize(); 00642 // DiffusionVectors.push_back(vect3d); 00643 // int p = bValues.size(); 00644 // MITK_INFO << "Image#: " << k << " BV: " << bValues[p-1] << " GD: " << DiffusionVectors[p-1] << std::endl; 00645 // } 00646 // } 00647 // } 00648 // else 00649 // { 00650 // } 00651 // 00652 // TransformGradients(); 00653 // 00654 // /////////////////////////////////////////////// 00655 // // construct header info 00656 // 00657 // header = new mitk::DWIHeader(nRows, nCols, xRes, yRes, xOrigin,yOrigin, 00658 // zOrigin, sliceThickness, sliceSpacing,nSliceInVolume, xRow, yRow, 00659 // zRow, xCol,yCol, zCol, xSlice, ySlice, zSlice,bValues[0], DiffusionVectors[0], 00660 // vendor,SliceMosaic); 00661 // 00662 // // set m_Output 00663 // 00664 // } 00665 // 00666 //} 00667 //