Transforms surface vertex positions from one coordinate space or orientation to another, optionally applying an additional custom transform.
Arguments
- surface
an
ieegio_surfaceobject or file path; seeas_ieegio_surfacefor valid inputs- space_from
source coordinate space; either an
ieegio_spaceobject (fromnew_space) or a character string; default is empty string- space_to
target coordinate space; either an
ieegio_spaceobject or a character string; default is empty string- transform
optional 4x4 affine transformation matrix or
ieegio_transformsobject to apply; seeas_ieegio_transform
Details
The function handles orientation changes (e.g., "RAS" to "LPS")
and optional custom transforms. It creates a transform chain consisting of:
an affine (orientation alignment from source), the custom transform, and
a post-affine (final orientation alignment to target).
If the provided transform has a "passive" interpretation, it is
automatically converted to an "active" interpretation before
being applied to the vertex coordinates.
See also
as_ieegio_surface for creating surface objects,
new_space for defining coordinate spaces,
transform_orientation for orientation transforms,
volume_to_surface for creating surfaces from volumes
Examples
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)
}
#> [1] 0 0