View source: R/write_fs_surface.R
| write.fs.surface.vtk | R Documentation |
The VTK legacy format is the plain text/binary format that is supported by all versions of the VTK library; the XML based VTK format (.vtp) is not the same thing. Two variants of the file layout exist and are both still written by software in use today: the old layout introduced in VTK 4.2, and the layout that VTK produces since version 5.1 (released 2015). The parameter 'version' selects which one to write.
write.fs.surface.vtk(
filepath,
vertex_coords,
faces,
version = 4.2,
binary = FALSE
)
filepath |
string. Full path to the output surface file, should end with '.vtk', but that is not enforced. |
vertex_coords |
n x 3 matrix of doubles. Each row defined the x,y,z coords for a vertex. |
faces |
n x 3 matrix of integers. Each row defined the 3 vertex indices that make up the face. WARNING: Vertex indices should be given in R-style, i.e., the index of the first vertex is 1. However, they will be written in VTK style, i.e., all indices will have 1 substracted, so that the index of the first vertex will be zero. |
version |
double, the VTK version whose file layout to write. Either 4.2 (the default) or 5.1. Version 4.2 writes the cell array layout that every VTK version can read, version 5.1 writes the |
binary |
logical, whether to write the data in binary form instead of the ASCII text form. Binary files are much smaller and much faster to read and write, but they are not human readable. Defaults to FALSE. |
string the format that was written. One of "tris" or "quads". Currently only triangular meshes are supported, so always 'tris'.
Binary data in the VTK legacy format is always big endian, the format has no way of expressing a different byte order. The vertex coordinates are written as single precision (4 byte) floats in both encodings, which is what VTK itself does.
Other mesh functions:
faces.quad.to.tris(),
read.fs.surface(),
read.fs.surface.asc(),
read.fs.surface.bvsrf(),
read.fs.surface.geo(),
read.fs.surface.gii(),
read.fs.surface.ico(),
read.fs.surface.obj(),
read.fs.surface.off(),
read.fs.surface.ply(),
read.fs.surface.vtk(),
read.mesh.brainvoyager(),
read_nisurface(),
read_nisurfacefile(),
write.fs.surface(),
write.fs.surface.asc(),
write.fs.surface.byu(),
write.fs.surface.gii(),
write.fs.surface.mz3()
Other mesh export functions:
write.fs.surface(),
write.fs.surface.obj(),
write.fs.surface.off(),
write.fs.surface.off.ply2(),
write.fs.surface.ply(),
write.fs.surface.ply2(),
write.fs.surface.stl()
## Not run:
# Read a surface from a file:
surface_file <- system.file("extdata", "lh.tinysurface",
package = "freesurferformats", mustWork = TRUE
)
mesh <- read.fs.surface(surface_file)
# Now save it:
write.fs.surface.vtk(tempfile(fileext = ".vtk"), mesh$vertices, mesh$faces)
# Or as a binary file using the layout of VTK 5.1:
write.fs.surface.vtk(tempfile(fileext = ".vtk"), mesh$vertices, mesh$faces,
version = 5.1, binary = TRUE
)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.