Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
itkDwiNormilzationFilter.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 __itkDwiNormilzationFilter_txx
18 #define __itkDwiNormilzationFilter_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 #include <itkNumericTraits.h>
31 
32 namespace itk {
33 
34 
35 template< class TInPixelType >
36 DwiNormilzationFilter< TInPixelType>::DwiNormilzationFilter()
37  :m_B0Index(-1)
38  ,m_ScalingFactor(1000)
39  ,m_UseGlobalReference(false)
40 {
41  this->SetNumberOfRequiredInputs( 1 );
42 }
43 
44 template< class TInPixelType >
45 void DwiNormilzationFilter< TInPixelType>::BeforeThreadedGenerateData()
46 {
47  typename InputImageType::Pointer inputImagePointer = static_cast< InputImageType * >( this->ProcessObject::GetInput(0) );
48 
49  m_B0Index = -1;
50  for (unsigned int i=0; i<inputImagePointer->GetVectorLength(); i++)
51  {
52  GradientDirectionType g = m_GradientDirections->GetElement(i);
53  if (g.magnitude()<0.001)
54  m_B0Index = i;
55  }
56  if (m_B0Index==-1)
57  itkExceptionMacro(<< "DwiNormilzationFilter: No b-Zero indecies found!");
58 
59  if (m_UseGlobalReference)
60  MITK_INFO << "Using global reference value: " << m_Reference;
61 }
62 
63 template< class TInPixelType >
64 void DwiNormilzationFilter< TInPixelType>::ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread, ThreadIdType )
65 {
66  typename OutputImageType::Pointer outputImage = static_cast< OutputImageType * >(this->ProcessObject::GetOutput(0));
67 
68  ImageRegionIterator< OutputImageType > oit(outputImage, outputRegionForThread);
69  oit.GoToBegin();
70 
71  typedef ImageRegionConstIterator< InputImageType > InputIteratorType;
72  typename InputImageType::Pointer inputImagePointer = static_cast< InputImageType * >( this->ProcessObject::GetInput(0) );
73 
74  typename OutputImageType::PixelType nullPix;
75  nullPix.SetSize(inputImagePointer->GetVectorLength());
76  nullPix.Fill(0);
77 
78  InputIteratorType git( inputImagePointer, outputRegionForThread );
79  git.GoToBegin();
80  while( !git.IsAtEnd() )
81  {
82  typename InputImageType::PixelType pix = git.Get();
83  typename OutputImageType::PixelType outPix;
84  outPix.SetSize(inputImagePointer->GetVectorLength());
85 
86  double S0 = pix[m_B0Index];
87  if (m_UseGlobalReference)
88  S0 = m_Reference;
89 
90  if (S0>0.1 && pix[m_B0Index]>0)
91  {
92  for (unsigned int i=0; i<inputImagePointer->GetVectorLength(); i++)
93  {
94  double val = (double)pix[i];
95 
96  if (val!=val || val<0)
97  val = 0;
98  else
99  {
100  val /= S0;
101  val *= (double)m_ScalingFactor;
102  }
103  outPix[i] = (TInPixelType)val;
104  }
105  oit.Set(outPix);
106  }
107  else
108  oit.Set(nullPix);
109 
110  ++oit;
111  ++git;
112  }
113 
114  std::cout << "One Thread finished calculation" << std::endl;
115 }
116 
117 template< class TInPixelType >
118 void
119 DwiNormilzationFilter< TInPixelType>
120 ::PrintSelf(std::ostream& os, Indent indent) const
121 {
122  Superclass::PrintSelf(os,indent);
123 }
124 
125 }
126 
127 #endif // __itkDwiNormilzationFilter_txx