library(ieegio)
# geometry
geom_file <- "gifti/GzipBase64/sujet01_Lwhite.surf.gii"
if(ieegio_sample_data(geom_file, test = TRUE)) {
surf_ras <- read_surface(ieegio_sample_data(geom_file))
plot(surf_ras)
# ---- Change axis orientation ------------------
# convert from RAS orientation to LPS
surf_lps <- surface_to_surface(
surf_ras,
space_from = new_space("", orientation = "RAS"),
space_to = new_space("", orientation = "LPS")
)
plot(surf_lps)
# validate
lps_verts <- diag(c(-1, -1, 1, 1)) %*% surf_ras$geometry$vertices
range(surf_lps$geometry$vertices - lps_verts)
# ---- Apply transforms ------------------
transform <- matrix(
byrow = TRUE, nrow = 4,
c(
0.5, 0, 0.3, 1,
0, -1, 0.2, 2,
0, 0.7, -0.5, 4,
0, 0, 0, 1
)
)
surf_stretch <- surface_to_surface(surf_ras, transform = transform)
plot(surf_stretch)
# validate
stretch_verts <- transform %*% surf_ras$geometry$vertices
range(surf_stretch$geometry$vertices - stretch_verts)
}
Run the code above in your browser using DataLab