diff --git a/Modules/DiffusionImaging/DiffusionCore/DicomImport/mitkDiffusionDICOMFileReader.cpp b/Modules/DiffusionImaging/DiffusionCore/DicomImport/mitkDiffusionDICOMFileReader.cpp index c93b140910..0a01784044 100644 --- a/Modules/DiffusionImaging/DiffusionCore/DicomImport/mitkDiffusionDICOMFileReader.cpp +++ b/Modules/DiffusionImaging/DiffusionCore/DicomImport/mitkDiffusionDICOMFileReader.cpp @@ -1,135 +1,185 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "mitkDiffusionDICOMFileReader.h" -#include "mitkDiffusionHeaderDICOMFileReader.h" +#include "mitkDiffusionDICOMFileReaderHelper.h" #include "mitkDiffusionHeaderSiemensDICOMFileReader.h" #include "mitkDiffusionHeaderSiemensMosaicDICOMFileReader.h" +static void PerformHeaderAnalysis( mitk::DiffusionHeaderDICOMFileReader::DICOMHeaderListType headers ) +{ + unsigned int images = headers.size(); + + unsigned int unweighted_images = 0; + unsigned int weighted_images = 0; + + mitk::DiffusionHeaderDICOMFileReader::DICOMHeaderListType::const_iterator c_iter = headers.begin(); + while( c_iter != headers.end() ) + { + const mitk::DiffusionImageDICOMHeaderInformation h = *c_iter; + if( h.baseline ) unweighted_images++; + if( h.b_value > 0 ) weighted_images++; + + ++c_iter; + } + + MITK_INFO << " :: Analyzed volumes " << images << "\n" + << " :: \t"<< unweighted_images << " b = 0" << "\n" + << " :: \t"<< weighted_images << " b > 0"; +} + mitk::DiffusionDICOMFileReader::DiffusionDICOMFileReader() { } mitk::DiffusionDICOMFileReader::~DiffusionDICOMFileReader() { } bool mitk::DiffusionDICOMFileReader ::LoadImages() { + // prepare data reading + DiffusionDICOMFileReaderHelper helper; + DiffusionDICOMFileReaderHelper::VolumeFileNamesContainer filenames; + + const size_t number_of_outputs = this->GetNumberOfOutputs(); + + for( size_t idx = 0; idx < number_of_outputs; idx++ ) + { + DICOMImageFrameList flist = this->GetOutput(idx).GetImageFrameList(); + + std::vector< std::string > FileNamesPerVolume; + + DICOMImageFrameList::const_iterator cIt = flist.begin(); + while( cIt != flist.end() ) + { + FileNamesPerVolume.push_back( (*cIt)->Filename ); + ++cIt; + } + + filenames.push_back( FileNamesPerVolume ); + } + + helper.LoadToVector( filenames ); + + } void mitk::DiffusionDICOMFileReader ::AnalyzeInputFiles() { Superclass::AnalyzeInputFiles(); // collect output from superclass size_t number_of_outputs = this->GetNumberOfOutputs(); if(number_of_outputs == 0) { MITK_ERROR << "Failed to parse input, retrieved 0 outputs from SeriesGDCMReader "; } DICOMImageBlockDescriptor block_0 = this->GetOutput(0); MITK_INFO << "Retrieved " << number_of_outputs << "outputs."; // collect vendor ID from the first output, first image StringList inputFilename; DICOMImageFrameInfo::Pointer frame_0 = block_0.GetImageFrameList().at(0); inputFilename.push_back( frame_0->Filename ); gdcm::Scanner gdcmScanner; gdcm::Tag t_vendor(0x008, 0x0070); gdcm::Tag t_imagetype(0x008, 0x008); // add DICOM Tag for vendor gdcmScanner.AddTag( t_vendor ); // add DICOM Tag for image type gdcmScanner.AddTag( t_imagetype ); gdcmScanner.Scan( inputFilename ); // retrieve both vendor and image type std::string vendor = gdcmScanner.GetValue( frame_0->Filename.c_str(), t_vendor ); std::string image_type = gdcmScanner.GetValue( frame_0->Filename.c_str(), t_imagetype ); MITK_INFO << "Got vendor: " << vendor << " image type " << image_type; mitk::DiffusionHeaderDICOMFileReader::Pointer header_reader; // parse vendor tag if( vendor.find("SIEMENS") != std::string::npos ) { if( image_type.find("MOSAIC") != std::string::npos ) { header_reader = mitk::DiffusionHeaderSiemensMosaicDICOMFileReader::New(); } else { header_reader = mitk::DiffusionHeaderSiemensDICOMFileReader::New(); } } else if( vendor.find("GE") != std::string::npos ) { } else if( vendor.find("PHILIPS") != std::string::npos ) { } else { // unknown vendor } if( header_reader.IsNull() ) { MITK_ERROR << "No header reader for given vendor. "; return; } bool canread = false; for( size_t idx; idx < number_of_outputs; idx++ ) { DICOMImageFrameInfo::Pointer frame = this->GetOutput( idx ).GetImageFrameList().at(0); canread = header_reader->ReadDiffusionHeader(frame->Filename); - - MITK_INFO << "Can read ()" << idx << " value: " << canread; - - canread = false; } + // collect the information + m_RetrievedHeader = header_reader->GetHeaderInformation(); + + // TODO : Analyze outputs + header information, i.e. for the loading confidence + MITK_INFO << "----- Diffusion DICOM Analysis Report ---- "; + PerformHeaderAnalysis( m_RetrievedHeader ); + MITK_INFO << "==========================================="; } bool mitk::DiffusionDICOMFileReader ::CanHandleFile(const std::string &filename) { } diff --git a/Modules/DiffusionImaging/DiffusionCore/DicomImport/mitkDiffusionDICOMFileReader.h b/Modules/DiffusionImaging/DiffusionCore/DicomImport/mitkDiffusionDICOMFileReader.h index 2435079868..5ed962aa3c 100644 --- a/Modules/DiffusionImaging/DiffusionCore/DicomImport/mitkDiffusionDICOMFileReader.h +++ b/Modules/DiffusionImaging/DiffusionCore/DicomImport/mitkDiffusionDICOMFileReader.h @@ -1,50 +1,53 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef MITKDIFFUSIONDICOMFILEREADER_H #define MITKDIFFUSIONDICOMFILEREADER_H #include "DiffusionCoreExports.h" #include "mitkDICOMITKSeriesGDCMReader.h" +#include "mitkDiffusionHeaderDICOMFileReader.h" namespace mitk { class DiffusionCore_EXPORT DiffusionDICOMFileReader : public DICOMITKSeriesGDCMReader { public: mitkClassMacro( DiffusionDICOMFileReader, DICOMITKSeriesGDCMReader ) mitkCloneMacro( DiffusionDICOMFileReader ) itkNewMacro( DiffusionDICOMFileReader ) virtual void AnalyzeInputFiles(); virtual bool LoadImages(); virtual bool CanHandleFile(const std::string &filename); protected: DiffusionDICOMFileReader(); virtual ~DiffusionDICOMFileReader(); + + mitk::DiffusionHeaderDICOMFileReader::DICOMHeaderListType m_RetrievedHeader; }; } #endif // MITKDIFFUSIONDICOMFILEREADER_H diff --git a/Modules/DiffusionImaging/DiffusionCore/DicomImport/mitkDiffusionDICOMFileReaderHelper.h b/Modules/DiffusionImaging/DiffusionCore/DicomImport/mitkDiffusionDICOMFileReaderHelper.h new file mode 100644 index 0000000000..b6861ee4af --- /dev/null +++ b/Modules/DiffusionImaging/DiffusionCore/DicomImport/mitkDiffusionDICOMFileReaderHelper.h @@ -0,0 +1,101 @@ +#ifndef MITKDIFFUSIONDICOMFILEREADERHELPER_H +#define MITKDIFFUSIONDICOMFILEREADERHELPER_H + +#include "mitkDiffusionImage.h" + +#include "itkImageSeriesReader.h" +#include "itkVectorImage.h" + +namespace mitk +{ + +class DiffusionDICOMFileReaderHelper +{ +public: + typedef std::vector< std::string > StringContainer; + + typedef std::vector< StringContainer > VolumeFileNamesContainer; + + + + template< typename PixelType, unsigned int VecImageDimension> + typename itk::VectorImage< PixelType, VecImageDimension >::Pointer LoadToVector( + const VolumeFileNamesContainer& filenames + //const itk::ImageBase<3>::RegionType requestedRegion + ) + { + typedef itk::Image< PixelType, 3> InputImageType; + typedef itk::ImageSeriesReader< InputImageType > SeriesReaderType; + + typename SeriesReaderType::Pointer probe_reader = SeriesReaderType::New(); + probe_reader->SetFileNames( filenames.at(0) ); + probe_reader->GenerateOutputInformation(); + const itk::ImageBase<3>::RegionType requestedRegion = probe_reader->GetOutput()->GetLargestPossibleRegion(); + + MITK_INFO << " --- Probe reader : \n" << + " Retrieved LPR " << requestedRegion; + + typedef itk::VectorImage< PixelType, 3 > VectorImageType; + + typename VectorImageType::Pointer output_image = VectorImageType::New(); + output_image->SetNumberOfComponentsPerPixel( filenames.size() ); + output_image->SetBufferedRegion( requestedRegion ); + output_image->Allocate(); + + itk::ImageRegionIterator< VectorImageType > vecIter( + output_image, requestedRegion ); + + VolumeFileNamesContainer::const_iterator volumesFileNamesIter = filenames.begin(); + + // iterate over the given volumes + unsigned int component = 0; + while( volumesFileNamesIter != filenames.end() ) + { + + MITK_INFO << " ======== Loading volume " << component+1 << " of " << filenames.size(); + + typename SeriesReaderType::Pointer volume_reader = SeriesReaderType::New(); + volume_reader->SetFileNames( *volumesFileNamesIter ); + + try + { + volume_reader->UpdateLargestPossibleRegion(); + } + catch( const itk::ExceptionObject &e) + { + mitkThrow() << " ITK Series reader failed : "<< e.what(); + } + + itk::ImageRegionConstIterator< InputImageType > iRCIter ( + volume_reader->GetOutput(), + volume_reader->GetOutput()->GetLargestPossibleRegion() ); + + // transfer to vector image + iRCIter.GoToBegin(); + vecIter.GoToBegin(); + + + + while( !iRCIter.IsAtEnd() ) + { + typename VectorImageType::PixelType vector_pixel = vecIter.Get(); + vector_pixel.SetElement( component, iRCIter.Get() ); + vecIter.Set( vector_pixel ); + + ++vecIter; + ++iRCIter; + } + + ++volumesFileNamesIter; + component++; + } + + return output_image; + + } +}; + + +} + +#endif // MITKDIFFUSIONDICOMFILEREADERHELPER_H