DMRITool  v0.1.1-139-g860d86b4
Diffusion MRI Tool
itkComposeVectorImageFilter.h
Go to the documentation of this file.
1 
11 #ifndef __itkComposeVectorImageFilter_h
12 #define __itkComposeVectorImageFilter_h
13 
14 #include "itkImageToImageFilter.h"
15 #include "itkVectorImage.h"
16 #include "itkImageRegionConstIterator.h"
17 #include <vector>
18 #include "itkVectorIndexSelectionCastImageFilter.h"
19 
20 #include "utlCoreMacro.h"
21 
22 namespace itk
23 {
49 template< typename TInputImage=VectorImage<double,3>, typename TOutputImage=VectorImage<typename TInputImage::PixelType, TInputImage::ImageDimension> >
51  public ImageToImageFilter< TInputImage, TOutputImage >
52 {
53 public:
54 
56  typedef SmartPointer< Self > Pointer;
57  typedef SmartPointer< const Self > ConstPointer;
58  typedef ImageToImageFilter< TInputImage, TOutputImage > Superclass;
59  itkNewMacro(Self);
60  itkTypeMacro(ComposeVectorImageFilter, ImageToImageFilter);
61 
62  itkStaticConstMacro(Dimension, unsigned int, TInputImage::ImageDimension);
63 
64  typedef TInputImage InputImageType;
65  typedef TOutputImage OutputImageType;
66  typedef typename InputImageType::PixelType InputPixelType;
67  typedef typename OutputImageType::PixelType OutputPixelType;
68  typedef typename InputImageType::RegionType RegionType;
69 
70  void SetInput1(const InputImageType *image1);
71  void SetInput2(const InputImageType *image2);
72  void SetInput3(const InputImageType *image3);
73 
74 
75 protected:
77 
78  virtual void GenerateOutputInformation(void) ITK_OVERRIDE;
79 
80  virtual void BeforeThreadedGenerateData() ITK_OVERRIDE;
81 
82  virtual void ThreadedGenerateData(const RegionType & outputRegionForThread, ThreadIdType) ITK_OVERRIDE;
83 
84 private:
85  ComposeVectorImageFilter(const Self &);
86  void operator=(const Self &);
87 
88 
89  // we have to specialize the code for complex, because it provides no operator[]
90  // method
91  typedef ImageRegionConstIterator< InputImageType > InputIteratorType;
92  typedef std::vector< InputIteratorType > InputIteratorContainerType;
93 
94  // template<typename T>
95  // void ComputeOutputPixel(std::complex<T> & pix, InputIteratorContainerType & inputItContainer )
96  // {
97  // pix = std::complex<T>(inputItContainer[0].Get(), inputItContainer[1].Get());
98  // ++( inputItContainer[0] );
99  // ++( inputItContainer[1] );
100  // }
101  template<typename TPixel>
102  void ComputeOutputPixel(TPixel & pix, InputIteratorContainerType & inputItContainer)
103  {
104  int j=0;
105  for ( unsigned int i = 0; i < this->GetNumberOfInputs(); i++ )
106  {
107  typename InputImageType::PixelType pixel = inputItContainer[i].Get();
108  for ( int k = 0; k < pixel.Size(); ++k )
109  {
110  pix[j] = pixel[k];
111  j++;
112  }
113  ++( inputItContainer[i] );
114  }
115  }
116 };
117 
118 
119 // template <class ImageType, class FilterType >
120 // SmartPointer<ImageType>
121 // VectorImageChannelFilterApply ( const SmartPointer<ImageType>& input, const SmartPointer<FilterType>& filter )
122 // {
123 // typedef typename FilterType::InputImageType FilterInputImageType;
124 // typedef typename FilterType::OutputImageType FilterOutputImageType;
125 // typedef itk::ComposeVectorImageFilter<FilterOutputImageType, ImageType> ComposeImageFilterType;
126 // typename ComposeImageFilterType::Pointer composeImageFilter = ComposeImageFilterType::New();
127 
128 // typedef itk::VectorIndexSelectionCastImageFilter<ImageType, FilterInputImageType> IndexSelectionType;
129 
130 // int N = input->GetNumberOfComponentsPerPixel();
131 // input->Print(std::cout<<"input=\n");
132 // for ( int i = 0; i < N; ++i )
133 // {
134 // typename IndexSelectionType::Pointer indexSelectionFilter = IndexSelectionType::New();
135 // indexSelectionFilter->SetIndex(i);
136 // indexSelectionFilter->SetInput(input);
137 // indexSelectionFilter->Update();
138 
139 // typename FilterType::Pointer filterCopy = filter->Clone();
140 // filterCopy->SetInput(indexSelectionFilter->GetOutput());
141 // filterCopy->Update();
142 // typename FilterOutputImageType::Pointer out = filterCopy->GetOutput();
143 
144 // utlPrintVar3(true, i, N, out->GetNumberOfComponentsPerPixel());
145 
146 // composeImageFilter->SetInput(i, out);
147 // }
148 
149 // composeImageFilter->Update();
150 // return composeImageFilter->GetOutput();
151 // }
152 
153 }
154 
155 #if !defined(ITK_MANUAL_INSTANTIATION) && !defined(__itkComposeVectorImageFilter_hxx)
157 #endif
158 
159 #endif
160 
std::vector< InputIteratorType > InputIteratorContainerType
virtual void GenerateOutputInformation(void) ITK_OVERRIDE
void SetInput3(const InputImageType *image3)
ComposeVectorImageFilter combine several vector images into a vector image.
STL namespace.
Created "06-27-2016.
#define ITK_OVERRIDE
Definition: utlITKMacro.h:46
SmartPointer< const Self > ConstPointer
void SetInput1(const InputImageType *image1)
virtual void BeforeThreadedGenerateData() ITK_OVERRIDE
InputImageType::PixelType InputPixelType
ImageRegionConstIterator< InputImageType > InputIteratorType
virtual void ThreadedGenerateData(const RegionType &outputRegionForThread, ThreadIdType) ITK_OVERRIDE
ImageToImageFilter< TInputImage, TOutputImage > Superclass
void SetInput2(const InputImageType *image2)
macros for utlCore
InputImageType::RegionType RegionType
OutputImageType::PixelType OutputPixelType
void ComputeOutputPixel(TPixel &pix, InputIteratorContainerType &inputItContainer)