Developer documentation
Version 3.0.3-105-gd3941f44
basic.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_seeding_basic_h__
18#define __dwi_tractography_seeding_basic_h__
19
22
23
24// By default, the rejection sampler will perform its sampling based on image intensity values,
25// and then randomly select a position within that voxel
26// Use this flag to instead perform rejection sampling on the trilinear-interpolated value
27// at each trial seed point
28//#define REJECTION_SAMPLING_USE_INTERPOLATION
29
30
31
32namespace MR
33{
34 namespace DWI
35 {
36 namespace Tractography
37 {
38 namespace Seeding
39 {
40
41
42 class Sphere : public Base
43 { MEMALIGN(Sphere)
44
45 public:
46 Sphere (const std::string& in) :
48 auto F = parse_floats (in);
49 if (F.size() != 4)
50 throw Exception ("Could not parse seed \"" + in + "\" as a spherical seed point; needs to be 4 comma-separated values (XYZ position, then radius)");
51 pos = { float(F[0]), float(F[1]), float(F[2]) };
52 rad = F[3];
53 volume = 4.0*Math::pi*Math::pow3(rad)/3.0;
54 }
55
56 virtual bool get_seed (Eigen::Vector3f& p) const override;
57
58 private:
59 Eigen::Vector3f pos;
60 float rad;
61
62 };
63
64
65 class SeedMask : public Base
66 { MEMALIGN(SeedMask)
67
68 public:
69 SeedMask (const std::string& in) :
70 Base (in, "random seeding mask", MAX_TRACKING_SEED_ATTEMPTS_RANDOM),
71 mask (in) {
72 volume = get_count (mask) * mask.spacing(0) * mask.spacing(1) * mask.spacing(2);
73 }
74
75 virtual bool get_seed (Eigen::Vector3f& p) const override;
76
77 private:
78 Mask mask;
79
80 };
81
82
83
84 class Random_per_voxel : public Base
85 { MEMALIGN(Random_per_voxel)
86
87 public:
88 Random_per_voxel (const std::string& in, const size_t num_per_voxel) :
89 Base (in, "random per voxel", MAX_TRACKING_SEED_ATTEMPTS_FIXED),
90 mask (in),
91 num (num_per_voxel),
92 inc (0),
93 expired (false) {
94 count = get_count (mask) * num_per_voxel;
95 mask.index(0) = 0; mask.index(1) = 0; mask.index(2) = -1;
96 }
97
98 virtual bool get_seed (Eigen::Vector3f& p) const override;
99 virtual ~Random_per_voxel() { }
100
101 private:
102 mutable Mask mask;
103 const size_t num;
104
105 mutable uint32_t inc;
106 mutable bool expired;
107 };
108
109
110
111 class Grid_per_voxel : public Base
112 { MEMALIGN(Grid_per_voxel)
113
114 public:
115 Grid_per_voxel (const std::string& in, const size_t os_factor) :
116 Base (in, "grid per voxel", MAX_TRACKING_SEED_ATTEMPTS_FIXED),
117 mask (in),
118 os (os_factor),
119 pos (os, os, os),
120 offset (-0.5 + (1.0 / (2*os))),
121 step (1.0 / os),
122 expired (false) {
123 count = get_count (mask) * Math::pow3 (os_factor);
124 }
125
126 virtual ~Grid_per_voxel() { }
127 virtual bool get_seed (Eigen::Vector3f& p) const override;
128
129
130 private:
131 mutable Mask mask;
132 const int os;
133 mutable Eigen::Vector3i pos;
134 const float offset, step;
135 mutable bool expired;
136
137 };
138
139
140
141 class Rejection : public Base
143 public:
144 using transform_type = Eigen::Transform<float, 3, Eigen::AffineCompact>;
145 Rejection (const std::string&);
146
147
148 virtual bool get_seed (Eigen::Vector3f& p) const override;
149
150 private:
151#ifdef REJECTION_SAMPLING_USE_INTERPOLATION
153#else
154 Image<float> image;
155 transform_type voxel2scanner;
156#endif
157 float max;
158
159 };
160
161
162
163
164
165
166 }
167 }
168 }
169}
170
171#endif
172
default_type spacing(size_t axis) const
Definition: image.h:67
constexpr T pow3(const T &v)
Definition: math.h:54
constexpr double pi
Definition: math.h:40
uint32_t get_count(ImageType &data)
Definition: base.h:67
Definition: base.h:24
vector< default_type > parse_floats(const std::string &spec)
Eigen::Transform< default_type, 3, Eigen::AffineCompact > transform_type
the type for the affine transform of an image:
Definition: types.h:234
#define MAX_TRACKING_SEED_ATTEMPTS_FIXED
Definition: base.h:49
#define MAX_TRACKING_SEED_ATTEMPTS_RANDOM
Definition: base.h:35
#define MEMALIGN(...)
Definition: types.h:185