diff --git a/Modules/DiffusionImaging/DicomImport/mitkDicomDiffusionImageHeaderReader.h b/Modules/DiffusionImaging/DicomImport/mitkDicomDiffusionImageHeaderReader.h index 7ad1e89c05..077d697d69 100644 --- a/Modules/DiffusionImaging/DicomImport/mitkDicomDiffusionImageHeaderReader.h +++ b/Modules/DiffusionImaging/DicomImport/mitkDicomDiffusionImageHeaderReader.h @@ -1,114 +1,107 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2008-02-08 13:23:19 +0100 (Fr, 08 Feb 2008) $ Version: $Revision: 13561 $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef __mitkDicomDiffusionImageHeaderReader_h__ #define __mitkDicomDiffusionImageHeaderReader_h__ #include "MitkDiffusionImagingExports.h" #include #include "itkImageSeriesReader.h" #include "itkImageFileReader.h" #include "itkOrientedImage.h" #include "itkGDCMImageIO.h" #include "mitkDiffusionImageHeaderInformation.h" namespace mitk { class MitkDiffusionImaging_EXPORT DicomDiffusionImageHeaderReader : public itk::Object { public: mitkClassMacro( DicomDiffusionImageHeaderReader, itk::Object ); itkNewMacro(Self); enum SupportedVendors{ SV_SIEMENS, SV_SIEMENS_MOSAIC, SV_PHILIPS, SV_GE, SV_UNKNOWN_VENDOR }; typedef std::vector< std::string > FileNamesContainer; typedef short PixelValueType; typedef itk::OrientedImage< PixelValueType, 2 > SliceType; typedef itk::OrientedImage< PixelValueType, 3 > VolumeType; typedef itk::ImageSeriesReader< VolumeType > VolumeReaderType; typedef itk::ImageFileReader< SliceType > SliceReaderType; typedef itk::GDCMImageIO ImageIOType; - // set input + /// set input void SetSeriesDicomFilenames(FileNamesContainer dicomFilenames) { this->m_DicomFilenames = dicomFilenames; } void SetGdcmIO(ImageIOType::Pointer gdcmIO) { this->m_GdcmIO = gdcmIO; } void SetVolumeReader(VolumeReaderType::Pointer volumeReader) { this->m_VolumeReader = volumeReader; } void SetOutputPointer(DiffusionImageHeaderInformation::Pointer output) { this->m_Output = output; } - // do the work + /// do the work virtual void Update(); - // return output + /// return output DiffusionImageHeaderInformation::Pointer GetOutput(); - // identify vendor + /// identify vendor SupportedVendors GetVendorID(); - //virtual const char* GetFileName() const {return 0;} - //virtual void SetFileName(const char* aFileName) {} - //virtual const char* GetFilePrefix() const {return 0;} - //virtual void SetFilePrefix(const char* aFilePrefix) {} - //virtual const char* GetFilePattern() const {return 0;} - //virtual void SetFilePattern(const char* aFilePattern) {} - protected: DicomDiffusionImageHeaderReader(); virtual ~DicomDiffusionImageHeaderReader(); void ReadPublicTags(); void ReadPublicTags2(); void TransformGradients(); FileNamesContainer m_DicomFilenames; DiffusionImageHeaderInformation::Pointer m_Output; ImageIOType::Pointer m_GdcmIO; VolumeReaderType::Pointer m_VolumeReader; bool m_SliceOrderIS; bool m_SingleSeries; int m_nSlice; std::vector m_sliceLocations; }; } #endif diff --git a/Modules/DiffusionImaging/DicomImport/mitkDicomDiffusionImageReader.cpp b/Modules/DiffusionImaging/DicomImport/mitkDicomDiffusionImageReader.cpp index 855cd47ef7..b46d65347f 100644 --- a/Modules/DiffusionImaging/DicomImport/mitkDicomDiffusionImageReader.cpp +++ b/Modules/DiffusionImaging/DicomImport/mitkDicomDiffusionImageReader.cpp @@ -1,179 +1,142 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2009-07-14 19:11:20 +0200 (Tue, 14 Jul 2009) $ Version: $Revision: 18127 $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef __mitkDicomDiffusionImageReader_cpp #define __mitkDicomDiffusionImageReader_cpp #include "mitkDicomDiffusionImageReader.h" #include "itkImageSeriesReader.h" -//#include "itkImageFileReader.h" -//#include "itkImageRegion.h" -//#include "itkImageRegionIterator.h" -//#include "itkImageRegionConstIterator.h" -//#include "itkExceptionObject.h" -//#include "itkArray.h" -//#include "vnl/vnl_math.h" -//#include "itkProgressReporter.h" -//#include "itkMetaDataObject.h" + namespace mitk { -// Destructor - //template - //DicomDiffusionImageReader - // ::~DicomDiffusionImageReader() - //{ - // //// Clear the eventual previous content of the MetaDictionary array - // //if( m_MetaDataDictionaryArray.size() ) - // // { - // // for(unsigned int i=0; i void DicomDiffusionImageReader ::PrintSelf(std::ostream& os, itk::Indent indent) const { Superclass::PrintSelf(os, indent); } template void DicomDiffusionImageReader ::GenerateOutputInformation(void) { typename OutputImageType::Pointer output = this->GetOutput(); typedef itk::ImageSeriesReader ReaderType; // Read the first (or last) volume and use its size. if (m_Headers.size() > 0) { typename ReaderType::Pointer reader = ReaderType::New(); try { // Read the image reader->SetFileNames (m_Headers[0]->m_DicomFilenames); reader->UpdateOutputInformation(); output->SetSpacing( reader->GetOutput()->GetSpacing() ); // Set the image spacing output->SetOrigin( reader->GetOutput()->GetOrigin() ); // Set the image origin output->SetDirection( reader->GetOutput()->GetDirection() ); // Set the image direction output->SetLargestPossibleRegion( reader->GetOutput()->GetLargestPossibleRegion() ); output->SetVectorLength( m_Headers.size() ); } catch (itk::ExceptionObject &e) { throw e; } } else { itkExceptionMacro(<< "At least one filename is required." ); } } template void DicomDiffusionImageReader ::EnlargeOutputRequestedRegion(itk::DataObject *output) { typename OutputImageType::Pointer out = dynamic_cast(output); out->SetRequestedRegion( out->GetLargestPossibleRegion() ); } template void DicomDiffusionImageReader ::GenerateData() { typedef itk::ImageSeriesReader ReaderType; typename OutputImageType::Pointer output = this->GetOutput(); typedef typename OutputImageType::RegionType RegionType; RegionType requestedRegion = output->GetRequestedRegion(); // Each file must have the same size. SizeType validSize = requestedRegion.GetSize(); int numberOfVolumes = static_cast(m_Headers.size()); // Allocate the output buffer output->SetBufferedRegion( requestedRegion ); output->Allocate(); itk::ProgressReporter progress(this, 0, m_Headers.size(), m_Headers.size()); itk::ImageRegionIterator ot (output, requestedRegion ); - // Clear the eventual previous content of the MetaDictionary array - //if( m_MetaDataDictionaryArray.size() ) - // { - // for(unsigned int i=0; iSetFileNames(m_Headers[i]->m_DicomFilenames); reader->UpdateLargestPossibleRegion(); if (reader->GetOutput()->GetRequestedRegion().GetSize() != validSize) { itkExceptionMacro(<< "Size mismatch!"); } itk::ImageRegionConstIterator it (reader->GetOutput(), reader->GetOutput()->GetLargestPossibleRegion()); while (!it.IsAtEnd()) { vec = ot.Get(); vec.SetElement(i, it.Get()); ot.Set(vec); ++it; ++ot; } ot = ot.Begin(); progress.CompletedPixel(); } } } //namespace MITK #endif diff --git a/Modules/DiffusionImaging/DicomImport/mitkDicomDiffusionImageReader.h b/Modules/DiffusionImaging/DicomImport/mitkDicomDiffusionImageReader.h index 2c584c269c..6e9485cbd5 100644 --- a/Modules/DiffusionImaging/DicomImport/mitkDicomDiffusionImageReader.h +++ b/Modules/DiffusionImaging/DicomImport/mitkDicomDiffusionImageReader.h @@ -1,126 +1,102 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2009-07-14 19:11:20 +0200 (Tue, 14 Jul 2009) $ Version: $Revision: 18127 $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef __mitkDicomDiffusionImageReader_h #define __mitkDicomDiffusionImageReader_h #include "itkImageSource.h" #include "itkVectorImage.h" #include "mitkDiffusionImageHeaderInformation.h" #include "itkDataObject.h" #include "mitkCommon.h" -//#include "itkImageIOBase.h" -//#include "itkExceptionObject.h" -//#include "itkSize.h" -//#include "itkImageRegion.h" -//#include -//#include -//#include "itkMetaDataDictionary.h" - namespace mitk { /** \brief */ template class DicomDiffusionImageReader : public itk::ImageSource< itk::VectorImage< TPixelType, TDimension > > { public: typedef itk::VectorImage< TPixelType, TDimension > OutputImageType; typedef itk::Image InputImageType; typedef itk::ImageSource< OutputImageType > ImageSourceType; mitkClassMacro( DicomDiffusionImageReader, ImageSourceType ); itkNewMacro(Self); /** The size of the output image. */ typedef typename OutputImageType::SizeType SizeType; /** The region of the output image. */ typedef typename OutputImageType::RegionType ImageRegionType; - /** The dictionary type of the output image. */ - //typedef MetaDataDictionary DictionaryType; - //typedef MetaDataDictionary * DictionaryRawPointer; - //typedef std::vector< DictionaryRawPointer > DictionaryArrayType; - //typedef const DictionaryArrayType * DictionaryArrayRawPointer; - typedef std::vector HeaderContainer; /** Set the vector of strings that contains the file names. Files * are processed in sequential order. */ void SetHeaders (const HeaderContainer &headers) { if ( m_Headers != headers) { m_Headers = headers; this->Modified(); } } const HeaderContainer & GetHeaders() const { return m_Headers; } /** Prepare the allocation of the output image during the first back * propagation of the pipeline. */ virtual void GenerateOutputInformation(void); /** Give the reader a chance to indicate that it will produce more * output than it was requested to produce. ImageSeriesReader cannot * currently read a portion of an image (since the ImageIO objects * cannot read a portion of an image), so the ImageSeriesReader must * enlarge the RequestedRegion to the size of the image on disk. */ virtual void EnlargeOutputRequestedRegion(itk::DataObject *output); - /** Get access to the Array of MetaDataDictionaries */ - //DictionaryArrayRawPointer GetMetaDataDictionaryArray() const; - protected: - //DicomDiffusionImageReader(); - //~DicomDiffusionImageReader(); - void PrintSelf(std::ostream& os, itk::Indent indent) const; /** Does the real work. */ virtual void GenerateData(); /** A list of filenames to be processed. */ HeaderContainer m_Headers; /** The number of independent variables in the images that comprise * the series. */ int m_NumberOfDimensionsInImage; - /** Array of MetaDataDictionaries. This allows to hold information from the - * ImageIO objects after reading every sub image in the series */ - //DictionaryArrayType m_MetaDataDictionaryArray; private: - //DicomDiffusionImageReader(const Self&); //purposely not implemented void operator=(const Self&); //purposely not implemented }; } //namespace MITK #include "mitkDicomDiffusionImageReader.cpp" #endif // __mitkDicomDiffusionImageReader_h diff --git a/Modules/DiffusionImaging/DicomImport/mitkGEDicomDiffusionImageHeaderReader.cpp b/Modules/DiffusionImaging/DicomImport/mitkGEDicomDiffusionImageHeaderReader.cpp index 6cccaad051..7853875212 100644 --- a/Modules/DiffusionImaging/DicomImport/mitkGEDicomDiffusionImageHeaderReader.cpp +++ b/Modules/DiffusionImaging/DicomImport/mitkGEDicomDiffusionImageHeaderReader.cpp @@ -1,161 +1,148 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2007-12-11 14:46:19 +0100 (Di, 11 Dez 2007) $ Version: $Revision: 13129 $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include "mitkGEDicomDiffusionImageHeaderReader.h" #include "gdcmGlobal.h" -//#include "gdcmVersion.h" - #include "gdcmDict.h" #include "gdcmDicts.h" #include "gdcmDictEntry.h" #include "gdcmDictEntry.h" #include "gdcmDict.h" #include "gdcmFile.h" #include "gdcmSerieHelper.h" -//const gdcm::DictEntry GEDictBValue( "0043,1039", gdcm::VR::IS, gdcm::VM::VM1, "B Value of diffusion weighting" ); -//const gdcm::DictEntry GEDictXGradient( "0019,10bb", gdcm::VR::DS, gdcm::VM::VM1 , "X component of gradient direction" ); -//const gdcm::DictEntry GEDictYGradient( "0019,10bc", gdcm::VR::DS, gdcm::VM::VM1 , "Y component of gradient direction" ); -//const gdcm::DictEntry GEDictZGradient( "0019,10bd", gdcm::VR::DS, gdcm::VM::VM1 , "Z component of gradient direction" ); + mitk::GEDicomDiffusionImageHeaderReader::GEDicomDiffusionImageHeaderReader() { } mitk::GEDicomDiffusionImageHeaderReader::~GEDicomDiffusionImageHeaderReader() { } // do the work void mitk::GEDicomDiffusionImageHeaderReader::Update() { // check if there are filenames if(m_DicomFilenames.size()) { const std::string& locale = "C"; const std::string& currLocale = setlocale( LC_ALL, NULL ); if ( locale.compare(currLocale)!=0 ) { try { setlocale(LC_ALL, locale.c_str()); } catch(...) { MITK_INFO << "Could not set locale " << locale; } } // adapted from namic-sandbox // DicomToNrrdConverter.cxx VolumeReaderType::DictionaryArrayRawPointer inputDict = m_VolumeReader->GetMetaDataDictionaryArray(); ReadPublicTags(); - //int mMosaic; // number of raws in each mosaic block; - //int nMosaic; // number of columns in each mosaic block - float x0, y0, z0; float x1, y1, z1; std::string tag; tag.clear(); itk::ExposeMetaData ( *(*inputDict)[0], "0020|0032", tag ); sscanf( tag.c_str(), "%f\\%f\\%f", &x0, &y0, &z0 ); std::cout << "Slice 0: " << tag << std::endl; tag.clear(); // assume volume interleaving, i.e. the second dicom file stores // the second slice in the same volume as the first dicom file itk::ExposeMetaData ( *(*inputDict)[1], "0020|0032", tag ); sscanf( tag.c_str(), "%f\\%f\\%f", &x1, &y1, &z1 ); std::cout << "Slice 1: " << tag << std::endl; x1 -= x0; y1 -= y0; z1 -= z0; x0 = x1*this->m_Output->xSlice + y1*this->m_Output->ySlice + z1*this->m_Output->zSlice; if (x0 < 0) { m_SliceOrderIS = false; } ReadPublicTags2(); int nSliceInVolume; int nVolume; nSliceInVolume = m_sliceLocations.size(); nVolume = m_nSlice/nSliceInVolume; // assume volume interleaving std::cout << "Number of Slices: " << m_nSlice << std::endl; std::cout << "Number of Volume: " << nVolume << std::endl; std::cout << "Number of Slices in each volume: " << nSliceInVolume << std::endl; for (int k = 0; k < m_nSlice; k += nSliceInVolume) { tag.clear(); bool exist = itk::ExposeMetaData ( *(*inputDict)[k], "0043|1039", tag); float b = atof( tag.c_str() ); this->m_Output->bValue = b; vnl_vector_fixed vect3d; if (!exist || b == 0) { vect3d.fill( 0 ); this->m_Output->DiffusionVector = vect3d; continue; } vect3d.fill( 0 ); tag.clear(); itk::ExposeMetaData ( *(*inputDict)[k], "0019|10bb", tag); vect3d[0] = atof( tag.c_str() ); tag.clear(); itk::ExposeMetaData ( *(*inputDict)[k], "0019|10bc", tag); vect3d[1] = atof( tag.c_str() ); tag.clear(); itk::ExposeMetaData ( *(*inputDict)[k], "0019|10bd", tag); vect3d[2] = atof( tag.c_str() ); vect3d.normalize(); this->m_Output->DiffusionVector = vect3d; } TransformGradients(); try { setlocale(LC_ALL, currLocale.c_str()); } catch(...) { MITK_INFO << "Could not reset locale " << currLocale; } } } -//header = new mitk::DWIHeader(nRows, nCols, xRes, yRes, xOrigin,yOrigin, -// zOrigin, sliceThickness, sliceSpacing,nSliceInVolume, xRow, yRow, -// zRow, xCol,yCol, zCol, xSlice, ySlice, zSlice,bValues[0], DiffusionVectors[0], -// vendor,SliceMosaic); - diff --git a/Modules/DiffusionImaging/DicomImport/mitkSiemensDicomDiffusionImageHeaderReader.cpp b/Modules/DiffusionImaging/DicomImport/mitkSiemensDicomDiffusionImageHeaderReader.cpp index 017e089101..07cc5f2aaf 100644 --- a/Modules/DiffusionImaging/DicomImport/mitkSiemensDicomDiffusionImageHeaderReader.cpp +++ b/Modules/DiffusionImaging/DicomImport/mitkSiemensDicomDiffusionImageHeaderReader.cpp @@ -1,612 +1,259 @@ /*========================================================================= Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include "mitkSiemensDicomDiffusionImageHeaderReader.h" #include "gdcmGlobal.h" //#include #include "gdcmFile.h" #include "gdcmImageReader.h" #include "gdcmDictEntry.h" #include "gdcmDicts.h" #include "gdcmTag.h" mitk::SiemensDicomDiffusionImageHeaderReader::SiemensDicomDiffusionImageHeaderReader() { } mitk::SiemensDicomDiffusionImageHeaderReader::~SiemensDicomDiffusionImageHeaderReader() { } int mitk::SiemensDicomDiffusionImageHeaderReader::ExtractSiemensDiffusionInformation( std::string tagString, std::string nameString, std::vector& valueArray, int startPos ) { std::string::size_type atPosition = tagString.find( nameString, startPos ); if ( atPosition == std::string::npos) { return 0; } else { std::string infoAsString = tagString.substr( atPosition, tagString.size()-atPosition+1 ); const char * infoAsCharPtr = infoAsString.c_str(); int vm = *(infoAsCharPtr+64); - std::string vr = infoAsString.substr( 68, 4 ); - //int syngodt = *(infoAsCharPtr+72); - //int nItems = *(infoAsCharPtr+76); - //int localDummy = *(infoAsCharPtr+80); int offset = 84; for (int k = 0; k < vm; k++) { int itemLength = *(infoAsCharPtr+offset+4); int strideSize = static_cast (ceil(static_cast(itemLength)/4) * 4); std::string valueString = infoAsString.substr( offset+16, itemLength ); valueArray.push_back( atof(valueString.c_str()) ); offset += 16+strideSize; } return vm; } } int mitk::SiemensDicomDiffusionImageHeaderReader::ExtractSiemensDiffusionGradientInformation( std::string tagString, std::string nameString, std::vector& valueArray ) { int nItems = 0; std::string::size_type pos = -1; while(nItems != 3) { nItems = ExtractSiemensDiffusionInformation( tagString, nameString, valueArray, pos+1 ); pos = tagString.find( nameString, pos+1 ); if ( pos == std::string::npos ) { break; } } return nItems; } // do the work void mitk::SiemensDicomDiffusionImageHeaderReader::Update() { // check if there are filenames if(m_DicomFilenames.size()) { const std::string& locale = "C"; const std::string& currLocale = setlocale( LC_ALL, NULL ); if ( locale.compare(currLocale)!=0 ) { try { setlocale(LC_ALL, locale.c_str()); } catch(...) { MITK_INFO << "Could not set locale " << locale; } } // adapted from slicer // DicomToNrrdConverter.cxx VolumeReaderType::DictionaryArrayRawPointer inputDict = m_VolumeReader->GetMetaDataDictionaryArray(); - // gdcm::DictEntry SiemensDictBValue( "0019,100c", "B Value of diffusion weighting", gdcm::VR::IS, gdcm::VM::VM1 ); - // gdcm::DictEntry SiemensDictDiffusionDirection( "0019,100e", "Diffusion Gradient Direction", gdcm::VR::FD, gdcm::VM::VM3 ); - // gdcm::DictEntry SiemensDictDiffusionMatrix( "0019,1027", "Diffusion Matrix", gdcm::VR::FD, gdcm::VM::VM6 ); - // gdcm::DictEntry SiemensDictShadowInfo( "0029,1010", "Siemens DWI Info", gdcm::VR::OB, gdcm::VM::VM1 ); - - // //if(gdcm::Global::GetInstance().GetDicts().GetPublicDict().GetDictEntry(gdcm::Tag(0x0019,0x100c)) == 0) - // gdcm::Global::GetInstance().GetDicts().GetPublicDict().AddDictEntry(gdcm::Tag(0x0019,0x100c),SiemensDictBValue); - // if(gdcm::Global::GetDicts()->GetDefaultPubDict()->GetEntry(SiemensDictDiffusionDirection.GetName()) == 0) - // gdcm::Global::GetDicts()->GetDefaultPubDict()->AddEntry(SiemensDictDiffusionDirection); - // if(gdcm::Global::GetDicts()->GetDefaultPubDict()->GetEntry(SiemensDictDiffusionMatrix.GetName()) == 0) - // gdcm::Global::GetDicts()->GetDefaultPubDict()->AddEntry(SiemensDictDiffusionMatrix); - // if(gdcm::Global::GetDicts()->GetDefaultPubDict()->GetEntry(SiemensDictShadowInfo.GetName()) == 0) - // gdcm::Global::GetDicts()->GetDefaultPubDict()->AddEntry(SiemensDictShadowInfo); - ReadPublicTags(); - //int mMosaic; // number of raws in each mosaic block; - //int nMosaic; // number of columns in each mosaic block - float x0, y0, z0; float x1, y1, z1; std::string tag; tag.clear(); itk::ExposeMetaData ( *(*inputDict)[0], "0020|0032", tag ); sscanf( tag.c_str(), "%f\\%f\\%f", &x0, &y0, &z0 ); //MITK_INFO << "Slice 0: " << tag << std::endl; tag.clear(); // assume volume interleaving, i.e. the second dicom file stores // the second slice in the same volume as the first dicom file if((*inputDict).size() > 1) { itk::ExposeMetaData ( *(*inputDict)[1], "0020|0032", tag ); sscanf( tag.c_str(), "%f\\%f\\%f", &x1, &y1, &z1 ); //MITK_INFO << "Slice 1: " << tag << std::endl; x1 -= x0; y1 -= y0; z1 -= z0; x0 = x1*this->m_Output->xSlice + y1*this->m_Output->ySlice + z1*this->m_Output->zSlice; if (x0 < 0) { m_SliceOrderIS = false; } } ReadPublicTags2(); int nStride = 1; - //MITK_INFO << orthoSliceSpacing << std::endl; this->m_Output->nSliceInVolume = m_sliceLocations.size(); - //nVolume = nSlice/this->m_Output->nSliceInVolume; - //MITK_INFO << "Number of Slices: " << m_nSlice << std::endl; - //MITK_INFO << "Number of Volume: " << nVolume << std::endl; - //MITK_INFO << "Number of Slices in each volume: " << this->m_Output->nSliceInVolume << std::endl; + nStride = this->m_Output->nSliceInVolume; MITK_INFO << m_DicomFilenames[0] << std::endl; MITK_INFO << "Dims " << this->m_Output->nRows << "x" << this->m_Output->nCols << "x" << this->m_Output->nSliceInVolume << " " << std::endl; for (int k = 0; k < m_nSlice; k += nStride ) { gdcm::ImageReader reader; reader.SetFileName( m_DicomFilenames[k].c_str() ); if( !reader.Read() ) { itkExceptionMacro(<< "Cannot read requested file"); } const gdcm::File &f = reader.GetFile(); const gdcm::DataSet &ds = f.GetDataSet(); // gdcm::DataSet ds = header0->GetDataSet(); gdcm::DataSet::ConstIterator it = ds.Begin(); // Copy of the header->content // copy information stored in 0029,1010 into a string for parsing for(; it != ds.End(); ++it) { const gdcm::DataElement &ref = *it; if (ref.GetTag() == gdcm::Tag(0x0029,0x1010)) { tag = std::string(ref.GetByteValue()->GetPointer(),ref.GetByteValue()->GetLength()); } } // parse B_value from 0029,1010 tag std::vector valueArray(0); vnl_vector_fixed vect3d; int nItems = ExtractSiemensDiffusionInformation(tag, "B_value", valueArray); if (nItems != 1 || valueArray[0] == 0) // did not find enough information { tag.clear(); MITK_INFO << "Reading diffusion info from 0019|100c and 0019|100e tags" << std::endl; bool success = false; for(it = ds.Begin(); it != ds.End(); ++it) { const gdcm::DataElement &ref = *it; if (ref.GetTag() == gdcm::Tag(0x0019,0x100c)) { tag = std::string(ref.GetByteValue()->GetPointer(),ref.GetByteValue()->GetLength()); this->m_Output->bValue = atof( tag.c_str() ); success = true; } } tag.clear(); if(success) { if(this->m_Output->bValue == 0) { MITK_INFO << "BV: 0 (Baseline image)"; continue; } success = false; for(it = ds.Begin(); it != ds.End(); ++it) { const gdcm::DataElement &ref = *it; if (ref.GetTag() == gdcm::Tag(0x0019,0x100e)) { tag = std::string(ref.GetByteValue()->GetPointer(),ref.GetByteValue()->GetLength()); success = true; } } if(success) { memcpy( &vect3d[0], tag.c_str()+0, 8 ); memcpy( &vect3d[1], tag.c_str()+8, 8 ); memcpy( &vect3d[2], tag.c_str()+16, 8 ); vect3d.normalize(); this->m_Output->DiffusionVector = vect3d; TransformGradients(); MITK_INFO << "BV: " << this->m_Output->bValue; MITK_INFO << " GD: " << this->m_Output->DiffusionVector; continue; } } } else { MITK_INFO << "Reading diffusion info from 0029,1010 tag" << std::endl; this->m_Output->bValue = valueArray[0]; if(this->m_Output->bValue == 0) { MITK_INFO << "BV: 0 (Baseline image)"; continue; } valueArray.resize(0); nItems = ExtractSiemensDiffusionGradientInformation(tag, "DiffusionGradientDirection", valueArray); if (nItems == 3) { vect3d[0] = valueArray[0]; vect3d[1] = valueArray[1]; vect3d[2] = valueArray[2]; vect3d.normalize(); this->m_Output->DiffusionVector = vect3d; TransformGradients(); MITK_INFO << "BV: " << this->m_Output->bValue; MITK_INFO << " GD: " << this->m_Output->DiffusionVector; continue; } } MITK_ERROR << "No diffusion info found, forcing to BASELINE image." << std::endl; this->m_Output->bValue = 0.0; vect3d.fill( 0.0 ); this->m_Output->DiffusionVector = vect3d; } try { setlocale(LC_ALL, currLocale.c_str()); } catch(...) { MITK_INFO << "Could not reset locale " << currLocale; } } } - -//header = new mitk::DWIHeader(nRows, nCols, xRes, yRes, xOrigin,yOrigin, -// zOrigin, sliceThickness, sliceSpacing,nSliceInVolume, xRow, yRow, -// zRow, xCol,yCol, zCol, xSlice, ySlice, zSlice,bValues[0], DiffusionVectors[0], -// vendor,SliceMosaic); - - -// -//// do the work -//void DicomDiffusionImageHeaderReader::Update() -//{ -// -// // check if there are filenames -// if(m_DicomFilenames.IsNotNull() -// && m_DicomFilenames->size() > 0) -// { -// // adapted from namic-sandbox -// // DicomToNrrdConverter.cxx -// -// bool SliceOrderIS = true; -// bool SingleSeries = true; -// -// VolumeReaderType::DictionaryArrayRawPointer inputDict -// = m_VolumeReader->GetMetaDataDictionaryArray(); -// -// if ( vendor.find("GE") != std::string::npos ) -// { -// // for GE data -// if(gdcm::Global::GetDicts()->GetDefaultPubDict()->GetEntry(GEDictBValue.GetKey()) == 0) -// gdcm::Global::GetDicts()->GetDefaultPubDict()->AddEntry(GEDictBValue); -// if(gdcm::Global::GetDicts()->GetDefaultPubDict()->GetEntry(GEDictXGradient.GetKey()) == 0) -// gdcm::Global::GetDicts()->GetDefaultPubDict()->AddEntry(GEDictXGradient); -// if(gdcm::Global::GetDicts()->GetDefaultPubDict()->GetEntry(GEDictYGradient.GetKey()) == 0) -// gdcm::Global::GetDicts()->GetDefaultPubDict()->AddEntry(GEDictYGradient); -// if(gdcm::Global::GetDicts()->GetDefaultPubDict()->GetEntry(GEDictZGradient.GetKey()) == 0) -// gdcm::Global::GetDicts()->GetDefaultPubDict()->AddEntry(GEDictZGradient); -// } -// else if( vendor.find("SIEMENS") != std::string::npos ) -// { -// // for Siemens data -// if(gdcm::Global::GetDicts()->GetDefaultPubDict()->GetEntry(SiemensMosiacParameters.GetKey()) == 0) -// gdcm::Global::GetDicts()->GetDefaultPubDict()->AddEntry(SiemensMosiacParameters); -// if(gdcm::Global::GetDicts()->GetDefaultPubDict()->GetEntry(SiemensDictNMosiac.GetKey()) == 0) -// gdcm::Global::GetDicts()->GetDefaultPubDict()->AddEntry(SiemensDictNMosiac); -// if(gdcm::Global::GetDicts()->GetDefaultPubDict()->GetEntry(SiemensDictBValue.GetKey()) == 0) -// gdcm::Global::GetDicts()->GetDefaultPubDict()->AddEntry(SiemensDictBValue); -// if(gdcm::Global::GetDicts()->GetDefaultPubDict()->GetEntry(SiemensDictDiffusionDirection.GetKey()) == 0) -// gdcm::Global::GetDicts()->GetDefaultPubDict()->AddEntry(SiemensDictDiffusionDirection); -// if(gdcm::Global::GetDicts()->GetDefaultPubDict()->GetEntry(SiemensDictDiffusionMatrix.GetKey()) == 0) -// gdcm::Global::GetDicts()->GetDefaultPubDict()->AddEntry(SiemensDictDiffusionMatrix); -// if(gdcm::Global::GetDicts()->GetDefaultPubDict()->GetEntry(SiemensDictShadowInfo.GetKey()) == 0) -// gdcm::Global::GetDicts()->GetDefaultPubDict()->AddEntry(SiemensDictShadowInfo); -// -// } -// else if( vendor.find("PHILIPS") != std::string::npos ) -// { -// // for philips data -// } -// else -// { -// std::cerr << "Unrecognized vendor.\n" << std::endl; -// } -// -// ReadPublicTags(); -// -// int mMosaic; // number of raws in each mosaic block; -// int nMosaic; // number of columns in each mosaic block -// int nSliceInVolume; -// -// // figure out slice order and mosaic arrangement. -// if ( vendor.find("GE") != std::string::npos || -// (vendor.find("SIEMENS") != std::string::npos && !SliceMosaic) ) -// { -// float x0, y0, z0; -// float x1, y1, z1; -// tag.clear(); -// itk::ExposeMetaData ( *(*inputDict)[0], "0020|0032", tag ); -// sscanf( tag.c_str(), "%f\\%f\\%f", &x0, &y0, &z0 ); -// MITK_INFO << "Slice 0: " << tag << std::endl; -// tag.clear(); -// -// // assume volume interleaving, i.e. the second dicom file stores -// // the second slice in the same volume as the first dicom file -// itk::ExposeMetaData ( *(*inputDict)[1], "0020|0032", tag ); -// sscanf( tag.c_str(), "%f\\%f\\%f", &x1, &y1, &z1 ); -// MITK_INFO << "Slice 1: " << tag << std::endl; -// x1 -= x0; y1 -= y0; z1 -= z0; -// x0 = x1*xSlice + y1*ySlice + z1*zSlice; -// if (x0 < 0) -// { -// SliceOrderIS = false; -// } -// } -// else if ( vendor.find("SIEMENS") != std::string::npos && SliceMosaic ) -// { -// MITK_INFO << "Siemens SliceMosaic......" << std::endl; -// -// SliceOrderIS = false; -// -// // for siemens mosaic image, figure out mosaic slice order from 0029|1010 -// tag.clear(); -// gdcm::File *header0 = new gdcm::File; -// gdcm::BinEntry* binEntry; -// -// header0->SetMaxSizeLoadEntry(65536); -// header0->SetFileName( filenames[0] ); -// header0->SetLoadMode( gdcm::LD_ALL ); -// header0->Load(); -// -// // copy information stored in 0029,1010 into a string for parsing -// gdcm::DocEntry* docEntry = header0->GetFirstEntry(); -// while(docEntry) -// { -// if ( docEntry->GetKey() == "0029|1010" ) -// { -// binEntry = dynamic_cast ( docEntry ); -// int binLength = binEntry->GetFullLength(); -// tag.resize( binLength ); -// uint8_t * tagString = binEntry->GetBinArea(); -// -// for (int k = 0; k < binLength; k++) -// { -// tag[k] = *(tagString+k); -// } -// break; -// } -// docEntry = header0->GetNextEntry(); -// } -// -// // parse SliceNormalVector from 0029,1010 tag -// std::vector valueArray(0); -// int nItems = ExtractSiemensDiffusionInformation(tag, "SliceNormalVector", valueArray); -// if (nItems != 3) // did not find enough information -// { -// MITK_INFO << "Warning: Cannot find complete information on SliceNormalVector in 0029|1010\n"; -// MITK_INFO << " Slice order may be wrong.\n"; -// } -// else if (valueArray[2] > 0) -// { -// SliceOrderIS = true; -// } -// -// // parse NumberOfImagesInMosaic from 0029,1010 tag -// valueArray.resize(0); -// nItems = ExtractSiemensDiffusionInformation(tag, "NumberOfImagesInMosaic", valueArray); -// if (nItems == 0) // did not find enough information -// { -// MITK_INFO << "Warning: Cannot find complete information on NumberOfImagesInMosaic in 0029|1010\n"; -// MITK_INFO << " Resulting image may contain empty slices.\n"; -// } -// else -// { -// nSliceInVolume = static_cast(valueArray[0]); -// mMosaic = static_cast (ceil(sqrt(valueArray[0]))); -// nMosaic = mMosaic; -// } -// MITK_INFO << "Mosaic in " << mMosaic << " X " << nMosaic << " blocks (total number of blocks = " << valueArray[0] << ").\n"; -// } -// else -// { -// } -// -// ReadPublicTags2(); -// -// //////////////////////////////////////////////////////////// -// // vendor dependent tags. -// // read in gradient vectors and determin nBaseline and nMeasurement -// -// if ( vendor.find("GE") != std::string::npos ) -// { -// nSliceInVolume = sliceLocations.size(); -// nVolume = nSlice/nSliceInVolume; -// -// // assume volume interleaving -// MITK_INFO << "Number of Slices: " << nSlice << std::endl; -// MITK_INFO << "Number of Volume: " << nVolume << std::endl; -// MITK_INFO << "Number of Slices in each volume: " << nSliceInVolume << std::endl; -// -// for (int k = 0; k < nSlice; k += nSliceInVolume) -// { -// tag.clear(); -// bool exist = itk::ExposeMetaData ( *(*inputDict)[k], "0043|1039", tag); -// float b = atof( tag.c_str() ); -// bValues.push_back(b); -// -// vnl_vector_fixed vect3d; -// if (!exist || b == 0) -// { -// vect3d.fill( 0 ); -// DiffusionVectors.push_back(vect3d); -// DiffusionVectorsOrig.push_back(vect3d); -// continue; -// } -// -// vect3d.fill( 0 ); -// tag.clear(); -// itk::ExposeMetaData ( *(*inputDict)[k], "0019|10bb", tag); -// vect3d[0] = atof( tag.c_str() ); -// -// tag.clear(); -// itk::ExposeMetaData ( *(*inputDict)[k], "0019|10bc", tag); -// vect3d[1] = atof( tag.c_str() ); -// -// tag.clear(); -// itk::ExposeMetaData ( *(*inputDict)[k], "0019|10bd", tag); -// vect3d[2] = atof( tag.c_str() ); -// -// DiffusionVectorsOrig.push_back(vect3d); -// vect3d.normalize(); -// DiffusionVectors.push_back(vect3d); -// } -// } -// else if ( vendor.find("SIEMENS") != std::string::npos ) -// { -// -// int nStride = 1; -// if ( !SliceMosaic ) -// { -// MITK_INFO << orthoSliceSpacing << std::endl; -// nSliceInVolume = sliceLocations.size(); -// nVolume = nSlice/nSliceInVolume; -// MITK_INFO << "Number of Slices: " << nSlice << std::endl; -// MITK_INFO << "Number of Volume: " << nVolume << std::endl; -// MITK_INFO << "Number of Slices in each volume: " << nSliceInVolume << std::endl; -// nStride = nSliceInVolume; -// } -// else -// { -// MITK_INFO << "Data in Siemens Mosaic Format\n"; -// nVolume = nSlice; -// MITK_INFO << "Number of Volume: " << nVolume << std::endl; -// MITK_INFO << "Number of Slices in each volume: " << nSliceInVolume << std::endl; -// nStride = 1; -// } -// -// -// for (int k = 0; k < nSlice; k += nStride ) -// { -// -// gdcm::File *header0 = new gdcm::File; -// gdcm::BinEntry* binEntry; -// -// header0->SetMaxSizeLoadEntry(65536); -// header0->SetFileName( filenames[k] ); -// header0->SetLoadMode( gdcm::LD_ALL ); -// header0->Load(); -// -// // copy information stored in 0029,1010 into a string for parsing -// gdcm::DocEntry* docEntry = header0->GetFirstEntry(); -// while(docEntry) -// { -// if ( docEntry->GetKey() == "0029|1010" ) -// { -// binEntry = dynamic_cast ( docEntry ); -// int binLength = binEntry->GetFullLength(); -// tag.resize( binLength ); -// uint8_t * tagString = binEntry->GetBinArea(); -// -// for (int n = 0; n < binLength; n++) -// { -// tag[n] = *(tagString+n); -// } -// break; -// } -// docEntry = header0->GetNextEntry(); -// } -// -// // parse B_value from 0029,1010 tag -// std::vector valueArray(0); -// vnl_vector_fixed vect3d; -// int nItems = ExtractSiemensDiffusionInformation(tag, "B_value", valueArray); -// if (nItems != 1 || valueArray[0] == 0) // did not find enough information -// { -// MITK_INFO << "Warning: Cannot find complete information on B_value in 0029|1010\n"; -// bValues.push_back( 0.0 ); -// vect3d.fill( 0.0 ); -// DiffusionVectors.push_back(vect3d); -// DiffusionVectorsOrig.push_back(vect3d); -// continue; -// } -// else -// { -// bValues.push_back( valueArray[0] ); -// } -// -// // parse DiffusionGradientDirection from 0029,1010 tag -// valueArray.resize(0); -// nItems = ExtractSiemensDiffusionInformation(tag, "DiffusionGradientDirection", valueArray); -// if (nItems != 3) // did not find enough information -// { -// MITK_INFO << "Warning: Cannot find complete information on DiffusionGradientDirection in 0029|1010\n"; -// vect3d.fill( 0 ); -// DiffusionVectors.push_back(vect3d); -// DiffusionVectorsOrig.push_back(vect3d); -// } -// else -// { -// vect3d[0] = valueArray[0]; -// vect3d[1] = valueArray[1]; -// vect3d[2] = valueArray[2]; -// DiffusionVectorsOrig.push_back(vect3d); -// vect3d.normalize(); -// DiffusionVectors.push_back(vect3d); -// int p = bValues.size(); -// MITK_INFO << "Image#: " << k << " BV: " << bValues[p-1] << " GD: " << DiffusionVectors[p-1] << std::endl; -// } -// } -// } -// else -// { -// } -// -// TransformGradients(); -// -// /////////////////////////////////////////////// -// // construct header info -// -// header = new mitk::DWIHeader(nRows, nCols, xRes, yRes, xOrigin,yOrigin, -// zOrigin, sliceThickness, sliceSpacing,nSliceInVolume, xRow, yRow, -// zRow, xCol,yCol, zCol, xSlice, ySlice, zSlice,bValues[0], DiffusionVectors[0], -// vendor,SliceMosaic); -// -// // set m_Output -// -// } -// -//} -//