Learn R Programming

freesurferformats (version 1.1.0)

write.fs.surface.vtk: Write mesh to file in VTK legacy format

Description

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.

Usage

write.fs.surface.vtk(
  filepath,
  vertex_coords,
  faces,
  version = 4.2,
  binary = FALSE
)

Value

string the format that was written. One of "tris" or "quads". Currently only triangular meshes are supported, so always 'tris'.

Arguments

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 OFFSETS/CONNECTIVITY layout that VTK itself has been producing since 2015. Only change this if you know that the software you hand the file to requires the newer layout.

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.

See Also

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()

Examples

Run this code
if (FALSE) {
# 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
)
}

Run the code above in your browser using DataLab