Learn R Programming

fsbrain (version 1.0.0)

apply.transform: Apply affine transformation to input.

Description

Apply an affine transformation, like a vox2ras_tkr transformation, to input. This is just matrix multiplication for different input objects. Supported input types are coordinate vectors, coordinate matrices, fs.surface meshes (the vertex coordinates are transformed, the face indices stay the same), renderable objects like fs.coloredmesh, fs.coloredvoxels, fs.coloredpaths or misc3d Triangles3D, rgl mesh3d/tmesh3d instances (including their normals, if any), and (hemi-)lists of such objects (which are transformed element-wise).

Usage

apply.transform(object, matrix_fun)

Value

the input after application of the affine matrix (matrix multiplication)

Arguments

object

numerical vector/matrix, fs.surface, fs.coloredmesh, fs.coloredvoxels, fs.coloredpaths, Triangles3D, mesh3d/tmesh3d instance, or a list (e.g., a hemilist) of such objects, the coordinates or objects to transform.

matrix_fun

a 4x4 affine matrix or a function returning such a matrix. If NULL, the input is returned as-is. In many cases you way want to use a matrix computed from the header of a volume file, e.g., the vox2ras matrix of the respective volume. See the mghheader.* functions in the freesurferformats package to obtain these matrices. Registration files can be read with freesurferformats::read.fs.transform and friends, but note that such files often describe a voxel to surface RAS mapping, so you may have to compose them with a vox2ras matrix to get a transformation between RAS coordinates.

Examples

Run this code
if (FALSE) {
   # Transform the vertex coordinates of a surface mesh:
   cube_file = system.file("extdata", "cube.ply", package = "fsbrain");
   cube = freesurferformats::read.fs.surface(cube_file);
   translation = matrix(c(1,0,0,10, 0,1,0,20, 0,0,1,30, 0,0,0,1), nrow = 4L, byrow = TRUE);
   cube_moved = apply.transform(cube, translation);
}

Run the code above in your browser using DataLab