Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkDicomDiffusionImageReader.cpp
Go to the documentation of this file.
1 /*===================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #ifndef __mitkDicomDiffusionImageReader_cpp
18 #define __mitkDicomDiffusionImageReader_cpp
19 
21 
22 #include "itkImageSeriesReader.h"
23 
24 
25 namespace mitk
26 {
27 
28 template <class TPixelType, const int TDimension>
30 ::PrintSelf(std::ostream& os, itk::Indent indent) const
31 {
32  Superclass::PrintSelf(os, indent);
33 }
34 
35 
36 template <class TPixelType, const int TDimension>
39 {
40  typename OutputImageType::Pointer output = this->GetOutput();
41  typedef itk::ImageSeriesReader<InputImageType> ReaderType;
42 
43  // Read the first (or last) volume and use its size.
44  if (m_Headers.size() > 0)
45  {
46  typename ReaderType::Pointer reader = ReaderType::New();
47 
48  try
49  {
50  // Read the image
51  reader->SetFileNames (m_Headers[0]->m_DicomFilenames);
52  reader->UpdateOutputInformation();
53 
54  output->SetSpacing( reader->GetOutput()->GetSpacing() ); // Set the image spacing
55  output->SetOrigin( reader->GetOutput()->GetOrigin() ); // Set the image origin
56  output->SetDirection( reader->GetOutput()->GetDirection() ); // Set the image direction
57  output->SetLargestPossibleRegion( reader->GetOutput()->GetLargestPossibleRegion() );
58  output->SetVectorLength( m_Headers.size() );
59  }
60  catch (itk::ExceptionObject &e)
61  {
62  throw e;
63  }
64  }
65  else
66  {
67  itkExceptionMacro(<< "At least one filename is required." );
68  }
69 }
70 
71 
72 template <class TPixelType, const int TDimension>
73  void
75  ::EnlargeOutputRequestedRegion(itk::DataObject *output)
76  {
77  typename OutputImageType::Pointer out = dynamic_cast<OutputImageType*>(output);
78  out->SetRequestedRegion( out->GetLargestPossibleRegion() );
79 }
80 
81 
82 template <class TPixelType, const int TDimension>
85 {
86  typedef itk::ImageSeriesReader<InputImageType> ReaderType;
87 
88  typename OutputImageType::Pointer output = this->GetOutput();
89 
90  typedef typename OutputImageType::RegionType RegionType;
91  RegionType requestedRegion = output->GetRequestedRegion();
92 
93  // Each file must have the same size.
94  SizeType validSize = requestedRegion.GetSize();
95 
96  int numberOfVolumes = static_cast<int>(m_Headers.size());
97 
98  // Allocate the output buffer
99  output->SetBufferedRegion( requestedRegion );
100  output->Allocate();
101 
102  itk::ProgressReporter progress(this, 0,
103  m_Headers.size(),
104  m_Headers.size());
105 
106  itk::ImageRegionIterator<OutputImageType> ot (output, requestedRegion );
107 
108  typename OutputImageType::PixelType vec;
109 
110  for (int i = 0; i < numberOfVolumes; i ++)
111  {
112 
113  MITK_INFO << "Loading volume " << i+1 << "/" << numberOfVolumes;
114  typename ReaderType::Pointer reader = ReaderType::New();
115  reader->SetFileNames(m_Headers[i]->m_DicomFilenames);
116  reader->UpdateLargestPossibleRegion();
117 
118  if (reader->GetOutput()->GetRequestedRegion().GetSize() != validSize)
119  {
120  itkExceptionMacro(<< "Size mismatch!");
121  }
122 
123  itk::ImageRegionConstIterator<InputImageType> it (reader->GetOutput(),
124  reader->GetOutput()->GetLargestPossibleRegion());
125 
126  while (!it.IsAtEnd())
127  {
128  vec = ot.Get();
129  vec.SetElement(i, it.Get());
130  ot.Set(vec);
131  ++it;
132  ++ot;
133  }
134  ot.GoToBegin();
135  progress.CompletedPixel();
136  }
137 }
138 
139 } //namespace MITK
140 
141 #endif
itk::SmartPointer< Self > Pointer
#define MITK_INFO
Definition: mitkLogMacros.h:22
DataCollection - Class to facilitate loading/accessing structured data.
itk::VectorImage< TPixelType, TDimension > OutputImageType
virtual void EnlargeOutputRequestedRegion(itk::DataObject *output)
unsigned short PixelType
void PrintSelf(std::ostream &os, itk::Indent indent) const
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.