diff --git a/KomaMRIBase/src/KomaMRIBase.jl b/KomaMRIBase/src/KomaMRIBase.jl index 739b7e44e..0eca34c48 100644 --- a/KomaMRIBase/src/KomaMRIBase.jl +++ b/KomaMRIBase/src/KomaMRIBase.jl @@ -45,8 +45,8 @@ export brain_phantom2D, brain_phantom3D, pelvis_phantom2D export get_dims # Motion export MotionModel -export SimpleMotion, NoMotion, ArbitraryMotion -export SimpleMotionType +export NoMotion, SimpleMotion, ArbitraryMotion +export SimpleMotionType, SimpleMotionTypes export Translation, Rotation, PeriodicTranslation, PeriodicRotation export get_spin_coords, get_times export LinearInterpolator diff --git a/KomaMRIBase/src/datatypes/phantom/motion/SimpleMotion.jl b/KomaMRIBase/src/datatypes/phantom/motion/SimpleMotion.jl index c2b4eab5e..13db2586b 100644 --- a/KomaMRIBase/src/datatypes/phantom/motion/SimpleMotion.jl +++ b/KomaMRIBase/src/datatypes/phantom/motion/SimpleMotion.jl @@ -1,4 +1,9 @@ -# ------ SimpleMotionType +# ------ SimpleMotionTypes +global SimpleMotionTypes = ["Translation", + "Rotation", + "PeriodicTranslation", + "PeriodicRotation"] + abstract type SimpleMotionType{T<:Real} end """ diff --git a/KomaMRIFiles/src/Phantom/Phantom.jl b/KomaMRIFiles/src/Phantom/Phantom.jl index e5334b880..8ef3bea31 100644 --- a/KomaMRIFiles/src/Phantom/Phantom.jl +++ b/KomaMRIFiles/src/Phantom/Phantom.jl @@ -79,9 +79,9 @@ function import_motion(Ns::Int, motion_group::HDF5.Group, precision::Type) for key in keys(types_group) type_group = types_group[key] type_str = match(r"^\d+_(\w+)", key).captures[1] - type = type_str == "Translation" ? Translation : - type_str == "Rotation" ? Rotation : - nothing + if type_str in SimpleMotionTypes + type = eval(Meta.parse(type_str)) # Use of eval is controlled + end args = [] for key in fieldnames(type) push!(args, read_attribute(type_group, string(key))) @@ -178,10 +178,10 @@ function export_motion(motion_group::HDF5.Group, motion::SimpleMotion) types_group = create_group(motion_group, "types") counter = 1 for type in motion.types - type_group = create_group(types_group, string(counter)*"_"*match(r"^\w+", string(typeof(type))).match) + type_group = create_group(types_group, string(counter)*"_"*match(r"(?<=\.)[^\{\}]+", string(typeof(type))).match) fields = fieldnames(typeof(type)) for field in fields - HDF5.attributes(type_group)[string(field)] = getfield(type, fieldcount) + HDF5.attributes(type_group)[string(field)] = getfield(type, field) end counter += 1 end