Learn R Programming

freesurferformats (version 1.1.0)

write.fs.surface.stl: Write mesh to file in STL format (ASCII or binary).

Description

The STL format (stereolithography, the format used for 3D printing) stores a triangular mesh as a list of triangles, each with its vertex coordinates repeated and with a normal vector, instead of storing a vertex list and indices into it. Both the ASCII and the binary version of the format are written by this function, the binary one being the default since it is much smaller and it is what most software uses. The resulting files can be read back with read.fs.surface.stl and are accepted by mesh viewers and slicers.

Usage

write.fs.surface.stl(
  filepath,
  vertex_coords,
  faces,
  ascii = FALSE,
  solid_name = "mesh"
)

Value

character string, the format that was written: 'tris'.

Arguments

filepath

character string, the path of the file to write.

vertex_coords

n x 3 matrix of doubles, the vertex coordinates.

faces

n x 3 matrix of integers, the vertex indices of the triangles. The STL format has no support for polygons with more than 3 vertices, so a quad mesh has to be converted first with faces.quad.to.tris.

ascii

logical, whether to write the ASCII version of the format. The default is the binary version, which is smaller by a factor of about 5 and which is what most mesh processing software writes. Use the ASCII version if the file has to be readable by humans or by software that supports only the ASCII variant.

solid_name

character string, the name of the mesh. Only used in the ASCII version, where the format requires the name in the first and the last line of the file.

See Also

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

Examples

Run this code
if (FALSE) {
# Write a mesh as binary and as ASCII STL:
mesh <- read.fs.surface(system.file("extdata", "cube.stl", package = "freesurferformats"));
write.fs.surface.stl(tempfile(fileext = ".stl"), mesh$vertices, mesh$faces);
write.fs.surface.stl(tempfile(fileext = ".stl"), mesh$vertices, mesh$faces, ascii = TRUE);

# The file format is also chosen by the file name when using the generic
# writer:
write.fs.surface(tempfile(fileext = ".stl"), mesh$vertices, mesh$faces);
}

Run the code above in your browser using DataLab