Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef __mitkDicomDiffusionImageReader_cpp
00019 #define __mitkDicomDiffusionImageReader_cpp
00020
00021 #include "mitkDicomDiffusionImageReader.h"
00022
00023 #include "itkImageSeriesReader.h"
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 namespace mitk
00035 {
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055 template <class TPixelType, const int TDimension>
00056 void DicomDiffusionImageReader<TPixelType, TDimension>
00057 ::PrintSelf(std::ostream& os, itk::Indent indent) const
00058 {
00059 Superclass::PrintSelf(os, indent);
00060 }
00061
00062
00063 template <class TPixelType, const int TDimension>
00064 void DicomDiffusionImageReader<TPixelType, TDimension>
00065 ::GenerateOutputInformation(void)
00066 {
00067 typename OutputImageType::Pointer output = this->GetOutput();
00068 typedef itk::ImageSeriesReader<InputImageType> ReaderType;
00069
00070
00071 if (m_Headers.size() > 0)
00072 {
00073 typename ReaderType::Pointer reader = ReaderType::New();
00074
00075 try
00076 {
00077
00078 reader->SetFileNames (m_Headers[0]->m_DicomFilenames);
00079 reader->UpdateOutputInformation();
00080
00081 output->SetSpacing( reader->GetOutput()->GetSpacing() );
00082 output->SetOrigin( reader->GetOutput()->GetOrigin() );
00083 output->SetDirection( reader->GetOutput()->GetDirection() );
00084 output->SetLargestPossibleRegion( reader->GetOutput()->GetLargestPossibleRegion() );
00085 output->SetVectorLength( m_Headers.size() );
00086 }
00087 catch (itk::ExceptionObject &e)
00088 {
00089 throw e;
00090 }
00091 }
00092 else
00093 {
00094 itkExceptionMacro(<< "At least one filename is required." );
00095 }
00096 }
00097
00098
00099 template <class TPixelType, const int TDimension>
00100 void
00101 DicomDiffusionImageReader<TPixelType, TDimension>
00102 ::EnlargeOutputRequestedRegion(itk::DataObject *output)
00103 {
00104 typename OutputImageType::Pointer out = dynamic_cast<OutputImageType*>(output);
00105 out->SetRequestedRegion( out->GetLargestPossibleRegion() );
00106 }
00107
00108
00109 template <class TPixelType, const int TDimension>
00110 void DicomDiffusionImageReader<TPixelType, TDimension>
00111 ::GenerateData()
00112 {
00113 typedef itk::ImageSeriesReader<InputImageType> ReaderType;
00114
00115 typename OutputImageType::Pointer output = this->GetOutput();
00116
00117 typedef typename OutputImageType::RegionType RegionType;
00118 RegionType requestedRegion = output->GetRequestedRegion();
00119
00120
00121 SizeType validSize = requestedRegion.GetSize();
00122
00123 int numberOfVolumes = static_cast<int>(m_Headers.size());
00124
00125
00126 output->SetBufferedRegion( requestedRegion );
00127 output->Allocate();
00128
00129 itk::ProgressReporter progress(this, 0,
00130 m_Headers.size(),
00131 m_Headers.size());
00132
00133 itk::ImageRegionIterator<OutputImageType> ot (output, requestedRegion );
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146 typename OutputImageType::PixelType vec;
00147
00148 for (int i = 0; i < numberOfVolumes; i ++)
00149 {
00150
00151 MITK_INFO << "Loading volume " << i+1 << "/" << numberOfVolumes;
00152 typename ReaderType::Pointer reader = ReaderType::New();
00153 reader->SetFileNames(m_Headers[i]->m_DicomFilenames);
00154 reader->UpdateLargestPossibleRegion();
00155
00156 if (reader->GetOutput()->GetRequestedRegion().GetSize() != validSize)
00157 {
00158 itkExceptionMacro(<< "Size mismatch!");
00159 }
00160
00161 itk::ImageRegionConstIterator<InputImageType> it (reader->GetOutput(),
00162 reader->GetOutput()->GetLargestPossibleRegion());
00163
00164 while (!it.IsAtEnd())
00165 {
00166 vec = ot.Get();
00167 vec.SetElement(i, it.Get());
00168 ot.Set(vec);
00169 ++it;
00170 ++ot;
00171 }
00172 ot = ot.Begin();
00173 progress.CompletedPixel();
00174 }
00175 }
00176
00177 }
00178
00179 #endif