DMRITool  v0.1.1-139-g860d86b4
Diffusion MRI Tool
itkVectorImageToMultiVolumeImageFilter.hxx
Go to the documentation of this file.
1 
18 #ifndef __itkVectorImageToMultiVolumeImageFilter_hxx
19 #define __itkVectorImageToMultiVolumeImageFilter_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 
36  OutputImagePointer outputPtr = this->GetOutput();
37  // NOTE: outputPtr->CopyInformation(inputPtr) is wrong when inputPtr is a 2D VectorImage
38  itk::CopyImageInformation(inputPtr, outputPtr);
39 
40  unsigned int vectorDimension = inputPtr->GetNumberOfComponentsPerPixel();
41  typename OutputImageType::RegionType outRegion = outputPtr->GetLargestPossibleRegion();
42  typename OutputImageType::SizeType outSize = outRegion.GetSize();
43  outSize[MultiVolumeImageDimension-1] = vectorDimension;
44  outRegion.SetSize(outSize);
45  outputPtr->SetRegions(outRegion);
46 }
47 
48 template <class TInputPixelType, class TOutputPixelType, unsigned int VImageDimension>
51 {
52  // get pointers to the input and output
53  InputImagePointer inputPtr = const_cast< InputImageType * >( this->GetInput());
54  OutputImagePointer outputPtr = this->GetOutput();
55 
56  outputPtr->Allocate();
57 
58  ImageRegionIteratorWithIndex<InputImageType> inputIt(inputPtr, inputPtr->GetLargestPossibleRegion());
59  inputIt.GoToBegin();
60  InputImagePixelType inputPixel;
61  unsigned int vectorDimension = inputPtr->GetNumberOfComponentsPerPixel();
62  inputPixel.SetSize( vectorDimension );
63  typename InputImageType::IndexType inputIndex;
64  typename OutputImageType::IndexType outputIndex;
65 
66  while(!inputIt.IsAtEnd())
67  {
68  inputIndex = inputIt.GetIndex();
69  inputPixel = inputIt.Get();
70 
71  for ( unsigned int i = 0; i < VectorImageDimension; i++ )
72  {
73  outputIndex[i] = inputIndex[i];
74  }
75 
76  for ( unsigned int i = 0; i < vectorDimension; i++ )
77  {
78  outputIndex[MultiVolumeImageDimension-1] = i;
79  outputPtr->SetPixel(outputIndex, inputPixel[i]);
80  }
81 
82  ++inputIt;
83  }
84 }
85 
86 template <class TInputPixelType, class TOutputPixelType, unsigned int VImageDimension>
88 ::PrintSelf(std::ostream& os, Indent indent) const
89 {
90  Superclass::PrintSelf(os, indent);
91  PrintVar1(this->GetInput(), this->GetInput(), os<<indent << "VectorImage");
92  PrintVar1(this->GetOutput(), this->GetOutput(), os<<indent << "MultiVolumeImage");
93 }
94 
95 template <class ScalarType, unsigned Dim>
96 void
97 VectorToMultiVolumeImage ( const SmartPointer<VectorImage<ScalarType,Dim> >& image1, SmartPointer<Image<ScalarType, Dim+1> >& image2 )
98 {
100  typename ConvertorType::Pointer convertor = ConvertorType::New();
101  convertor->SetInput(image1);
102  convertor->Update();
103  image2 = convertor->GetOutput();
104 }
105 
106 }
107 
108 #endif
#define PrintVar1(cond, var, os)
Definition: utlCoreMacro.h:447
convert VectorImage<TOutputPixelType, VImageDimension> to Image<TInputPixelType, VImageDimension+1> ...
void CopyImageInformation(const SmartPointer< ImageWithInfoType > &imageFrom, SmartPointer< ImageType > &imageTo)
Definition: utlITK.h:552
void VectorToMultiVolumeImage(const SmartPointer< VectorImage< ScalarType, Dim > > &image1, SmartPointer< Image< ScalarType, Dim+1 > > &image2)
VectorImage< TOutputPixelType, VectorImageDimension > InputImageType
void PrintSelf(std::ostream &os, Indent indent) const ITK_OVERRIDE