Skip to content

Commit 499f592

Browse files
committed
tckglobal: Fix operation
Changes in 2be257c made as part of #3011 resulted in there being two separate attempts to construct an Image class from the same input header. Fixes #3171.
1 parent 39ef6e6 commit 499f592

3 files changed

Lines changed: 31 additions & 32 deletions

File tree

cmd/tckglobal.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -303,15 +303,13 @@ void run ()
303303
if (opt.size())
304304
stats.open_stream(opt[0][0]);
305305

306-
auto dwi = header_in.get_image<float>().with_direct_io(3);
307-
ParticleGrid pgrid (dwi);
308-
306+
ParticleGrid pgrid (header_in);
309307
ExternalEnergyComputer* Eext = new ExternalEnergyComputer(stats, header_in, properties);
310308
InternalEnergyComputer* Eint = new InternalEnergyComputer(stats, pgrid);
311309
Eint->setConnPot(cpot);
312310
EnergySumComputer* Esum = new EnergySumComputer(stats, Eint, properties.lam_int, Eext, properties.lam_ext / ( wmscale2 * properties.weight*properties.weight));
313311

314-
MHSampler mhs (dwi, properties, stats, pgrid, Esum, mask); // All EnergyComputers are recursively destroyed upon destruction of mhs, except for the shared data.
312+
MHSampler mhs (header_in, properties, stats, pgrid, Esum, mask); // All EnergyComputers are recursively destroyed upon destruction of mhs, except for the shared data.
315313

316314

317315
INFO("Start MH sampler");
@@ -345,7 +343,7 @@ void run ()
345343

346344

347345
// Save fiso, tod and eext
348-
Header header_out (dwi);
346+
Header header_out (header_in);
349347
header_out.datatype() = DataType::Float32;
350348

351349
opt = get_options("fod");

src/dwi/tractography/GT/externalenergy.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ namespace MR {
2828
namespace Tractography {
2929
namespace GT {
3030

31-
ExternalEnergyComputer::ExternalEnergyComputer(Stats& stat, Header& dwiheader, const Properties& props)
31+
ExternalEnergyComputer::ExternalEnergyComputer(Stats& stat, Header &dwiheader, const Properties& props)
3232
: EnergyComputer(stat),
3333
dwi(dwiheader.get_image<float>().with_direct_io(3)),
3434
T(Transform(dwiheader).scanner2voxel),

src/dwi/tractography/GT/mhsampler.h

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#ifndef __gt_mhsampler_h__
1818
#define __gt_mhsampler_h__
1919

20+
#include "header.h"
2021
#include "image.h"
2122
#include "transform.h"
2223

@@ -40,77 +41,77 @@ namespace MR {
4041
class MHSampler
4142
{ MEMALIGN(MHSampler)
4243
public:
43-
MHSampler(const Image<float>& dwi, Properties &p, Stats &s, ParticleGrid &pgrid,
44+
MHSampler(const Header& dwiheader, Properties &p, Stats &s, ParticleGrid &pgrid,
4445
EnergyComputer* e, Image<bool>& m)
45-
: props(p), stats(s), pGrid(pgrid), E(e), T(dwi),
46-
dims{size_t(dwi.size(0)), size_t(dwi.size(1)), size_t(dwi.size(2))},
47-
mask(m), lock(make_shared<SpatialLock<float>>(5*Particle::L)),
46+
: props(p), stats(s), pGrid(pgrid), E(e), T(dwiheader),
47+
dims{size_t(dwiheader.size(0)), size_t(dwiheader.size(1)), size_t(dwiheader.size(2))},
48+
mask(m), lock(make_shared<SpatialLock<float>>(5*Particle::L)),
4849
sigpos(Particle::L / 8.), sigdir(0.2)
4950
{
5051
DEBUG("Initialise Metropolis Hastings sampler.");
5152
}
52-
53+
5354
MHSampler(const MHSampler& other)
54-
: props(other.props), stats(other.stats), pGrid(other.pGrid), E(other.E->clone()),
55+
: props(other.props), stats(other.stats), pGrid(other.pGrid), E(other.E->clone()),
5556
T(other.T), dims(other.dims), mask(other.mask), lock(other.lock), rng_uniform(), rng_normal(), sigpos(other.sigpos), sigdir(other.sigdir)
5657
{
5758
DEBUG("Copy Metropolis Hastings sampler.");
5859
}
59-
60+
6061
~MHSampler() { delete E; }
61-
62+
6263
void execute();
63-
64+
6465
void next();
65-
66+
6667
void birth();
6768
void death();
6869
void randshift();
6970
void optshift();
7071
void connect();
71-
72-
72+
73+
7374
protected:
74-
75+
7576
Properties& props;
7677
Stats& stats;
7778
ParticleGrid& pGrid;
7879
EnergyComputer* E; // Polymorphic copy requires call to EnergyComputer::clone(), hence references or smart pointers won't do.
79-
80+
8081
Transform T;
8182
vector<size_t> dims;
8283
Image<bool> mask;
83-
84+
8485
std::shared_ptr< SpatialLock<float> > lock;
8586
Math::RNG::Uniform<float> rng_uniform;
8687
Math::RNG::Normal<float> rng_normal;
8788
float sigpos, sigdir;
88-
89-
89+
90+
9091
Point_t getRandPosInMask();
91-
92+
9293
bool inMask(const Point_t p);
93-
94+
9495
Point_t getRandDir();
95-
96+
9697
void moveRandom(const Particle* par, Point_t& pos, Point_t& dir);
97-
98+
9899
bool moveOptimal(const Particle* par, Point_t& pos, Point_t& dir) const;
99-
100+
100101
inline double calcShiftProb(const Particle* par, const Point_t& pos, const Point_t& dir) const
101102
{
102103
Point_t Dpos = par->getPosition() - pos;
103104
Point_t Ddir = par->getDirection() - dir;
104105
return gaussian_pdf(Dpos, sigpos) * gaussian_pdf(Ddir, sigdir);
105106
}
106-
107+
107108
inline double gaussian_pdf(const Point_t& x, double sigma) const {
108109
return std::exp( -x.squaredNorm() / (2*sigma) ) / std::sqrt( 2*Math::pi * sigma*sigma);
109110
}
110-
111-
111+
112+
112113
};
113-
114+
114115

115116
}
116117
}

0 commit comments

Comments
 (0)