Skip to content

Commit 2c270c9

Browse files
committed
improvement
1 parent 59891fa commit 2c270c9

File tree

5 files changed

+35
-12
lines changed

5 files changed

+35
-12
lines changed

src/file_utils.cpp

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ bool file_utils::read_config(std::string config_filename, simulation_parameters
280280
}
281281

282282

283-
bool file_utils::read_fieldmap(std::string fieldmap_filename, std::vector<float> &fieldmap, std::vector<uint8_t> &mask, simulation_parameters *param)
283+
bool file_utils::read_phantom(std::string fieldmap_filename, std::vector<float> &fieldmap, std::vector<uint8_t> &mask, simulation_parameters *param)
284284
{
285285
if(std::filesystem::exists(fieldmap_filename) == false)
286286
{
@@ -296,9 +296,9 @@ bool file_utils::read_fieldmap(std::string fieldmap_filename, std::vector<float>
296296
dims = get_size_h5(fieldmap_filename, "fieldmap");
297297
if (product(dims) != fieldmap.size())
298298
{
299-
BOOST_LOG_TRIVIAL(error) << "Error in reading fieldmap: " << fieldmap_filename;
300-
BOOST_LOG_TRIVIAL(error) << "Fieldmap size does not match the expected size: " << product(dims) << " vs " << fieldmap.size() << ". Aborting...!";
301-
return false;
299+
BOOST_LOG_TRIVIAL(warning) << "Hint in reading fieldmap: " << fieldmap_filename;
300+
BOOST_LOG_TRIVIAL(warning) << "Fieldmap size does not match the expected size: " << product(dims) << " vs " << fieldmap.size() << ". resize it...!";
301+
fieldmap.resize(product(dims));
302302
}
303303
read_h5(fieldmap_filename, fieldmap.data(), "fieldmap", "float");
304304
}
@@ -309,13 +309,19 @@ bool file_utils::read_fieldmap(std::string fieldmap_filename, std::vector<float>
309309
dims = get_size_h5(fieldmap_filename, "mask");
310310
if (product(dims) != mask.size())
311311
{
312-
BOOST_LOG_TRIVIAL(error) << "Error in reading mask: " << fieldmap_filename;
313-
BOOST_LOG_TRIVIAL(error) << "Mask size does not match the expected size: " << product(dims) << " vs " << mask.size() << ". Aborting...!";
314-
return false;
312+
BOOST_LOG_TRIVIAL(warning) << "Hint in reading mask: " << fieldmap_filename;
313+
BOOST_LOG_TRIVIAL(warning) << "Mask size does not match the expected size: " << product(dims) << " vs " << mask.size() << ". Aborting...!";
314+
mask.resize(product(dims));
315315
}
316316
read_h5(fieldmap_filename, mask.data(), "mask", "uint8_t");
317317
}
318318

319+
if (param->mask_exist && param->fieldmap_exist && mask.size() != fieldmap.size())
320+
{
321+
BOOST_LOG_TRIVIAL(error) << "Fieldmap and mask sizes do not match: " << mask.size() << " vs " << fieldmap.size();
322+
return false;
323+
}
324+
319325
std::vector<float> fov(3, 0);
320326
file_utils::read_h5(fieldmap_filename, fov.data(), "fov", "float");
321327
BOOST_LOG_TRIVIAL(info) << "Size = " << dims[0] << " x " << dims[1] << " x " << dims[2] << std::endl;
@@ -330,6 +336,7 @@ bool file_utils::read_fieldmap(std::string fieldmap_filename, std::vector<float>
330336
return true;
331337
}
332338

339+
333340
std::vector<size_t> file_utils::get_size_h5(std::string input_filename, std::string dataset_name)
334341
{
335342
std::vector<size_t> dims(1,0);
@@ -384,7 +391,11 @@ bool file_utils::read_h5(std::string input_filename, void *data, std::string dat
384391

385392
bool file_utils::save_h5(std::string output_filename, void *data, std::vector<size_t> dims, std::string dataset_name, std::string data_type)
386393
{
387-
BOOST_LOG_TRIVIAL(info) << "Saving " << dataset_name << " to: " << std::filesystem::absolute(output_filename);
394+
std::ostringstream oss;
395+
for (const auto& elem : dims)
396+
oss << elem << " ";
397+
398+
BOOST_LOG_TRIVIAL(info) << "Saving " << dataset_name << " with size = [" << oss.str() << "] to: " << std::filesystem::absolute(output_filename);
388399
std::filesystem::path parent_path = std::filesystem::absolute(output_filename).parent_path();
389400
if (std::filesystem::is_directory(parent_path) == false)
390401
{

src/file_utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ bool read_config(std::string config_filename, simulation_parameters *param, std:
3939
//---------------------------------------------------------------------------------------------
4040
//
4141
//---------------------------------------------------------------------------------------------
42-
bool read_fieldmap(std::string fieldmap_filename, std::vector<float> &fieldmap, std::vector<uint8_t> &mask, simulation_parameters *param);
42+
bool read_phantom(std::string fieldmap_filename, std::vector<float> &fieldmap, std::vector<uint8_t> &mask, simulation_parameters *param);
4343

4444
//---------------------------------------------------------------------------------------------
4545
//

src/simulation_parameters.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,11 @@ typedef struct simulation_parameters
189189
{
190190
BOOST_LOG_TRIVIAL(warning) << "Off-resonance map is not provided. Simulation will be performed with a perfect homogeneous field.";
191191
}
192+
if(n_fov_scale == 0)
193+
{
194+
BOOST_LOG_TRIVIAL(error) << "No FoV scale is provided";
195+
return false;
196+
}
192197
return true;
193198
}
194199
} simulation_parameters;

src/spinwalk.cu

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,15 @@ bool run(simulation_parameters param, std::map<std::string, std::vector<std::str
9595
{
9696
// ========== load files (field-maps, xyz0, m0) ==========
9797
std::cout << "Loading phantom: " << std::filesystem::path(filenames.at("phantom")[fieldmap_no]).filename().string() << "\n";
98-
if(file_utils::read_fieldmap(filenames.at("phantom")[fieldmap_no], fieldmap, mask, &param) == false)
98+
if(file_utils::read_phantom(filenames.at("phantom")[fieldmap_no], fieldmap, mask, &param) == false)
9999
return false;
100+
param.matrix_length = mask.size(); // update the matrix length based on the mask size from the recent read
101+
#ifdef __CUDACC__
102+
if(d_pMask.size() != mask.size())
103+
d_pMask.resize(mask.size());
104+
if(d_pFieldMap.size() != fieldmap.size() && param.fieldmap_exist)
105+
d_pFieldMap.resize(fieldmap.size());
106+
#endif
100107
// convert fieldmap from T to degree per timestep
101108
float Tesla2deg = param.B0 * param.timestep_us * 1e-6 * GAMMA * RAD2DEG;
102109
if(param.fieldmap_exist)
@@ -263,7 +270,7 @@ bool dump_settings(simulation_parameters param, std::map<std::string, std::vecto
263270
for (int i = 0; i< it->second.size(); i++)
264271
ss << it->first << "[" << i << "] = " << it->second.at(i) << '\n';
265272

266-
ss << "\nSample length scale = [";
273+
ss << "\nFoV scale = [";
267274
for (int32_t i = 0; i < param.n_fov_scale; i++)
268275
ss << fov_scale[i] << ", ";
269276
ss << "]\n";

src/version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
#define SPINWALK_VERSION_MAJOR 1
88
#define SPINWALK_VERSION_MINOR 13
9-
#define SPINWALK_VERSION_PATCH 3
9+
#define SPINWALK_VERSION_PATCH 4
1010

1111
//---------------------------------------------------------------------------------------------
1212
//

0 commit comments

Comments
 (0)