View source: R/vis_volume_3d.R
| apply.transform | R Documentation |
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).
apply.transform(object, matrix_fun)
object |
numerical vector/matrix, |
matrix_fun |
a 4x4 affine matrix or a function returning such a matrix. If |
the input after application of the affine matrix (matrix multiplication)
The affine matrix is applied in the standard way: the coordinates are interpreted as homogeneous column vectors, i.e., a vertex v is transformed as v' = M %*% v. Note that rgl, and fsbrain functions that are implemented on top of rgl (like the camera transforms used internally for views), use the transposed convention for their rotation matrices, see rotationMatrix. For pure translations and scalings, both conventions are identical.
Meshes keep their orientation: if the linear part of the matrix has a negative determinant, the transformation mirrors the object (this is the case for the FreeSurfer vox2ras_tkr matrix, which flips and permutes axes), which would invert all surface normals and make the mesh render inside-out. In that case, the vertex order within each face is reversed to preserve the original orientation, and the stored normals (if any) are transformed with the linear part of the matrix so that they stay consistent with the faces.
## Not run:
# 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);
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.