1 #ifndef MITKDIFFUSIONDICOMFILEREADERHELPER_H
2 #define MITKDIFFUSIONDICOMFILEREADERHELPER_H
4 #include "itkImageSeriesReader.h"
5 #include "itkVectorImage.h"
7 #include "itkImageRegionIteratorWithIndex.h"
36 typedef itk::ImageSeriesReader< InputImageType > SeriesReaderType;
39 probe_reader->SetFileNames( filenames.at(0) );
40 probe_reader->GenerateOutputInformation();
41 probe_reader->Update();
43 std::string seriesDescTag, seriesNumberTag, patientName;
44 SeriesReaderType::DictionaryArrayRawPointer inputDict = probe_reader->GetMetaDataDictionaryArray();
46 if( ! itk::ExposeMetaData< std::string > ( *(*inputDict)[0],
"0008|103e", seriesDescTag ) )
47 seriesDescTag =
"UNSeries";
49 if( ! itk::ExposeMetaData< std::string > ( *(*inputDict)[0],
"0020|0011", seriesNumberTag ) )
50 seriesNumberTag =
"00000";
52 if( ! itk::ExposeMetaData< std::string > ( *(*inputDict)[0],
"0010|0010", patientName ) )
53 patientName =
"UnknownName";
56 ss << seriesDescTag <<
"_" << seriesNumberTag <<
"_" << patientName;
62 template<
typename PixelType,
unsigned int VecImageDimension>
64 const VolumeFileNamesContainer& filenames
69 typedef itk::ImageSeriesReader< InputImageType > SeriesReaderType;
72 probe_reader->SetFileNames( filenames.at(0) );
73 probe_reader->GenerateOutputInformation();
74 const itk::ImageBase<3>::RegionType requestedRegion = probe_reader->GetOutput()->GetLargestPossibleRegion();
77 " Retrieved LPR " << requestedRegion;
82 output_image->SetNumberOfComponentsPerPixel( filenames.size() );
83 output_image->SetSpacing( probe_reader->GetOutput()->GetSpacing() );
84 output_image->SetOrigin( probe_reader->GetOutput()->GetOrigin() );
85 output_image->SetDirection( probe_reader->GetOutput()->GetDirection() );
86 output_image->SetLargestPossibleRegion( probe_reader->GetOutput()->GetLargestPossibleRegion() );
87 output_image->SetBufferedRegion( requestedRegion );
88 output_image->Allocate();
90 itk::ImageRegionIterator< VectorImageType > vecIter(
91 output_image, requestedRegion );
93 auto volumesFileNamesIter = filenames.begin();
96 unsigned int component = 0;
97 while( volumesFileNamesIter != filenames.end() )
100 MITK_INFO <<
" ======== Loading volume " << component+1 <<
" of " << filenames.size();
103 volume_reader->SetFileNames( *volumesFileNamesIter );
107 volume_reader->UpdateLargestPossibleRegion();
109 catch(
const itk::ExceptionObject &e)
111 mitkThrow() <<
" ITK Series reader failed : "<< e.what();
114 itk::ImageRegionConstIterator< InputImageType > iRCIter (
115 volume_reader->GetOutput(),
116 volume_reader->GetOutput()->GetLargestPossibleRegion() );
124 while( !iRCIter.IsAtEnd() )
127 vector_pixel.SetElement( component, iRCIter.Get() );
128 vecIter.Set( vector_pixel );
134 ++volumesFileNamesIter;
148 template<
typename PixelType,
unsigned int VecImageDimension>
150 const VolumeFileNamesContainer& filenames,
153 typedef itk::Image< PixelType, 3> MosaicImageType;
154 typedef itk::ImageFileReader< MosaicImageType > SingleImageReaderType;
159 auto volumesFileNamesIter = filenames.begin();
165 mosaic_probe->SetFileName( (*volumesFileNamesIter).at(0) );
168 mosaic_probe->UpdateLargestPossibleRegion();
170 catch(
const itk::ExceptionObject &e)
172 mitkThrow() <<
" ITK Image file reader failed : "<< e.what();
175 typename MosaicImageType::RegionType mosaic_lpr = mosaic_probe->GetOutput()->GetLargestPossibleRegion();
176 MITK_INFO <<
" == MOSAIC: " << mosaic_lpr;
178 itk::ImageBase<3>::SizeValueType images_per_row = ceil( sqrt( (
float) mosaicInfo.
nimages ) );
180 itk::ImageBase<3>::RegionType requestedRegion;
181 requestedRegion.SetSize( 0, mosaic_lpr.GetSize()[0]/images_per_row);
182 requestedRegion.SetSize( 1, mosaic_lpr.GetSize()[1]/images_per_row);
183 requestedRegion.SetSize( 2, mosaicInfo.
nimages);
186 output_image->SetNumberOfComponentsPerPixel( filenames.size() );
188 typename VectorImageType::DirectionType dmatrix;
189 dmatrix.SetIdentity();
191 std::vector<double> dirx = mosaic_probe->GetImageIO()->GetDirection(0);
192 std::vector<double> diry = mosaic_probe->GetImageIO()->GetDirection(1);
193 std::vector<double> dirz = mosaic_probe->GetImageIO()->GetDirection(2);
195 dmatrix.GetVnlMatrix().set_column( 0, &dirx[0] );
196 dmatrix.GetVnlMatrix().set_column( 1, &diry[0] );
197 dmatrix.GetVnlMatrix().set_column( 2, &dirz[0] );
203 output_image->SetSpacing( mosaicInfo.
spacing );
204 output_image->SetOrigin( mosaic_probe->GetOutput()->GetOrigin() );
205 output_image->SetDirection( dmatrix );
206 output_image->SetLargestPossibleRegion( requestedRegion );
207 output_image->SetBufferedRegion( requestedRegion );
208 output_image->Allocate();
210 itk::ImageRegionIteratorWithIndex< VectorImageType > vecIter(
211 output_image, requestedRegion );
214 typename MosaicImageType::SizeValueType dx = requestedRegion.GetSize()[0];
215 typename MosaicImageType::SizeValueType dy = requestedRegion.GetSize()[1];
218 unsigned int component = 0;
219 while( volumesFileNamesIter != filenames.end() )
222 MITK_INFO <<
" ======== Loading volume " << component+1 <<
" of " << filenames.size();
225 mosaic_reader->SetFileName( (*volumesFileNamesIter).at(0) );
229 mosaic_reader->UpdateLargestPossibleRegion();
231 catch(
const itk::ExceptionObject &e)
233 mitkThrow() <<
" ITK Image file reader failed : "<< e.what();
239 while( !vecIter.IsAtEnd() )
242 typename VectorImageType::IndexType threeD_index = vecIter.GetIndex();
244 typename MosaicImageType::IndexType mosaic_index;
255 mosaic_index[0] = (threeD_index[2] % images_per_row) * dx + threeD_index[0];
256 mosaic_index[1] = (threeD_index[2] / images_per_row) * dy + threeD_index[1];
260 vector_pixel.SetElement( component, mosaic_pixel );
262 vecIter.Set( vector_pixel );
267 ++volumesFileNamesIter;
281 #endif // MITKDIFFUSIONDICOMFILEREADERHELPER_H
itk::ImageBase< 3 >::DirectionType direction
itk::SmartPointer< Self > Pointer
The MosaicDescriptor struct is a help struct holding the necessary information for loading a mosaic D...
DataCollection - Class to facilitate loading/accessing structured data.
std::vector< StringContainer > VolumeFileNamesContainer
itk::Image< double, 3 > InputImageType
std::string GetOutputName(const VolumeFileNamesContainer &filenames)
itk::VectorImage< PixelType, VecImageDimension >::Pointer LoadMosaicToVector(const VolumeFileNamesContainer &filenames, const MosaicDescriptor &mosaicInfo)
std::vector< std::string > StringContainer
itk::ImageBase< 3 >::SpacingType spacing
itk::VectorImage< PixelType, VecImageDimension >::Pointer LoadToVector(const VolumeFileNamesContainer &filenames)
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.