Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
mitkTensorModel.cpp
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 #include <vnl/vnl_cross.h>
17 #include <vnl/vnl_quaternion.h>
18 #include <mitkTensorModel.h>
19 
20 using namespace mitk;
21 
22 template< class ScalarType >
24  : m_BValue(1000)
25 {
27  m_KernelTensorMatrix.fill(0.0);
28  m_KernelTensorMatrix[0][0] = 0.002;
29  m_KernelTensorMatrix[1][1] = 0.0005;
30  m_KernelTensorMatrix[2][2] = 0.0005;
31 }
32 
33 template< class ScalarType >
35 {
36 
37 }
38 
39 template< class ScalarType >
41 {
42  ScalarType signal = 0;
43 
44  if (dir>=this->m_GradientList.size())
45  return signal;
46 
47  ItkTensorType tensor; tensor.Fill(0.0);
48  this->m_FiberDirection.Normalize();
49  vnl_vector_fixed<double, 3> axis = itk::CrossProduct(m_KernelDirection, this->m_FiberDirection).GetVnlVector(); axis.normalize();
50  vnl_quaternion<double> rotation(axis, acos(m_KernelDirection*this->m_FiberDirection));
51  rotation.normalize();
52  vnl_matrix_fixed<double, 3, 3> matrix = rotation.rotation_matrix_transpose();
53 
54  vnl_matrix_fixed<double, 3, 3> tensorMatrix = matrix.transpose()*m_KernelTensorMatrix*matrix;
55  tensor[0] = tensorMatrix[0][0]; tensor[1] = tensorMatrix[0][1]; tensor[2] = tensorMatrix[0][2];
56  tensor[3] = tensorMatrix[1][1]; tensor[4] = tensorMatrix[1][2]; tensor[5] = tensorMatrix[2][2];
57 
58  GradientType g = this->m_GradientList[dir];
59  ScalarType bVal = g.GetNorm(); bVal *= bVal;
60 
61  if (bVal>0.0001)
62  {
63  itk::DiffusionTensor3D< ScalarType > S;
64  S[0] = g[0]*g[0];
65  S[1] = g[1]*g[0];
66  S[2] = g[2]*g[0];
67  S[3] = g[1]*g[1];
68  S[4] = g[2]*g[1];
69  S[5] = g[2]*g[2];
70 
71  ScalarType D = tensor[0]*S[0] + tensor[1]*S[1] + tensor[2]*S[2] +
72  tensor[1]*S[1] + tensor[3]*S[3] + tensor[4]*S[4] +
73  tensor[2]*S[2] + tensor[4]*S[4] + tensor[5]*S[5];
74 
75  // check for corrupted tensor and generate signal
76  if (D>=0)
77  signal = std::exp ( -m_BValue * bVal * D );
78  }
79  else
80  signal = 1;
81 
82  return signal;
83 }
84 
85 template< class ScalarType >
87 {
88  PixelType signal; signal.SetSize(this->m_GradientList.size()); signal.Fill(0.0);
89 
90  ItkTensorType tensor; tensor.Fill(0.0);
91  this->m_FiberDirection.Normalize();
92  vnl_vector_fixed<double, 3> axis = itk::CrossProduct(m_KernelDirection, this->m_FiberDirection).GetVnlVector(); axis.normalize();
93  vnl_quaternion<double> rotation(axis, acos(m_KernelDirection*this->m_FiberDirection));
94  rotation.normalize();
95  vnl_matrix_fixed<double, 3, 3> matrix = rotation.rotation_matrix_transpose();
96 
97  vnl_matrix_fixed<double, 3, 3> tensorMatrix = matrix.transpose()*m_KernelTensorMatrix*matrix;
98  tensor[0] = tensorMatrix[0][0]; tensor[1] = tensorMatrix[0][1]; tensor[2] = tensorMatrix[0][2];
99  tensor[3] = tensorMatrix[1][1]; tensor[4] = tensorMatrix[1][2]; tensor[5] = tensorMatrix[2][2];
100 
101  for( unsigned int i=0; i<this->m_GradientList.size(); i++)
102  {
103  GradientType g = this->m_GradientList[i];
104  ScalarType bVal = g.GetNorm(); bVal *= bVal;
105 
106  if (bVal>0.0001)
107  {
108  itk::DiffusionTensor3D< ScalarType > S;
109  S[0] = g[0]*g[0];
110  S[1] = g[1]*g[0];
111  S[2] = g[2]*g[0];
112  S[3] = g[1]*g[1];
113  S[4] = g[2]*g[1];
114  S[5] = g[2]*g[2];
115 
116  ScalarType D = tensor[0]*S[0] + tensor[1]*S[1] + tensor[2]*S[2] +
117  tensor[1]*S[1] + tensor[3]*S[3] + tensor[4]*S[4] +
118  tensor[2]*S[2] + tensor[4]*S[4] + tensor[5]*S[5];
119 
120  // check for corrupted tensor and generate signal
121  if (D>=0)
122  signal[i] = std::exp ( -m_BValue * bVal * D );
123  }
124  else
125  signal[i] = 1;
126  }
127 
128  return signal;
129 }
vnl_matrix_fixed< double, 3, 3 > m_KernelTensorMatrix
3x3 matrix containing the kernel tensor values
double ScalarType
DataCollection - Class to facilitate loading/accessing structured data.
static Matrix3D rotation
itk::Vector< double, 3 > GradientType
GradientType m_KernelDirection
Direction of the kernel tensors principal eigenvector.
PixelType SimulateMeasurement()
itk::DiffusionTensor3D< ScalarType > ItkTensorType