Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #ifndef __itkB0ImageExtractionImageFilter_txx
00017 #define __itkB0ImageExtractionImageFilter_txx
00018
00019 #include "itkB0ImageExtractionImageFilter.h"
00020
00021 namespace itk {
00022
00023 template< class TInputImagePixelType,
00024 class TOutputImagePixelType >
00025 B0ImageExtractionImageFilter< TInputImagePixelType,
00026 TOutputImagePixelType >
00027 ::B0ImageExtractionImageFilter()
00028 {
00029
00030
00031 this->SetNumberOfRequiredInputs( 1 );
00032 }
00033
00034 template< class TInputImagePixelType,
00035 class TOutputImagePixelType >
00036 void B0ImageExtractionImageFilter< TInputImagePixelType,
00037 TOutputImagePixelType >
00038 ::GenerateData()
00039 {
00040
00041 typename GradientDirectionContainerType::Iterator begin = m_Directions->Begin();
00042 typename GradientDirectionContainerType::Iterator end = m_Directions->End();
00043
00044
00045 std::vector<int> indices;
00046 int index = 0;
00047 while(begin!=end)
00048 {
00049 GradientDirectionType grad = begin->Value();
00050
00051 if(grad[0] == 0 && grad[1] == 0 && grad[2] == 0)
00052 {
00053 indices.push_back(index);
00054 }
00055 ++index;
00056 ++begin;
00057 }
00058
00059 typedef itk::Image<float,3> TempImageType;
00060 TempImageType::Pointer tmp = TempImageType::New();
00061 typename TempImageType::RegionType region = this->GetInput()->GetLargestPossibleRegion();
00062
00063 tmp->SetSpacing(this->GetInput()->GetSpacing());
00064 tmp->SetOrigin(this->GetInput()->GetOrigin());
00065 tmp->SetDirection(this->GetInput()->GetDirection());
00066 tmp->SetRegions(region);
00067 tmp->Allocate();
00068
00069 itk::ImageRegionIterator<TempImageType> it(tmp.GetPointer(), tmp->GetLargestPossibleRegion() );
00070 itk::ImageRegionConstIterator<InputImageType> vectorIt(this->GetInput(), this->GetInput()->GetLargestPossibleRegion() );
00071
00072 it.GoToBegin();
00073 while(!it.IsAtEnd())
00074 {
00075 it.Set(0);
00076 ++it;
00077 }
00078
00079
00080 for(std::vector<int>::iterator indexIt = indices.begin();
00081 indexIt != indices.end();
00082 indexIt++)
00083 {
00084 it.GoToBegin();
00085 vectorIt.GoToBegin();
00086
00087 while(!it.IsAtEnd() && !vectorIt.IsAtEnd())
00088 {
00089 typename InputImageType::PixelType vec = vectorIt.Get();
00090 it.Set((1.0 * it.Get()) + (1.0 * vec[*indexIt]) / (1.0 * indices.size()));
00091 ++it;
00092 ++vectorIt;
00093 }
00094 }
00095
00096 typename OutputImageType::Pointer b0Image =
00097 static_cast< OutputImageType * >(this->ProcessObject::GetOutput(0));
00098 typename OutputImageType::RegionType outregion = this->GetInput()->GetLargestPossibleRegion();
00099 b0Image->SetSpacing(this->GetInput()->GetSpacing());
00100 b0Image->SetOrigin(this->GetInput()->GetOrigin());
00101 b0Image->SetDirection(this->GetInput()->GetDirection());
00102 b0Image->SetRegions(outregion);
00103 b0Image->Allocate();
00104 itk::ImageRegionIterator<TempImageType> itIn(tmp, tmp->GetLargestPossibleRegion() );
00105 itk::ImageRegionIterator<OutputImageType> itOut(b0Image, b0Image->GetLargestPossibleRegion() );
00106 itIn.GoToBegin();
00107 itOut.GoToBegin();
00108 while(!itIn.IsAtEnd())
00109 {
00110 itOut.Set(itIn.Get());
00111 ++itIn;
00112 ++itOut;
00113 }
00114 }
00115
00116 }
00117
00118 #endif // __itkB0ImageExtractionImageFilter_txx