write.fs.surface.ply: Write mesh to file in PLY format (.ply)

Description Usage Arguments Value References See Also Examples

View source: R/write_fs_surface.R

Description

The PLY format is a versatile ASCII format for storing meshes. Also known as Polygon File Format or Stanford Triangle Format.

Usage

1
write.fs.surface.ply(filepath, vertex_coords, faces, vertex_colors = NULL)

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

m 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 FreeSurfer style, i.e., all indices will have 1 substracted, so that the index of the first vertex will be zero.

vertex_colors

optional, matrix of RGBA vertex colors, number of rows must be the same as for vertex_coords. Color values must be integers in range 0-255. Alternatively, a vector of *n* RGB color strings can be passed.

Value

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

References

See http://paulbourke.net/dataformats/ply/ for the PLY format spec.

See Also

Other mesh export functions: write.fs.surface.obj(), write.fs.surface.off.ply2(), write.fs.surface.off(), write.fs.surface.ply2(), write.fs.surface()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
## 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.ply(tempfile(fileext=".ply"), mesh$vertices, mesh$faces);

    # save a version with RGBA vertex colors
    vertex_colors = matrix(rep(82L, 5*4), ncol=4);
    write.fs.surface.ply(tempfile(fileext=".ply"), mesh$vertices,
     mesh$faces, vertex_colors=vertex_colors);

## End(Not run)

freesurferformats documentation built on Feb. 11, 2022, 5:06 p.m.