Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkAstroStickModel.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 <mitkAstroStickModel.h>
19 
20 using namespace mitk;
21 
22 template< class ScalarType >
24  : m_BValue(1000)
25  , m_Diffusivity(0.001)
26  , m_NumSticks(42)
27  , m_RandomizeSticks(false)
28 {
30  this->m_RandGen->SetSeed();
31 
32  vnl_matrix_fixed<double,3,42>* sticks = itk::PointShell<42, vnl_matrix_fixed<double, 3, 42> >::DistributePointShell();
33  for (unsigned int i=0; i<m_NumSticks; i++)
34  {
35  GradientType stick;
36  stick[0] = sticks->get(0,i); stick[1] = sticks->get(1,i); stick[2] = sticks->get(2,i);
37  stick.Normalize();
38  m_Sticks.push_back(stick);
39  }
40 }
41 
42 template< class ScalarType >
44 {
45 
46 }
47 
48 template< class ScalarType >
50 {
51  ScalarType signal = 0;
52 
53  if (dir>=this->m_GradientList.size())
54  return signal;
55 
56  ScalarType b = -m_BValue*m_Diffusivity;
57 
58  if (m_RandomizeSticks) // random number of sticks
59  m_NumSticks = 30 + this->m_RandGen->GetIntegerVariate()%31;
60 
61  GradientType g = this->m_GradientList[dir];
62  ScalarType bVal = g.GetNorm(); bVal *= bVal;
63 
64  if (bVal>0.0001) // is weighted direction
65  {
66  for (unsigned int j=0; j<m_NumSticks; j++)
67  {
68  ScalarType dot = 0;
69  if(m_RandomizeSticks)
70  dot = GetRandomDirection()*g;
71  else
72  dot = m_Sticks[j]*g;
73  signal += std::exp( (double)(b*bVal*dot*dot) );
74  }
75  signal /= m_NumSticks;
76  }
77  else // is baseline direction
78  signal = 1;
79 
80  return signal;
81 }
82 
83 template< class ScalarType >
85 {
86  GradientType vec;
87  vec[0] = this->m_RandGen->GetNormalVariate();
88  vec[1] = this->m_RandGen->GetNormalVariate();
89  vec[2] = this->m_RandGen->GetNormalVariate();
90  vec.Normalize();
91  return vec;
92 }
93 
94 template< class ScalarType >
96 {
97  PixelType signal;
98  signal.SetSize(this->m_GradientList.size());
99  ScalarType b = -m_BValue*m_Diffusivity;
100 
101  if (m_RandomizeSticks)
102  m_NumSticks = 30 + this->m_RandGen->GetIntegerVariate()%31;
103 
104  for( unsigned int i=0; i<this->m_GradientList.size(); i++)
105  {
106  GradientType g = this->m_GradientList[i];
107  ScalarType bVal = g.GetNorm(); bVal *= bVal;
108 
109  if (bVal>0.0001)
110  {
111  for (unsigned int j=0; j<m_NumSticks; j++)
112  {
113  ScalarType dot = 0;
114  if(m_RandomizeSticks)
115  dot = GetRandomDirection()*g;
116  else
117  dot = m_Sticks[j]*g;
118  signal[i] += std::exp( (double)(b*bVal*dot*dot) );
119  }
120  signal[i] /= m_NumSticks;
121  }
122  else
123  signal[i] = 1;
124  }
125 
126  return signal;
127 }
GradientListType m_Sticks
Stick container.
GradientType GetRandomDirection()
unsigned int m_NumSticks
Number of sticks.
double ScalarType
DataCollection - Class to facilitate loading/accessing structured data.
ItkRandGenType::Pointer m_RandGen
Random number generator.
DiffusionSignalModel< ScalarType >::GradientType GradientType
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.