Developer documentation
Version 3.0.3-105-gd3941f44
tissues.h
Go to the documentation of this file.
1/* Copyright (c) 2008-2022 the MRtrix3 contributors.
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 *
7 * Covered Software is provided under this License on an "as is"
8 * basis, without warranty of any kind, either expressed, implied, or
9 * statutory, including, without limitation, warranties that the
10 * Covered Software is free of defects, merchantable, fit for a
11 * particular purpose or non-infringing.
12 * See the Mozilla Public License v. 2.0 for more details.
13 *
14 * For more details, see http://www.mrtrix.org/.
15 */
16
17#ifndef __dwi_tractography_act_tissues_h__
18#define __dwi_tractography_act_tissues_h__
19
20
21// If the sum of tissue probabilities is below this threshold, the image is being exited, so a boolean flag is thrown
22// The values will however still be accessible
23#define TISSUE_SUM_THRESHOLD 0.5
24
25
26
27namespace MR
28{
29 namespace DWI
30 {
31 namespace Tractography
32 {
33 namespace ACT
34 {
35
36
37 class Tissues { MEMALIGN(Tissues)
38
39 public:
40 Tissues () : cgm (0.0), sgm (0.0), wm (0.0), csf (0.0), path (0.0), is_valid (false) { }
41
42 Tissues (const float cg, const float sg, const float w, const float c, const float p) :
43 cgm (0.0),
44 sgm (0.0),
45 wm (0.0),
46 csf (0.0),
47 path (0.0)
48 {
49 set (cg, sg, w, c, p);
50 }
51
52 template <class ImageType>
53 Tissues (ImageType& data) :
54 cgm (0.0),
55 sgm (0.0),
56 wm (0.0),
57 csf (0.0),
58 path (0.0),
59 is_valid (false)
60 {
61 set<ImageType> (data);
62 }
63
64
65 Tissues (const Tissues& that) :
66 cgm (that.cgm),
67 sgm (that.sgm),
68 wm (that.wm),
69 csf (that.csf),
70 path (that.path),
71 is_valid (that.is_valid) { }
72
73 Tissues (Tissues& that) :
74 cgm (that.cgm),
75 sgm (that.sgm),
76 wm (that.wm),
77 csf (that.csf),
78 path (that.path),
79 is_valid (that.is_valid) { }
80
81 bool set (const float cg, const float sg, const float w, const float c, const float p) {
82 if (std::isnan (cg) || std::isnan (sg) || std::isnan (w) || std::isnan (c) || std::isnan (p)) {
83 cgm = sgm = wm = csf = path = 0.0;
84 return ((is_valid = false));
85 }
86 cgm = (cg < 0.0) ? 0.0 : ((cg > 1.0) ? 1.0 : cg);
87 sgm = (sg < 0.0) ? 0.0 : ((sg > 1.0) ? 1.0 : sg);
88 wm = (w < 0.0) ? 0.0 : ((w > 1.0) ? 1.0 : w );
89 csf = (c < 0.0) ? 0.0 : ((c > 1.0) ? 1.0 : c );
90 path = (p < 0.0) ? 0.0 : ((p > 1.0) ? 1.0 : p );
91 return ((is_valid = ((cgm + sgm + wm + csf + path) >= TISSUE_SUM_THRESHOLD)));
92 }
93
94 template <class ImageType>
95 bool set (ImageType& data)
96 {
97 data.index(3) = 0; const float cg = data.value();
98 data.index(3) = 1; const float sg = data.value();
99 data.index(3) = 2; const float w = data.value();
100 data.index(3) = 3; const float c = data.value();
101 data.index(3) = 4; const float p = data.value();
102 return set (cg, sg, w, c, p);
103 }
104
105 void reset() {
106 cgm = sgm = wm = csf = path = 0.0;
107 is_valid = false;
108 }
109
110 bool valid() const { return is_valid; }
111
112 float get_cgm() const { return cgm; }
113 float get_sgm() const { return sgm; }
114 float get_wm () const { return wm; }
115 float get_csf() const { return csf; }
116 float get_path() const { return path; }
117
118 float get_gm () const { return (cgm + sgm); }
119
120 bool is_cgm() const { return ((cgm >= sgm) && (cgm >= wm ) && (cgm > csf) && (cgm > path)); }
121 bool is_sgm() const { return ((sgm > cgm) && (sgm >= wm ) && (sgm > csf) && (sgm > path)); }
122 bool is_wm () const { return ((wm > cgm) && (wm > sgm) && (wm > csf) && (wm > path)); }
123 bool is_csf() const { return ((csf >= cgm) && (csf >= sgm) && (csf >= wm ) && (csf >= path)); }
124 bool is_path() const { return ((path >= cgm) && (path >= sgm) && (path >= wm ) && (path > csf )); }
125
126 bool is_gm() const { return ((get_gm() >= wm) && (get_gm() > csf) && (get_gm() > path)); }
127
128 private:
129 float cgm, sgm, wm, csf, path;
130 bool is_valid;
131
132 };
133
134
135 inline std::ostream& operator<< (std::ostream& stream, const Tissues& t)
136 {
137 stream << "[ " << t.get_cgm() << " " << t.get_sgm() << " " << t.get_wm() << " " << t.get_csf() << " " << t.get_path() <<" ]";
138 return (stream);
139 }
140
141
142 }
143 }
144 }
145}
146
147#endif
148
std::ostream & operator<<(std::ostream &stream, const Tissues &t)
Definition: tissues.h:135
Definition: base.h:24
#define TISSUE_SUM_THRESHOLD
Definition: tissues.h:23