17#ifndef __dwi_tractography_seeding_dynamic_h__
18#define __dwi_tractography_seeding_dynamic_h__
46#define DYNAMIC_SEED_INITIAL_TD_SUM 1e-6
51#define DYNAMIC_SEED_INITIAL_PROB 1e-3
56#define DYNAMIC_SEEDING_DAMPING_FACTOR 0.5
64 namespace Tractography
67 namespace ACT {
class GMWMI_finder; }
84 applied_prob (old_prob),
85 track_count_at_last_update (0),
95 old_prob (that.old_prob),
96 applied_prob (that.applied_prob),
97 track_count_at_last_update (that.track_count_at_last_update),
98 seed_count (that.seed_count) {
108 applied_prob (old_prob),
109 track_count_at_last_update (0),
115 double get_TD ()
const {
return TD.load (std::memory_order_relaxed); }
116 void clear_TD () { TD.store (0.0, std::memory_order_relaxed); }
117 double get_diff (
const double mu)
const {
return ((TD.load (std::memory_order_relaxed) * mu) -
FOD); }
119 void mask() { update =
false; }
120 bool can_update()
const {
return update; }
131 double old_TD = TD.load (std::memory_order_relaxed);
132 while (!TD.compare_exchange_weak (old_TD, old_TD +
length, std::memory_order_relaxed));
137 void set_voxel (
const Eigen::Vector3i& i) { voxel = i; }
138 const Eigen::Vector3i& get_voxel()
const {
return voxel; }
140 float get_ratio (
const double mu)
const {
return ((mu * TD.load (std::memory_order_relaxed)) /
FOD); }
143 float get_cumulative_prob (
const uint64_t track_count)
145 while (updating.test_and_set (std::memory_order_acquire));
146 float cumulative_prob = old_prob;
147 if (track_count > track_count_at_last_update) {
148 cumulative_prob = ((track_count_at_last_update * old_prob) + ((track_count - track_count_at_last_update) * applied_prob)) / float(track_count);
149 old_prob = cumulative_prob;
150 track_count_at_last_update = track_count;
152 return cumulative_prob;
155 void update_prob (
const float new_prob,
const bool seed_drawn)
157 applied_prob = new_prob;
160 updating.clear (std::memory_order_release);
164 float get_old_prob()
const {
return old_prob; }
165 float get_prob()
const {
return applied_prob; }
166 size_t get_seed_count()
const {
return seed_count; }
171 Eigen::Vector3i voxel;
172 std::atomic<double> TD;
176 std::atomic_flag updating;
177 float old_prob, applied_prob;
178 size_t track_count_at_last_update;
192 gmwmi_finder (interp_template) { }
194 bool check_seed (Eigen::Vector3f&);
225 bool get_seed (Eigen::Vector3f&, Eigen::Vector3f&)
override;
236#ifdef DYNAMIC_SEED_DEBUGGING
237 const size_t updated_count = ++track_count;
238 if (updated_count == target_trackcount / 2)
239 output_fixel_images();
240 if (updated_count >= target_trackcount)
243 if (++track_count >= target_trackcount)
259 const size_t target_trackcount;
260 std::atomic<size_t> track_count;
263 std::atomic<uint64_t> attempts, seeds;
266#ifdef DYNAMIC_SEED_DEBUGGING
268 void write_seed (
const Eigen::Vector3f&);
270 void output_fixel_images();
275 std::unique_ptr<Dynamic_ACT_additions> act;
277 void perform_fixel_masking();
virtual bool operator()(const FMLS::FOD_lobes &in)
bool operator()(const FMLS::FOD_lobes &) override
bool get_seed(Eigen::Vector3f &, Eigen::Vector3f &) override
Dynamic(const Dynamic &)=delete
Dynamic & operator=(const Dynamic &)=delete
bool get_seed(Eigen::Vector3f &) const override
Dynamic(const std::string &, Image< float > &, const size_t, const DWI::Directions::FastLookupSet &)
class to handle writing tracks to file, with RAM buffer
functions and classes related to image data input/output
#define DYNAMIC_SEED_INITIAL_PROB
PointType::Scalar length(const vector< PointType > &tck)