DMRITool  v0.1.1-139-g860d86b4
Diffusion MRI Tool
itkVectorImageChannelFilter.hxx
Go to the documentation of this file.
1 
12 #ifndef __itkVectorImageChannelFilter_hxx
13 #define __itkVectorImageChannelFilter_hxx
14 
16 #include "itkVectorIndexSelectionCastImageFilter.h"
18 
19 namespace itk
20 {
21 
22 template< class TInputImage, class TOutputImage, class TFilter >
25 {
26  m_Filter=NULL;
27 }
28 
29 template< class TInputImage, class TOutputImage, class TFilter >
30 typename LightObject::Pointer
33 {
34  typename LightObject::Pointer loPtr = Superclass::InternalClone();
35 
36  typename Self::Pointer rval = dynamic_cast<Self *>(loPtr.GetPointer());
37  if(rval.IsNull())
38  {
39  itkExceptionMacro(<< "downcast to type " << this->GetNameOfClass()<< " failed.");
40  }
41  rval->m_Filter = m_Filter->Clone();
42  return loPtr;
43 }
44 
45 template< class TInputImage, class TOutputImage, class TFilter >
46 void
48 ::PrintSelf(std::ostream& os, Indent indent) const
49 {
50  Superclass::PrintSelf(os, indent);
51  if (m_Filter)
52  m_Filter->Print(os<<indent << "m_Filter =\n");
53 }
54 
55 template< class TInputImage, class TOutputImage, class TFilter >
56 void
59 {
60  utlException(!m_Filter, "need to set m_Filter");
61  typename TInputImage::ConstPointer inputImage = this->GetInput();
62  int N = inputImage->GetNumberOfComponentsPerPixel();
63 
64  typedef typename TFilter::OutputImageType FilterOutputImageType;
66  typename ComposeImageFilterType::Pointer composeImageFilter = ComposeImageFilterType::New();
67 
68  typedef itk::VectorIndexSelectionCastImageFilter<TInputImage, typename TFilter::InputImageType> IndexSelectionType;
69 
70  for ( int i = 0; i < N; ++i )
71  {
72  typename IndexSelectionType::Pointer indexSelectionFilter = IndexSelectionType::New();
73  indexSelectionFilter->SetIndex(i);
74  indexSelectionFilter->SetInput(inputImage);
75  // indexSelectionFilter->Update();
76 
77  typename TFilter::Pointer filterCopy = m_Filter->Clone();
78  filterCopy->SetInput(indexSelectionFilter->GetOutput());
79  filterCopy->Update();
80  typename FilterOutputImageType::Pointer out = filterCopy->GetOutput();
81 
82  composeImageFilter->SetInput(i, filterCopy->GetOutput());
83  }
84 
85  composeImageFilter->Update();
86  typename OutputImageType::Pointer outputImage = composeImageFilter->GetOutput();
87 
88  this->GraftOutput(outputImage);
89 }
90 
91 
92 }
93 
94 #endif
95 
TInputImage and TOutputImage are VectorImage, TFilter is an image filter which works for itk::Image...
Created "06-27-2016.
virtual void PrintSelf(std::ostream &os, Indent indent) const ITK_OVERRIDE
ComposeVectorImageFilter combine several vector images into a vector image.
ImageToImageFilter< TInputImage, TOutputImage > Superclass
#define utlException(cond, expout)
Definition: utlCoreMacro.h:548
Created "06-27-2016.
LightObject::Pointer InternalClone() const ITK_OVERRIDE