ANIMA  4.0
animaSimuBlochSP-GRE.hxx
Go to the documentation of this file.
1 #pragma once
2 #include "animaSimuBlochSP-GRE.h"
3 
4 #include <itkObjectFactory.h>
5 #include <itkImageRegionIterator.h>
6 #include <itkImageRegionConstIterator.h>
7 
8 namespace anima
9 {
10 
11 template< class TImage>
13 {
14  this->SetNumberOfRequiredInputs(3);
15 }
16 
17 template< class TImage>
18 void SimuBlochSPGRE<TImage>::SetInputT1(const TImage* T1)
19 {
20  SetInput(0, const_cast<TImage*>(T1));
21 }
22 
23 template< class TImage>
24 void SimuBlochSPGRE<TImage>::SetInputT2s(const TImage* T2s)
25 {
26  SetInput(1, const_cast<TImage*>(T2s));
27 }
28 
29 template< class TImage>
30 void SimuBlochSPGRE<TImage>::SetInputM0(const TImage* M0)
31 {
32  SetInput(2, const_cast<TImage*>(M0));
33 }
34 
35 template< class TImage>
36 void SimuBlochSPGRE<TImage>::SetInputB1(const TImage* B1)
37 {
38  this->SetInput(3, const_cast<TImage*>(B1));
39 }
40 
41 template< class TImage>
44 {
45  typename TImage::ConstPointer T1 = this->GetInput(0);
46  typename TImage::ConstPointer T2s = this->GetInput(1);
47  typename TImage::ConstPointer M0 = this->GetInput(2);
48  typename TImage::ConstPointer B1;
49 
50  itk::ImageRegionIterator<TImage> outputIterator(this->GetOutput(), outputRegionForThread);
51  itk::ImageRegionConstIterator<TImage> inputIteratorT1(T1, outputRegionForThread);
52  itk::ImageRegionConstIterator<TImage> inputIteratorT2s(T2s, outputRegionForThread);
53  itk::ImageRegionConstIterator<TImage> inputIteratorM0(M0, outputRegionForThread);
54 
55  itk::ImageRegionConstIterator<TImage> inputIteratorB1;
56  bool b1DataPresent = (this->GetNumberOfIndexedInputs() == 4);
57  if (b1DataPresent)
58  {
59  B1 = this->GetInput(3);
60  inputIteratorB1 = itk::ImageRegionConstIterator<TImage> (B1, outputRegionForThread);
61  }
62 
63  // For each voxel, calculate the signal of SP-GRE
64  while(!outputIterator.IsAtEnd())
65  {
66  if ((inputIteratorT1.Get() <= 0) || (inputIteratorT2s.Get() <= 0))
67  {
68  outputIterator.Set(0);
69 
70  ++inputIteratorT1;
71  ++inputIteratorT2s;
72  ++inputIteratorM0;
73  if (b1DataPresent)
74  ++inputIteratorB1;
75 
76  ++outputIterator;
77  continue;
78  }
79 
80  double b1Value = 1;
81  if (b1DataPresent)
82  b1Value = inputIteratorB1.Get();
83 
84  double t1Value = inputIteratorT1.Get();
85  double t2sValue = inputIteratorT2s.Get();
86  double m0Value = inputIteratorM0.Get();
87 
88  double sinFA = std::sin(M_PI * b1Value * m_FA / 180);
89  double cosFA = std::cos(M_PI * b1Value * m_FA / 180);
90 
91  outputIterator.Set(m0Value * (1- exp(- m_TR / t1Value)) * sinFA / (1 - exp(- m_TR / t1Value) * cosFA ) * exp(- m_TE / t2sValue));
92 
93  ++inputIteratorT1;
94  ++inputIteratorT2s;
95  ++inputIteratorM0;
96  if (b1DataPresent)
97  ++inputIteratorB1;
98 
99  ++outputIterator;
100  }
101 }
102 
103 }// end of namespace anima
void SetInputT1(const TImage *T1)
void SetInputM0(const TImage *M0)
void SetInputB1(const TImage *B1)
Superclass::OutputImageRegionType OutputImageRegionType
void SetInputT2s(const TImage *T2s)
virtual void DynamicThreadedGenerateData(const OutputImageRegionType &outputRegionForThread) ITK_OVERRIDE