@@ -280,7 +280,7 @@ bool file_utils::read_config(std::string config_filename, simulation_parameters
280
280
}
281
281
282
282
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)
284
284
{
285
285
if (std::filesystem::exists (fieldmap_filename) == false )
286
286
{
@@ -296,9 +296,9 @@ bool file_utils::read_fieldmap(std::string fieldmap_filename, std::vector<float>
296
296
dims = get_size_h5 (fieldmap_filename, " fieldmap" );
297
297
if (product (dims) != fieldmap.size ())
298
298
{
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)) ;
302
302
}
303
303
read_h5 (fieldmap_filename, fieldmap.data (), " fieldmap" , " float" );
304
304
}
@@ -309,13 +309,19 @@ bool file_utils::read_fieldmap(std::string fieldmap_filename, std::vector<float>
309
309
dims = get_size_h5 (fieldmap_filename, " mask" );
310
310
if (product (dims) != mask.size ())
311
311
{
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)) ;
315
315
}
316
316
read_h5 (fieldmap_filename, mask.data (), " mask" , " uint8_t" );
317
317
}
318
318
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
+
319
325
std::vector<float > fov (3 , 0 );
320
326
file_utils::read_h5 (fieldmap_filename, fov.data (), " fov" , " float" );
321
327
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>
330
336
return true ;
331
337
}
332
338
339
+
333
340
std::vector<size_t > file_utils::get_size_h5 (std::string input_filename, std::string dataset_name)
334
341
{
335
342
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
384
391
385
392
bool file_utils::save_h5 (std::string output_filename, void *data, std::vector<size_t > dims, std::string dataset_name, std::string data_type)
386
393
{
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);
388
399
std::filesystem::path parent_path = std::filesystem::absolute (output_filename).parent_path ();
389
400
if (std::filesystem::is_directory (parent_path) == false )
390
401
{
0 commit comments