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 __itkDwiNormilzationFilter_txx
18 #define __itkDwiNormilzationFilter_txx
24 #define _USE_MATH_DEFINES
27 #include "itkImageRegionConstIterator.h"
28 #include "itkImageRegionConstIteratorWithIndex.h"
29 #include "itkImageRegionIterator.h"
30 #include <itkNumericTraits.h>
35 template< class TInPixelType >
36 DwiNormilzationFilter< TInPixelType>::DwiNormilzationFilter()
38 ,m_ScalingFactor(1000)
39 ,m_UseGlobalReference(false)
41 this->SetNumberOfRequiredInputs( 1 );
44 template< class TInPixelType >
45 void DwiNormilzationFilter< TInPixelType>::BeforeThreadedGenerateData()
47 typename InputImageType::Pointer inputImagePointer = static_cast< InputImageType * >( this->ProcessObject::GetInput(0) );
50 for (unsigned int i=0; i<inputImagePointer->GetVectorLength(); i++)
52 GradientDirectionType g = m_GradientDirections->GetElement(i);
53 if (g.magnitude()<0.001)
57 itkExceptionMacro(<< "DwiNormilzationFilter: No b-Zero indecies found!");
59 if (m_UseGlobalReference)
60 MITK_INFO << "Using global reference value: " << m_Reference;
63 template< class TInPixelType >
64 void DwiNormilzationFilter< TInPixelType>::ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, ThreadIdType )
66 typename OutputImageType::Pointer outputImage = static_cast< OutputImageType * >(this->ProcessObject::GetOutput(0));
68 ImageRegionIterator< OutputImageType > oit(outputImage, outputRegionForThread);
71 typedef ImageRegionConstIterator< InputImageType > InputIteratorType;
72 typename InputImageType::Pointer inputImagePointer = static_cast< InputImageType * >( this->ProcessObject::GetInput(0) );
74 typename OutputImageType::PixelType nullPix;
75 nullPix.SetSize(inputImagePointer->GetVectorLength());
78 InputIteratorType git( inputImagePointer, outputRegionForThread );
80 while( !git.IsAtEnd() )
82 typename InputImageType::PixelType pix = git.Get();
83 typename OutputImageType::PixelType outPix;
84 outPix.SetSize(inputImagePointer->GetVectorLength());
86 double S0 = pix[m_B0Index];
87 if (m_UseGlobalReference)
90 if (S0>0.1 && pix[m_B0Index]>0)
92 for (unsigned int i=0; i<inputImagePointer->GetVectorLength(); i++)
94 double val = (double)pix[i];
96 if (val!=val || val<0)
101 val *= (double)m_ScalingFactor;
103 outPix[i] = (TInPixelType)val;
114 std::cout << "One Thread finished calculation" << std::endl;
117 template< class TInPixelType >
119 DwiNormilzationFilter< TInPixelType>
120 ::PrintSelf(std::ostream& os, Indent indent) const
122 Superclass::PrintSelf(os,indent);
127 #endif // __itkDwiNormilzationFilter_txx