Skip to content

Commit 230fbad

Browse files
Mxyank24cncastillo
andauthored
fix: optimize Rotate displacement! matrix operations (#604) (#787)
* fix: optimize Rotate displacement! matrix operations (#604) * Bump KomaMRIBase to 0.11.2 --------- Co-authored-by: Carlos Castillo Passi <cacp@stanford.edu>
1 parent fa76b7b commit 230fbad

2 files changed

Lines changed: 28 additions & 24 deletions

File tree

KomaMRIBase/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "KomaMRIBase"
22
uuid = "d0bc0b20-b151-4d03-b2a4-6ca51751cb9c"
33

4-
version = "0.11.1"
4+
version = "0.11.2"
55
authors = ["Carlos Castillo Passi <cncastillo@uc.cl>"]
66

77
[workspace]

KomaMRIBase/src/motion/actions/simpleactions/Rotate.jl

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -79,39 +79,43 @@ get_center(center::CenterOfMass, x, y, z) = (sum(x) / length(x), sum(y) / length
7979
get_center(center::NTuple, x, y, z) = center
8080

8181
function displacement_x!(ux, action::Rotate, x, y, z, t)
82-
# Not using sind and cosd functions until bug with oneAPI is solved:
83-
# https://github.com/JuliaGPU/oneAPI.jl/issues/65
84-
α = t .* (action.yaw*π/180)
85-
β = t .* (action.roll*π/180)
86-
γ = t .* (action.pitch*π/180)
8782
cx, cy, cz = get_center(action.center, x, y, z)
88-
x0, y0, z0 = x .- cx, y .- cy, z .- cz
89-
ux .= cos.(α) .* cos.(β) .* x0 +
90-
(cos.(α) .* sin.(β) .* sin.(γ) .- sin.(α) .* cos.(γ)) .* y0 +
91-
(cos.(α) .* sin.(β) .* cos.(γ) .+ sin.(α) .* sin.(γ)) .* z0 .+ cx .- x
83+
α = deg2rad(action.yaw)
84+
β = deg2rad(action.roll)
85+
γ = deg2rad(action.pitch)
86+
87+
@. ux = cos* t) * cos* t) * (x - cx) +
88+
(cos* t) * sin* t) * sin* t) - sin* t) * cos* t)) * (y - cy) +
89+
(cos* t) * sin* t) * cos* t) + sin* t) * sin* t)) * (z - cz) +
90+
cx - x
91+
9292
return nothing
9393
end
9494

9595
function displacement_y!(uy, action::Rotate, x, y, z, t)
96-
α = t .* (action.yaw*π/180)
97-
β = t .* (action.roll*π/180)
98-
γ = t .* (action.pitch*π/180)
9996
cx, cy, cz = get_center(action.center, x, y, z)
100-
x0, y0, z0 = x .- cx, y .- cy, z .- cz
101-
uy .= sin.(α) .* cos.(β) .* x0 +
102-
(sin.(α) .* sin.(β) .* sin.(γ) .+ cos.(α) .* cos.(γ)) .* y0 +
103-
(sin.(α) .* sin.(β) .* cos.(γ) .- cos.(α) .* sin.(γ)) .* z0 .+ cy .- y
97+
α = deg2rad(action.yaw)
98+
β = deg2rad(action.roll)
99+
γ = deg2rad(action.pitch)
100+
101+
@. uy = sin* t) * cos* t) * (x - cx) +
102+
(sin* t) * sin* t) * sin* t) + cos* t) * cos* t)) * (y - cy) +
103+
(sin* t) * sin* t) * cos* t) - cos* t) * sin* t)) * (z - cz) +
104+
cy - y
105+
104106
return nothing
105107
end
106108

107109
function displacement_z!(uz, action::Rotate, x, y, z, t)
108-
α = t .* (action.yaw*π/180)
109-
β = t .* (action.roll*π/180)
110-
γ = t .* (action.pitch*π/180)
111110
cx, cy, cz = get_center(action.center, x, y, z)
112-
x0, y0, z0 = x .- cx, y .- cy, z .- cz
113-
uz .= -sin.(β) .* x0 +
114-
cos.(β) .* sin.(γ) .* y0 +
115-
cos.(β) .* cos.(γ) .* z0 .+ cz .- z
111+
α = deg2rad(action.yaw)
112+
β = deg2rad(action.roll)
113+
γ = deg2rad(action.pitch)
114+
115+
@. uz = -sin* t) * (x - cx) +
116+
cos* t) * sin* t) * (y - cy) +
117+
cos* t) * cos* t) * (z - cz) +
118+
cz - z
119+
116120
return nothing
117121
end

0 commit comments

Comments
 (0)