DMRITool  v0.1.1-139-g860d86b4
Diffusion MRI Tool
itkMultiVolumeImageToVectorImageFilter.hxx
Go to the documentation of this file.
1 
18 #ifndef __itkMultiVolumeImageToVectorImageFilter_hxx
19 #define __itkMultiVolumeImageToVectorImageFilter_hxx
20 
21 
22 #include "utlITK.h"
24 #include "itkImageRegionIteratorWithIndex.h"
25 
26 
27 namespace itk
28 {
29 
30 template <class TInputPixelType, class TOutputPixelType, unsigned int VImageDimension>
33 {
34  InputImagePointer inputPtr = const_cast< InputImageType * >( this->GetInput());
35  OutputImagePointer outputPtr = this->GetOutput();
36  itk::CopyImageInformation<InputImageType, OutputImageType>(inputPtr, outputPtr);
37  typename InputImageType::RegionType inputRegion = inputPtr->GetLargestPossibleRegion();
38  typename InputImageType::SizeType inputImageSize = inputRegion.GetSize();
39  outputPtr->SetNumberOfComponentsPerPixel( inputImageSize[MultiVolumeImageDimension-1] );
40 }
41 
42 template <class TInputPixelType, class TOutputPixelType, unsigned int VImageDimension>
45 {
46  // get pointers to the input and output
47  InputImagePointer inputPtr = const_cast< InputImageType * >( this->GetInput());
48  OutputImagePointer outputPtr = this->GetOutput();
49 
50  outputPtr->Allocate();
51 
52  ImageRegionIteratorWithIndex<OutputImageType> outputIt(outputPtr, outputPtr->GetLargestPossibleRegion());
53  outputIt.GoToBegin();
54  OutputImagePixelType outputPixel;
55  unsigned int vectorDimension = outputPtr->GetNumberOfComponentsPerPixel();
56  outputPixel.SetSize( vectorDimension );
57  typename InputImageType::IndexType inputIndex;
58  typename OutputImageType::IndexType outputIndex;
59 
60  while(!outputIt.IsAtEnd())
61  {
62  outputIndex = outputIt.GetIndex();
63  for ( int i = 0; i < VectorImageDimension; i += 1 )
64  {
65  inputIndex[i] = outputIndex[i];
66  }
67  for ( int i = 0; i < vectorDimension; i += 1 )
68  {
69  inputIndex[MultiVolumeImageDimension-1] = i;
70  outputPixel[i] = (TOutputPixelType) inputPtr->GetPixel(inputIndex);
71  }
72  outputIt.Set(outputPixel);
73  ++outputIt;
74  }
75 }
76 
77 template <class TInputPixelType, class TOutputPixelType, unsigned int VImageDimension>
79 ::PrintSelf(std::ostream& os, Indent indent) const
80 {
81  Superclass::PrintSelf(os, indent);
82  PrintVar1(this->GetInput(), this->GetInput(), os<<indent << "MultiVolumeImage");
83  PrintVar1(this->GetOutput(), this->GetOutput(), os<<indent << "VectorImage");
84 }
85 
86 template <class ScalarType, unsigned Dim>
87 void
88 MultiVolumeToVectorImage ( const SmartPointer<Image<ScalarType, Dim+1> >& image1, SmartPointer<VectorImage<ScalarType,Dim> >& image2 )
89 {
91  typename ConvertorType::Pointer convertor = ConvertorType::New();
92  convertor->SetInput(image1);
93  convertor->Update();
94  image2 = convertor->GetOutput();
95 }
96 
97 }
98 
99 #endif
#define PrintVar1(cond, var, os)
Definition: utlCoreMacro.h:447
void MultiVolumeToVectorImage(const SmartPointer< Image< ScalarType, Dim+1 > > &image1, SmartPointer< VectorImage< ScalarType, Dim > > &image2)
void PrintSelf(std::ostream &os, Indent indent) const ITK_OVERRIDE
convert Image<TInputPixelType, VImageDimension+1> to VectorImage<TOutputPixelType, VImageDimension>
Image< TInputPixelType, MultiVolumeImageDimension > InputImageType