aimsdata  5.0.5
Neuroimaging data handling
dtitensor.h
Go to the documentation of this file.
1 /* This software and supporting documentation are distributed by
2  * Institut Federatif de Recherche 49
3  * CEA/NeuroSpin, Batiment 145,
4  * 91191 Gif-sur-Yvette cedex
5  * France
6  *
7  * This software is governed by the CeCILL-B license under
8  * French law and abiding by the rules of distribution of free software.
9  * You can use, modify and/or redistribute the software under the
10  * terms of the CeCILL-B license as circulated by CEA, CNRS
11  * and INRIA at the following URL "http://www.cecill.info".
12  *
13  * As a counterpart to the access to the source code and rights to copy,
14  * modify and redistribute granted by the license, users are provided only
15  * with a limited warranty and the software's author, the holder of the
16  * economic rights, and the successive licensors have only limited
17  * liability.
18  *
19  * In this respect, the user's attention is drawn to the risks associated
20  * with loading, using, modifying and/or developing or reproducing the
21  * software by the user in light of its specific status of free software,
22  * that may mean that it is complicated to manipulate, and that also
23  * therefore means that it is reserved for developers and experienced
24  * professionals having in-depth computer knowledge. Users are therefore
25  * encouraged to load and test the software's suitability as regards their
26  * requirements in conditions enabling the security of their systems and/or
27  * data to be ensured and, more generally, to use and operate it in the
28  * same conditions as regards security.
29  *
30  * The fact that you are presently reading this means that you have had
31  * knowledge of the CeCILL-B license and that you accept its terms.
32  */
33 
34 /*
35  * 2nd order tensor class for DTI
36  */
37 #ifndef AIMS_MATH_DTITENSOR_H
38 #define AIMS_MATH_DTITENSOR_H
39 
40 #include <aims/math/tensor.h>
41 #include <aims/math/mathelem.h>
42 #include <cartobase/type/types.h>
43 
44 
45 class DtiTensor;
46 
47 float volumeRatio( const DtiTensor& thing );
48 float fractionalAniso( const DtiTensor& thing );
49 std::ostream& operator << (std::ostream& os, const DtiTensor& thing);
50 
51 
52 class DtiTensor
53 {
54  public:
55 
56  enum
57  {
58  CORRECTED_N26 = 0, // corrected with estimation of mean diffusivity on N26
59  CORRECTED_TC, // corrected with estimation of mean diffusivity on
60  // tensor coefficients
65  };
66 
67 
68  DtiTensor() { }
69  DtiTensor( const Trieder& trieder, const Point3df& eigenvalue )
70  : _base( trieder, eigenvalue )
71  { }
73  : _base( coef )
74  { }
75  DtiTensor( const Tensor& other ) : _base( other )
76  { }
77  DtiTensor(const DtiTensor& other) : _base( other._base ),
78  _dir( other._dir ),
79  _location( other._location ),
82  _category( other._category )
83  { }
84  virtual ~DtiTensor() { }
85 
86  const Tensor& base() const { return _base; }
87  Tensor& base() { return _base; }
88 
89  const Point3df& dir() const { return _dir; }
90  Point3df& dir() { return _dir; }
91 
92  const Point3df& location() const { return _location; }
93  Point3df& location() { return _location; }
94 
95  const float& anisotropyVR() const { return _anisotropyVR; }
96  float& anisotropyVR() { return _anisotropyVR; }
97 
98  const float& anisotropyFA() const { return _anisotropyFA; }
99  float& anisotropyFA() { return _anisotropyFA; }
100 
101  const int& category() const { return _category; }
102  int& category() { return _category; }
103 
104  const short& index() const { return _index; }
105  short& index() { return _index; }
106 
107  friend
108  std::ostream& operator << (std::ostream& os, const DtiTensor& thing);
109 
110  protected:
117  short _index;
118 };
119 
120 
121 #ifndef DOXYGEN_HIDE_INTERNAL_CLASSES
122 
123 namespace carto
124 {
125 
126  template<> inline std::string DataTypeCode<DtiTensor>::dataType()
127  {
128  return "DTITENSOR";
129  }
130 
131 }
132 
133 #endif // DOXYGEN_HIDE_INTERNAL_CLASSES
134 
135 
136 inline
137 float volumeRatio( const DtiTensor& thing )
138 {
139 
140  float averageDc = thing.base().meanDiffusivity();
141  if ( averageDc <= 0.0 )
142  return 0.0;
143 
144  float thirdInvariant = thing.base().coef().item( 0 ) *
145  ( thing.base().coef().item( 3 ) *
146  thing.base().coef().item( 5 ) -
147  thing.base().coef().item( 4 ) *
148  thing.base().coef().item( 4 ) ) -
149  thing.base().coef().item( 1 ) *
150  ( thing.base().coef().item( 1 ) *
151  thing.base().coef().item( 5 ) -
152  thing.base().coef().item( 2 ) *
153  thing.base().coef().item( 4 ) ) +
154  thing.base().coef().item( 2 ) *
155  ( thing.base().coef().item( 1 ) *
156  thing.base().coef().item( 4 ) -
157  thing.base().coef().item( 2 ) *
158  thing.base().coef().item( 3 ) );
159 
160  if ( thirdInvariant < 0.0 )
161  return 1.0;
162 
163  float val = 1.0 - thirdInvariant / cube( averageDc );
164 
165  if ( val < 0.0 )
166  return 0.0;
167 
168  return val;
169 
170 }
171 
172 
173 inline
174 float fractionalAniso( const DtiTensor& thing )
175 {
176 
177  float averageDc = thing.base().meanDiffusivity();
178 
179  float fourthInvariant = thing.base().coef().item( 0 ) *
180  thing.base().coef().item( 0 ) +
181  thing.base().coef().item( 3 ) *
182  thing.base().coef().item( 3 ) +
183  thing.base().coef().item( 5 ) *
184  thing.base().coef().item( 5 ) +
185  ( thing.base().coef().item( 1 ) *
186  thing.base().coef().item( 1 ) +
187  thing.base().coef().item( 2 ) *
188  thing.base().coef().item( 2 ) +
189  thing.base().coef().item( 4 ) *
190  thing.base().coef().item( 4 ) ) * 2.0;
191 
192  float magnitudeDc = ( fourthInvariant < 0.0 ? 0.0 :
193  sqrt( fourthInvariant / 3.0 ) );
194 
195  float val = ( float )sqrt( 1.5 * ( 1.0 - ( averageDc * averageDc ) /
196  ( magnitudeDc * magnitudeDc ) ) );
197  if ( val > 1.0 )
198  val = 1.0;
199 
200  return val;
201 
202 }
203 
204 
205 inline
206 std::ostream& operator << (std::ostream& os, const DtiTensor& thing)
207 {
208  os << "{base=" << thing.base()
209  << ",dir=" << thing.dir()
210  << ",location=" << thing.location()
211  << ",VR=" << thing.anisotropyVR()
212  << ",FA=" << thing.anisotropyFA()
213  << ",category=";
214  switch( thing.category() )
215  {
216  case DtiTensor::NO_PROBLEM : os << "NO_PROBLEM";break;
217  case DtiTensor::NOT_POSITIVE_MATRIX : os << "NOT_POSITIVE_MATRIX";break;
218  case DtiTensor::CORRECTED_N26 : os << "CORRECTED_N26";break;
219  case DtiTensor::CORRECTED_TC : os << "CORRECTED_TC";break;
220  default : os << "UNKNOWN";break;
221  }
222  os << ",index=" << thing.index();
223  os << "}";
224  return os;
225 }
226 
227 
228 #endif
short _index
Definition: dtitensor.h:117
float & anisotropyVR()
Definition: dtitensor.h:96
const float & anisotropyFA() const
Definition: dtitensor.h:98
short & index()
Definition: dtitensor.h:105
friend std::ostream & operator<<(std::ostream &os, const DtiTensor &thing)
Definition: dtitensor.h:206
float volumeRatio(const DtiTensor &thing)
Definition: dtitensor.h:137
DtiTensor(const DtiTensor &other)
Definition: dtitensor.h:77
std::ostream & operator<<(std::ostream &os, const DtiTensor &thing)
Definition: dtitensor.h:206
const Tensor & base() const
Definition: dtitensor.h:86
DtiTensor()
Definition: dtitensor.h:68
virtual ~DtiTensor()
Definition: dtitensor.h:84
T cube(const T &val)
Definition: mathelem.h:341
float meanDiffusivity() const
Definition: tensor.h:125
Point3df & location()
Definition: dtitensor.h:93
float _anisotropyVR
Definition: dtitensor.h:114
const Point3df & dir() const
Definition: dtitensor.h:89
const Point3df & location() const
Definition: dtitensor.h:92
DtiTensor(const Tensor &other)
Definition: dtitensor.h:75
Point3df _location
Definition: dtitensor.h:113
Point3df _dir
Definition: dtitensor.h:112
int _category
Definition: dtitensor.h:116
Tensor _base
Definition: dtitensor.h:111
float & anisotropyFA()
Definition: dtitensor.h:99
DtiTensor(const AimsVector< float, 6 > &coef)
Definition: dtitensor.h:72
Definition: tensor.h:51
int & category()
Definition: dtitensor.h:102
DtiTensor(const Trieder &trieder, const Point3df &eigenvalue)
Definition: dtitensor.h:69
const short & index() const
Definition: dtitensor.h:104
const AimsVector< float, 6 > & coef() const
Definition: tensor.h:74
const float & anisotropyVR() const
Definition: dtitensor.h:95
Tensor & base()
Definition: dtitensor.h:87
const int & category() const
Definition: dtitensor.h:101
float _anisotropyFA
Definition: dtitensor.h:115
const T & item(int d) const
float fractionalAniso(const DtiTensor &thing)
Definition: dtitensor.h:174
Point3df & dir()
Definition: dtitensor.h:90