Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
itkRemoveDwiChannelFilter.txx
Go to the documentation of this file.
1 /*===================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #ifndef __itkRemoveDwiChannelFilter_txx
18 #define __itkRemoveDwiChannelFilter_txx
19 
20 #include <time.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 
24 #define _USE_MATH_DEFINES
25 #include <math.h>
26 
27 #include "itkImageRegionConstIterator.h"
28 #include "itkImageRegionConstIteratorWithIndex.h"
29 #include "itkImageRegionIterator.h"
30 
31 namespace itk {
32 
33 
34 template< class TInPixelType >
35 RemoveDwiChannelFilter< TInPixelType>::RemoveDwiChannelFilter()
36 {
37  this->SetNumberOfRequiredInputs( 1 );
38 }
39 
40 template< class TInPixelType >
41 void RemoveDwiChannelFilter< TInPixelType>::BeforeThreadedGenerateData()
42 {
43  typename InputImageType::Pointer inputImagePointer = static_cast< InputImageType * >( this->ProcessObject::GetInput(0) );
44  if ( inputImagePointer->GetVectorLength()-m_ChannelIndices.size()<=0 )
45  itkExceptionMacro("No channels remaining!");
46 
47  typename OutputImageType::Pointer outputImage = static_cast< OutputImageType * >(this->ProcessObject::GetOutput(0));
48  outputImage->SetSpacing( inputImagePointer->GetSpacing() );
49  outputImage->SetOrigin( inputImagePointer->GetOrigin() );
50  outputImage->SetDirection( inputImagePointer->GetDirection() );
51  outputImage->SetLargestPossibleRegion( inputImagePointer->GetLargestPossibleRegion() );
52  outputImage->SetBufferedRegion( inputImagePointer->GetLargestPossibleRegion() );
53  outputImage->SetRequestedRegion( inputImagePointer->GetLargestPossibleRegion() );
54  outputImage->Allocate();
55  outputImage->SetVectorLength( inputImagePointer->GetVectorLength()-m_ChannelIndices.size() );
56  typename OutputImageType::PixelType nullPix;
57  nullPix.SetSize(outputImage->GetVectorLength());
58  nullPix.Fill(0);
59  outputImage->FillBuffer(nullPix);
60  this->SetNthOutput(0, outputImage);
61 
62  m_NewDirections = DirectionContainerType::New();
63 
64  int chIdx = 0;
65  for (unsigned int i=0; i<inputImagePointer->GetVectorLength(); i++)
66  {
67  bool use = true;
68  for (unsigned int j=0; j<m_ChannelIndices.size(); j++)
69  if (m_ChannelIndices.at(j)==i)
70  {
71  use = false;
72  break;
73  }
74  if (use)
75  {
76  m_NewDirections->InsertElement(chIdx, m_Directions->GetElement(i));
77  ++chIdx;
78  MITK_INFO << "Using channel " << i;
79  }
80  }
81 }
82 
83 template< class TInPixelType >
84 void RemoveDwiChannelFilter< TInPixelType>::ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, ThreadIdType id )
85 {
86  typename OutputImageType::Pointer outputImage = static_cast< OutputImageType * >(this->ProcessObject::GetOutput(0));
87 
88  ImageRegionIterator< OutputImageType > oit(outputImage, outputRegionForThread);
89  oit.GoToBegin();
90 
91  typedef ImageRegionConstIterator< InputImageType > InputIteratorType;
92  typename InputImageType::Pointer inputImagePointer = static_cast< InputImageType * >( this->ProcessObject::GetInput(0) );
93 
94  InputIteratorType git( inputImagePointer, outputRegionForThread );
95  git.GoToBegin();
96  while( !git.IsAtEnd() )
97  {
98  int chIdx = 0;
99  typename OutputImageType::PixelType pix = oit.Get();
100  for (unsigned int i=0; i<inputImagePointer->GetVectorLength(); i++)
101  {
102  bool use = true;
103  for (unsigned int j=0; j<m_ChannelIndices.size(); j++)
104  if (m_ChannelIndices.at(j)==i)
105  {
106  use = false;
107  break;
108  }
109  if (use)
110  {
111  pix[chIdx] = git.Get()[i];
112  ++chIdx;
113  }
114  }
115  oit.Set(pix);
116  ++oit;
117  ++git;
118  }
119 
120  std::cout << "One Thread finished calculation" << std::endl;
121 }
122 
123 template< class TInPixelType >
124 void
125 RemoveDwiChannelFilter< TInPixelType>
126 ::PrintSelf(std::ostream& os, Indent indent) const
127 {
128  Superclass::PrintSelf(os,indent);
129 }
130 
131 }
132 
133 #endif // __itkRemoveDwiChannelFilter_txx