1 /*===================================================================
3 The Medical Imaging Interaction Toolkit (MITK)
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
13 See LICENSE.txt or http://www.mitk.org for details.
15 ===================================================================*/
17 #ifndef __itkRemoveDwiChannelFilter_txx
18 #define __itkRemoveDwiChannelFilter_txx
24 #define _USE_MATH_DEFINES
27 #include "itkImageRegionConstIterator.h"
28 #include "itkImageRegionConstIteratorWithIndex.h"
29 #include "itkImageRegionIterator.h"
34 template< class TInPixelType >
35 RemoveDwiChannelFilter< TInPixelType>::RemoveDwiChannelFilter()
37 this->SetNumberOfRequiredInputs( 1 );
40 template< class TInPixelType >
41 void RemoveDwiChannelFilter< TInPixelType>::BeforeThreadedGenerateData()
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!");
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());
59 outputImage->FillBuffer(nullPix);
60 this->SetNthOutput(0, outputImage);
62 m_NewDirections = DirectionContainerType::New();
65 for (unsigned int i=0; i<inputImagePointer->GetVectorLength(); i++)
68 for (unsigned int j=0; j<m_ChannelIndices.size(); j++)
69 if (m_ChannelIndices.at(j)==i)
76 m_NewDirections->InsertElement(chIdx, m_Directions->GetElement(i));
78 MITK_INFO << "Using channel " << i;
83 template< class TInPixelType >
84 void RemoveDwiChannelFilter< TInPixelType>::ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, ThreadIdType id )
86 typename OutputImageType::Pointer outputImage = static_cast< OutputImageType * >(this->ProcessObject::GetOutput(0));
88 ImageRegionIterator< OutputImageType > oit(outputImage, outputRegionForThread);
91 typedef ImageRegionConstIterator< InputImageType > InputIteratorType;
92 typename InputImageType::Pointer inputImagePointer = static_cast< InputImageType * >( this->ProcessObject::GetInput(0) );
94 InputIteratorType git( inputImagePointer, outputRegionForThread );
96 while( !git.IsAtEnd() )
99 typename OutputImageType::PixelType pix = oit.Get();
100 for (unsigned int i=0; i<inputImagePointer->GetVectorLength(); i++)
103 for (unsigned int j=0; j<m_ChannelIndices.size(); j++)
104 if (m_ChannelIndices.at(j)==i)
111 pix[chIdx] = git.Get()[i];
120 std::cout << "One Thread finished calculation" << std::endl;
123 template< class TInPixelType >
125 RemoveDwiChannelFilter< TInPixelType>
126 ::PrintSelf(std::ostream& os, Indent indent) const
128 Superclass::PrintSelf(os,indent);
133 #endif // __itkRemoveDwiChannelFilter_txx