Skip to content

Commit ba5681e

Browse files
committed
minor
1 parent 6346290 commit ba5681e

File tree

9 files changed

+32
-25
lines changed

9 files changed

+32
-25
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ You can either use the supplied Dockerfile for a consistent build that includes
3737
We suggest utilizing the provided Dockerfile, which automates the installation of all dependencies, as well as the cloning and building of the program. Download the [Dockerfile](./Dockerfile) to your current directory and then execute the following commands:
3838

3939
```
40-
docker build -t spinwalk .
40+
docker build --no-cache -t spinwalk .
4141
docker run --gpus all --rm -it --runtime=nvidia spinwalk bash
4242
```
4343
### CMake

src/file_utils.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,13 @@ bool file_utils::read_config(std::string config_filename, simulation_parameters
3838
std::string cf_name = std::filesystem::path(config_filename).filename().string();
3939
BOOST_LOG_TRIVIAL(info) << "Reading config: " << config_filename;
4040
boost::property_tree::ptree pt;
41-
boost::property_tree::ini_parser::read_ini(config_filename, pt);
41+
42+
try{
43+
boost::property_tree::ini_parser::read_ini(config_filename, pt);
44+
}catch (std::exception& e) {
45+
std::cout << ERR_MSG << e.what() << "\n";
46+
return false;
47+
}
4248

4349
if(pt.get_child_optional("PARENT.PARENT_CONFIG"))
4450
{

src/shapes/cylinder.cu

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ cylinder::cylinder()
2626
m_orientation = 0;
2727
}
2828

29-
cylinder::cylinder(float fov_um, size_t resolution, float dChi, float Y, float radius_um, float BVF, float orientation, bool is_seed_fixed, std::string filename)
30-
: shape(fov_um, resolution, dChi, Y, BVF, is_seed_fixed, filename)
29+
cylinder::cylinder(float fov_um, size_t resolution, float dChi, float Y, float radius_um, float BVF, float orientation, int32_t seed, std::string filename)
30+
: shape(fov_um, resolution, dChi, Y, BVF, seed, filename)
3131
{
3232
set_cylinder_parameters(radius_um, orientation);
3333
}
@@ -60,7 +60,7 @@ void cylinder::generate_shapes()
6060
float cyl_pnt[3], cyl_rad ;
6161
float curr_BVF = 0;
6262
// srandom engine
63-
std::mt19937 gen(m_random_seed); // Mersenne Twister generator
63+
std::mt19937 gen(m_seed); // Mersenne Twister generator
6464
std::uniform_real_distribution<float> dist(0.f, 1.f);
6565

6666
float distance, vol_cyl = 0, vol_cyl_total = 0, vol_tol = m_fov*m_fov*m_fov;

src/shapes/cylinder.cuh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class cylinder : public shape
1717
{
1818
public:
1919
cylinder();
20-
cylinder(float fov_um, size_t resolution, float dChi, float Y, float radius_um = 50, float BVF = 10., float orientation = -1.0f, bool is_seed_fixed=false, std::string filename = "shape.h5");
20+
cylinder(float fov_um, size_t resolution, float dChi, float Y, float radius_um = 50, float BVF = 10., float orientation = -1.0f, int32_t seed=-1, std::string filename = "shape.h5");
2121
~cylinder();
2222

2323
virtual bool run();

src/shapes/shape_base.cu

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,19 @@ shape::shape()
1717
{
1818
m_fov = 0;
1919
m_resolution = 0;
20-
m_random_seed = std::random_device{}();
20+
m_seed = std::random_device{}();
2121
set_blood_parameters(0.273e-6 * 0.4, 0, 10.0);
2222
set_filename();
2323
}
2424

25-
shape::shape(float fov_um, size_t resolution, float dChi, float Y, float BVF, bool is_seed_fixed, std::string filename)
25+
shape::shape(float fov_um, size_t resolution, float dChi, float Y, float BVF, int32_t seed, std::string filename)
2626
:shape()
2727
{
2828
set_space(fov_um, resolution);
2929
set_blood_parameters(dChi, Y, BVF);
3030
set_filename(filename);
31-
if(is_seed_fixed)
32-
m_random_seed = 0;
31+
if(seed >= 0)
32+
m_seed = seed;
3333
}
3434

3535
shape::~shape()
@@ -135,5 +135,5 @@ void shape::print_info()
135135
std::cout << " Resolution: " << m_resolution << "\n";
136136
std::cout << " Blood parameters: dChi=" << m_dChi << ", Y=" << m_Y << "\n";
137137
std::cout << " Filename: " << m_filename << "\n";
138-
std::cout << " Seed: " << m_random_seed << "\n";
138+
std::cout << " Seed: " << m_seed << "\n";
139139
}

src/shapes/shape_base.cuh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class shape
1717
{
1818
public:
1919
shape();
20-
shape(float fov_um, size_t resolution, float dChi, float Y, float BVF, bool is_seed_fixed, std::string filename);
20+
shape(float fov_um, size_t resolution, float dChi, float Y, float BVF, int32_t seed, std::string filename);
2121
~shape();
2222
void set_space(float fov_um, size_t resolution);
2323
void set_blood_parameters(float dChi, float Y, float BVF = 10.0);
@@ -39,7 +39,7 @@ class shape
3939
std::string m_filename;
4040
float B0[3] = {0.f, 0.f, 1.f};
4141
bool m_calc_fieldmap;
42-
size_t m_random_seed;
42+
size_t m_seed;
4343

4444
private:
4545
};

src/shapes/sphere.cu

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ sphere::sphere()
2525
m_radius = 0;
2626
}
2727

28-
sphere::sphere(float fov_um, size_t resolution, float dChi, float Y, float radius_um, float BVF, bool is_seed_fixed, std::string filename)
29-
: shape(fov_um, resolution, dChi, Y, BVF, is_seed_fixed, filename)
28+
sphere::sphere(float fov_um, size_t resolution, float dChi, float Y, float radius_um, float BVF, int32_t seed, std::string filename)
29+
: shape(fov_um, resolution, dChi, Y, BVF, seed, filename)
3030
{
3131
set_sphere_parameters(radius_um);
3232
}
@@ -55,7 +55,7 @@ void sphere::generate_shapes()
5555
float sph_pnt[3], radius ;
5656

5757
// srandom engine
58-
std::mt19937 gen(m_random_seed); // Mersenne Twister generator
58+
std::mt19937 gen(m_seed); // Mersenne Twister generator
5959
std::uniform_real_distribution<float> dist(0.f, 1.f);
6060

6161
float distance, vol_sph = 0, vol_tol = m_fov*m_fov*m_fov;

src/shapes/sphere.cuh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class sphere : public shape
1717
{
1818
public:
1919
sphere();
20-
sphere(float fov_um, size_t resolution, float dChi, float Y, float radius_um = 50, float BVF = 10.0, bool is_seed_fixed=false, std::string filename = "shape.h5");
20+
sphere(float fov_um, size_t resolution, float dChi, float Y, float radius_um = 50, float BVF = 10.0, int32_t seed = -1, std::string filename = "shape.h5");
2121
~sphere();
2222

2323
virtual bool run();

src/spinwalk.cu

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ bool run(simulation_parameters param, std::map<std::string, std::vector<std::str
9494
for (int16_t fieldmap_no=0; fieldmap_no<param.n_fieldmaps; fieldmap_no++)
9595
{
9696
// ========== load files (field-maps, xyz0, m0) ==========
97+
std::cout << "Loading phantom: " << std::filesystem::path(filenames.at("phantom")[fieldmap_no]).filename().string() << "\n";
9798
if(file_utils::read_fieldmap(filenames.at("phantom")[fieldmap_no], fieldmap, mask, &param) == false)
9899
return false;
99100
// convert fieldmap from T to degree per timestep
@@ -224,7 +225,7 @@ bool run(simulation_parameters param, std::map<std::string, std::vector<std::str
224225
checkCudaErrors(cudaEventElapsedTime(&elapsedTime, start, end));
225226
std::cout << "Simulation over " << device_count << " GPU(s) took " << std::fixed << std::setprecision(2) << elapsedTime/1000. << " second(s)" << '\n';
226227
// ========== save results ==========
227-
std::cout << "Saving the results to disk" << "\n";
228+
std::cout << "Saving the results to disk." << "\n";
228229
std::string f = filenames.at("output")[fieldmap_no];
229230
if (std::filesystem::exists(f))
230231
std::filesystem::remove(f);
@@ -274,7 +275,7 @@ int main(int argc, char * argv[])
274275
bool bStatus = true;
275276
std::string phantom_output;
276277
float phantom_radius, phantom_fov, phantom_dchi, phantom_oxy_level, phantom_orientation, phantom_BVF;
277-
int32_t phantom_resolution;
278+
int32_t phantom_resolution, phantom_seed;
278279
std::vector<std::string> config_files;
279280
print_logo();
280281
// ========== parse command line arguments ==========
@@ -287,15 +288,15 @@ int main(int argc, char * argv[])
287288
("no_gpu,g", "only run on CPU(s) (default: GPU)")
288289
#endif
289290
("cylinder,C", "generate phantom filled with cylinders")
290-
("sphere,s", "generate phantom filled with spheres")
291+
("sphere,S", "generate phantom filled with spheres")
291292
("orientation,o", po::value<float>(&phantom_orientation)->default_value(90.0), "orientation of the cylinders in degree with respect to B0")
292293
("radius,r", po::value<float>(&phantom_radius)->default_value(50), "radius of the cylinders/spheres in um (negative value = random radius)")
293-
("reproducible,R", "set fixed seed for random number generator (for reproducibility)")
294+
("seed,s", po::value<int32_t>(&phantom_seed)->default_value(-1), "seed for random number generator in phantom creator (negative value = random seed)")
294295
("BVF,b", po::value<float>(&phantom_BVF)->default_value(10.0), "fraction of shapes to entire volume <0.0 100.0> (i.e. blood volume fraction)")
295296
("fov,v", po::value<float>(&phantom_fov)->default_value(1000.0), "voxel field of view in um (isotropic)")
296297
("resolution,z", po::value<int32_t>(&phantom_resolution)->default_value(500), "base resolution")
297298
("dchi,d", po::value<float>(&phantom_dchi)->default_value(0.11e-6), "susceptibility difference between fully deoxygenated blood (inside cylinders/spheres) and tissue (outside cylinders/spheres) (default: 0.11e-6 in cgs units)")
298-
("oxy_level,Y", po::value<float>(&phantom_oxy_level)->default_value(0.75), "blood oxygenetation level <0.0 1.0> (negative value = exclude off-resonance effect and only generate the mask)")
299+
("oxy_level,y", po::value<float>(&phantom_oxy_level)->default_value(0.75), "blood oxygenetation level <0.0 1.0> (negative value = exclude off-resonance effect and only generate the mask)")
299300
("output_file,f", po::value<std::string>(&phantom_output)->default_value("./phantom.h5"), "path to save phantom (h5 format)");
300301

301302
po::variables_map vm;
@@ -326,12 +327,12 @@ int main(int argc, char * argv[])
326327
// ========== generate phantom ==========
327328
if (vm.count("cylinder"))
328329
{
329-
cylinder cyl(phantom_fov, phantom_resolution, phantom_dchi, phantom_oxy_level, phantom_radius, phantom_BVF, phantom_orientation, vm.count("reproducible")>0, phantom_output);
330+
cylinder cyl(phantom_fov, phantom_resolution, phantom_dchi, phantom_oxy_level, phantom_radius, phantom_BVF, phantom_orientation, phantom_seed, phantom_output);
330331
cyl.run();
331332
}
332333
if (vm.count("sphere"))
333334
{
334-
sphere sph(phantom_fov, phantom_resolution, phantom_dchi, phantom_oxy_level, phantom_radius, phantom_BVF, vm.count("reproducible")>0, phantom_output);
335+
sphere sph(phantom_fov, phantom_resolution, phantom_dchi, phantom_oxy_level, phantom_radius, phantom_BVF, phantom_seed, phantom_output);
335336
sph.run();
336337
}
337338

@@ -343,7 +344,7 @@ int main(int argc, char * argv[])
343344
auto start = std::chrono::steady_clock::now();
344345
for(const auto& cfile : config_files)
345346
{
346-
std::cout << "<" << std::filesystem::path(cfile).filename().string() << ">\n";
347+
std::cout << "<" << std::filesystem::path(cfile).filename().string() << ">\n";
347348
std::map<std::string, std::vector<std::string> > filenames = {{"phantom", std::vector<std::string>()}, // input: map of off-resonance in Tesla
348349
{"xyz0", std::vector<std::string>()}, // input: spins starting spatial positions in meters
349350
{"m0", std::vector<std::string>()}, // input: spins initial magnetization

0 commit comments

Comments
 (0)