DMRITool  v0.1.1-139-g860d86b4
Diffusion MRI Tool
itkComposeVectorImageFilter.hxx
Go to the documentation of this file.
1 
11 #ifndef __itkComposeVectorImageFilter_hxx
12 #define __itkComposeVectorImageFilter_hxx
13 
15 #include "itkImageRegionIterator.h"
16 #include "itkProgressReporter.h"
17 
18 namespace itk
19 {
20 //----------------------------------------------------------------------------
21 template< typename TInputImage, typename TOutputImage >
24 {
26  int nbOfComponents = NumericTraits<OutputPixelType>::GetLength(p);
27  nbOfComponents = std::max( 1, nbOfComponents ); // require at least one input
28  this->SetNumberOfRequiredInputs( nbOfComponents );
29 }
30 
31 //----------------------------------------------------------------------------
32 template< typename TInputImage, typename TOutputImage >
33 void
36 {
37  // The ProcessObject is not const-correct so the const_cast is required here
38  this->SetNthInput( 0, const_cast< InputImageType * >( image1 ) );
39 }
40 
41 //----------------------------------------------------------------------------
42 template< typename TInputImage, typename TOutputImage >
43 void
46 {
47  // The ProcessObject is not const-correct so the const_cast is required here
48  this->SetNthInput( 1, const_cast< InputImageType * >( image2 ) );
49 }
50 
51 //----------------------------------------------------------------------------
52 template< typename TInputImage, typename TOutputImage >
53 void
56 {
57  // The ProcessObject is not const-correct so the const_cast is required here
58  this->SetNthInput( 2, const_cast< InputImageType * >( image3 ) );
59 }
60 
61 //----------------------------------------------------------------------------
62 template< typename TInputImage, typename TOutputImage >
63 void
66 {
67  // Override the method in itkImageSource, so we can set the vector length of
68  // the output itk::VectorImage
69 
70  this->Superclass::GenerateOutputInformation();
71 
72  OutputImageType *output = this->GetOutput();
73  int n=0;
74  for ( int i = 0; i < this->GetNumberOfIndexedInputs(); ++i )
75  {
76  const InputImageType * inputImage = this->GetInput(i);
77  n += inputImage->GetNumberOfComponentsPerPixel();
78  }
79  output->SetNumberOfComponentsPerPixel( n );
80 }
81 
82 //----------------------------------------------------------------------------
83 template< typename TInputImage, typename TOutputImage >
84 void
87 {
88  // Check to verify all inputs are specified and have the same metadata,
89  // spacing etc...
90  const unsigned int numberOfInputs = this->GetNumberOfIndexedInputs();
91  RegionType region;
92 
93  for ( unsigned int i = 0; i < numberOfInputs; i++ )
94  {
95  InputImageType *input = itkDynamicCastInDebugMode< InputImageType * >
96  (this->ProcessObject::GetInput(i) );
97  if ( !input )
98  {
99  itkExceptionMacro(<< "Input " << i << " not set!");
100  }
101  if ( i == 0 )
102  {
103  region = input->GetLargestPossibleRegion();
104  }
105  else if ( input->GetLargestPossibleRegion() != region )
106  {
107  itkExceptionMacro(<< "All Inputs must have the same dimensions.");
108  }
109  }
110 }
111 
112 //----------------------------------------------------------------------------
113 template< typename TInputImage, typename TOutputImage >
114 void
116 ::ThreadedGenerateData(const RegionType & outputRegionForThread,
117  ThreadIdType threadId)
118 {
119  ProgressReporter progress( this, threadId, outputRegionForThread.GetNumberOfPixels() );
120 
121  typename OutputImageType::Pointer outputImage =
122  static_cast< OutputImageType * >( this->ProcessObject::GetOutput(0) );
123 
124  ImageRegionIterator< OutputImageType > oit(outputImage, outputRegionForThread);
125  oit.GoToBegin();
126 
127  InputIteratorContainerType inputItContainer;
128 
129  for ( unsigned int i = 0; i < this->GetNumberOfIndexedInputs(); i++ )
130  {
131  const InputImageType * inputImage = this->GetInput(i);
132 
133  InputIteratorType iit( inputImage, outputRegionForThread);
134  iit.GoToBegin();
135  inputItContainer.push_back(iit);
136  }
137 
138  OutputPixelType pix;
139  NumericTraits<OutputPixelType>::SetLength( pix, outputImage->GetNumberOfComponentsPerPixel() );
140  while ( !oit.IsAtEnd() )
141  {
142  ComputeOutputPixel( pix, inputItContainer );
143  oit.Set(pix);
144  ++oit;
145  progress.CompletedPixel();
146  }
147 }
148 } // end namespace itk
149 
150 #endif
151 
152 
153 
std::vector< InputIteratorType > InputIteratorContainerType
virtual void GenerateOutputInformation(void) ITK_OVERRIDE
void SetInput3(const InputImageType *image3)
const T & max(const T &a, const T &b)
Return the maximum between a and b.
Definition: utlCore.h:263
void SetInput1(const InputImageType *image1)
virtual void BeforeThreadedGenerateData() ITK_OVERRIDE
Created "06-27-2016.
ImageRegionConstIterator< InputImageType > InputIteratorType
virtual void ThreadedGenerateData(const RegionType &outputRegionForThread, ThreadIdType) ITK_OVERRIDE
void SetInput2(const InputImageType *image2)
InputImageType::RegionType RegionType
OutputImageType::PixelType OutputPixelType