DMRITool  v0.1.1-139-g860d86b4
Diffusion MRI Tool
itkTensorBasisMatrixGenerator.hxx
Go to the documentation of this file.
1 
18 #ifndef __itkTensorBasisMatrixGenerator_hxx
19 #define __itkTensorBasisMatrixGenerator_hxx
20 
23 
24 namespace itk
25 {
26 
27 template<typename TElement>
30 {
31  m_EigenValue1=-1;
32  m_EigenValue2=-1;
33  m_EigenValue3=-1;
34  m_EigenValueISO=-1;
35 }
36 
37 template<typename TElement>
38 typename LightObject::Pointer
41 {
42  utlShowPosition(this->GetDebug());
43  typename LightObject::Pointer loPtr = Superclass::InternalClone();
44 
45  typename Self::Pointer rval = dynamic_cast<Self *>(loPtr.GetPointer());
46  if(rval.IsNull())
47  {
48  itkExceptionMacro(<< "downcast to type " << this->GetNameOfClass()<< " failed.");
49  }
50  rval->m_EigenValue1 = m_EigenValue1;
51  rval->m_EigenValue2 = m_EigenValue2;
52  rval->m_EigenValue3 = m_EigenValue3;
53  rval->m_EigenValueISO = m_EigenValueISO;
54  return loPtr;
55 }
56 
57 template<typename TElement>
58 void
60 ::PrintSelf(std::ostream& os, Indent indent) const
61 {
62  Superclass::PrintSelf(os, indent);
63  PrintVar3(true, m_EigenValue1, m_EigenValue2, m_EigenValue3, os<<indent);
64  PrintVar1(true, m_EigenValueISO, os<<indent);
65 }
66 
67 template<typename TElement>
68 void
71 {
72  Superclass::VerifyInputParameters();
73 
74  utlSAGlobalException(m_EigenValue1<0 || m_EigenValue2<0 || m_EigenValue3<0)(m_EigenValue1)(m_EigenValue2)(m_EigenValue3).msg("need to set m_EigenValue1, m_EigenValue2, m_EigenValue3");
75  utlSAGlobalException(this->m_UseIsotropicTerm && m_EigenValueISO<0)(m_EigenValueISO).msg("need to set m_EigenValueISO");
76 
77  utlGlobalException(this->m_OutputType==Superclass::DWI && this->m_SamplingSchemeQSpace->GetBVector()->size()==0, "no bVector");
78 }
79 
80 
81 template<typename TElement>
82 void
85 {
86  utlShowPosition(this->GetDebug());
87  VerifyInputParameters();
88 
89  MatrixPointer qOrientations = this->m_SamplingSchemeQSpace->GetOrientationsCartesian();
90  STDVectorPointer bVector = this->m_SamplingSchemeQSpace->GetBVector();
91  MatrixPointer rOrientations = this->m_SamplingSchemeRSpace->GetOrientationsCartesian();
92  STDVectorPointer rVector = this->m_SamplingSchemeRSpace->GetRadiusVector();
93  double tau = this->m_SamplingSchemeQSpace->GetTau();
94 
95  int numberOfBasis = this->GetNumberOfBasis();
96  int numberOfSamples = -1;
97  // if (this->m_OutputType==Superclass::DWI)
98  // numberOfSamples = this->GetNumberOfQSamples();
99  // else if (this->m_OutputType==Superclass::EAP || this->m_OutputType==Superclass::ODF)
100  // numberOfSamples = this->GetNumberOfRSamples();
101  numberOfSamples = this->GetNumberOfSamples();
102  MatrixPointer mat (new MatrixType(numberOfSamples, numberOfBasis) );
103 
104  TensorType tensor;
105  std::vector<double> vec(3,1);
106  vec[0]=m_EigenValue1, vec[1]=m_EigenValue2, vec[2]=m_EigenValue3;
107 
108  Vector<double, 3> principalDirection(0.0);
109  Vector<double, 3> e1;
110  e1[0]=1.0, e1[1]=0.0, e1[2]=0.0;
111  Matrix<double,3,3> rotation;
112 
113  VectorType out(numberOfSamples);
114  for ( int i = 0; i < this->m_BasisOrientations->Rows(); i += 1 )
115  {
116  tensor.Fill(0.0);
117  tensor.SetEigenValues(vec);
118 
119  principalDirection[0] = (*this->m_BasisOrientations)(i,0);
120  principalDirection[1] = (*this->m_BasisOrientations)(i,1);
121  principalDirection[2] = (*this->m_BasisOrientations)(i,2);
122  utl::RotationMatrixFromVectors<Vector<double,3>, Matrix<double,3> >(e1, principalDirection, rotation);
123  tensor.Rotate(rotation);
124 
125  // std::cout << "tensor = " << tensor << std::endl << std::flush;
126  if (this->m_OutputType==Superclass::DWI)
127  tensor.GetDWISamples(out, *qOrientations, *bVector);
128  else if (this->m_OutputType==Superclass::EAP)
129  tensor.GetEAPSamples(out, *rOrientations, *rVector, tau);
130  else if (this->m_OutputType==Superclass::ODF)
131  tensor.GetODFSamples(out, *rOrientations, this->m_ODFOrder, false);
132 
133  // utl::PrintVnlVector(out, "out");
134  if (this->m_UseIsotropicTerm)
135  mat->SetColumn(i+1, out);
136  else
137  mat->SetColumn(i, out);
138  }
139 
140  if (this->m_UseIsotropicTerm)
141  {
142  vec[0]=m_EigenValueISO, vec[1]=m_EigenValueISO, vec[2]=m_EigenValueISO;
143  tensor.Fill(0.0);
144  tensor.SetEigenValues(vec);
145 
146  if (this->m_OutputType==Superclass::DWI)
147  tensor.GetDWISamples(out, *qOrientations, *bVector);
148  else if (this->m_OutputType==Superclass::EAP)
149  tensor.GetEAPSamples(out, *rOrientations, *rVector, tau);
150  else if (this->m_OutputType==Superclass::ODF)
151  tensor.GetODFSamples(out, *rOrientations, this->m_ODFOrder, false);
152 
153  mat->SetColumn(0, out);
154  }
155 
156  if (this->m_OutputType==Superclass::DWI)
157  this->m_QBasisMatrixForDWI = mat;
158  else if (this->m_OutputType==Superclass::EAP)
159  this->m_RBasisMatrixForEAP = mat;
160  else if (this->m_OutputType==Superclass::ODF)
161  this->m_RBasisMatrixForODF = mat;
162 
163 }
164 
165 
166 
167 
168 }
169 
170 
171 #endif
172 
173 
174 
175 
void GetEAPSamples(TVectorType &vec, const utl::NDArray< TPrecision, 2 > &gradients, const std::vector< TPrecision > &rValues, const TPrecision &tau) const
void PrintSelf(std::ostream &os, Indent indent) const ITK_OVERRIDE
#define PrintVar1(cond, var, os)
Definition: utlCoreMacro.h:447
LightObject::Pointer InternalClone() const ITK_OVERRIDE
void GetDWISamples(TVectorType &vec, const utl::NDArray< TPrecision, 2 > &gradients, const std::vector< TPrecision > &bValues) const
#define utlSAGlobalException(expr)
Definition: utlCoreMacro.h:362
utl_shared_ptr< STDVectorType > STDVectorPointer
Self & Rotate(const typename Self::MatrixType &mat)
utl_shared_ptr< MatrixType > MatrixPointer
#define utlGlobalException(cond, expout)
Definition: utlCoreMacro.h:372
void SetEigenValues(const TArrayType &array)
#define PrintVar3(cond, var1, var2, var3, os)
Definition: utlCoreMacro.h:462
#define utlShowPosition(cond)
Definition: utlCoreMacro.h:554
virtual void VerifyInputParameters() const ITK_OVERRIDE
void GetODFSamples(TVectorType &vec, const utl::NDArray< TPrecision, 2 > &gradients, const int &odfOrder=2, const bool &isNormalize=false) const
tensor with some useful functions