From 95357c6841f234f481a21ceddfd64bde3a7dfcd5 Mon Sep 17 00:00:00 2001 From: Tim Schaefer Date: Mon, 15 Jun 2020 12:39:10 +0200 Subject: [PATCH] finish BYU write support --- NAMESPACE | 2 +- R/read_fs_surface.R | 4 +- R/write_fs_surface.R | 84 ++++++++++++++++++++++++++++--------- man/faces.quad.to.tris.Rd | 1 + man/fixed.vec.format.int.Rd | 3 +- man/read.fs.curv.Rd | 2 +- man/read.fs.mgh.Rd | 2 +- man/read.fs.morph.Rd | 4 +- man/read.fs.surface.Rd | 3 +- man/read.fs.surface.asc.Rd | 1 + man/read.fs.surface.gii.Rd | 1 + man/read.fs.surface.ply.Rd | 1 + man/read.fs.surface.vtk.Rd | 1 + man/read.fs.volume.Rd | 2 +- man/read_nisurface.Rd | 1 + man/read_nisurfacefile.Rd | 1 + man/write.fs.surface.Rd | 3 +- man/write.fs.surface.asc.Rd | 1 + man/write.fs.surface.byu.Rd | 53 +++++++++++++++++++++++ man/write.fs.surface.gii.Rd | 1 + man/write.fs.surface.mz3.Rd | 3 +- man/write.fs.surface.vtk.Rd | 1 + 22 files changed, 143 insertions(+), 32 deletions(-) create mode 100644 man/write.fs.surface.byu.Rd diff --git a/NAMESPACE b/NAMESPACE index 6db9013..9fe479d 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -14,7 +14,6 @@ export(colortable.from.annot) export(delete_all_optional_data) export(download_optional_data) export(faces.quad.to.tris) -export(fixed.vec.format.int) export(flip2D) export(flip3D) export(fs.get.morph.file.ext.for.format) @@ -85,6 +84,7 @@ export(write.fs.morph.gii) export(write.fs.patch) export(write.fs.surface) export(write.fs.surface.asc) +export(write.fs.surface.byu) export(write.fs.surface.gii) export(write.fs.surface.mz3) export(write.fs.surface.obj) diff --git a/R/read_fs_surface.R b/R/read_fs_surface.R index 2ce0766..ffe3193 100644 --- a/R/read_fs_surface.R +++ b/R/read_fs_surface.R @@ -896,8 +896,8 @@ read.fs.surface.byu <- function(filepath, part = 1L) { } relevant_part_info_line_index = part + 1L; part_info = as.integer(linesplit.fixed(byu_lines[relevant_part_info_line_index], length_per_part=6L, num_parts_expected=2L, error_tag = relevant_part_info_line_index)); - part_start = part_info[1]; # the first face (by one-based index in the face list) of this mesh - part_end = part_info[2]; # the last face (by one-based index in the face list) of this mesh + part_start = part_info[1]; # the first vertex index (by one-based index in the face list) of this mesh + part_end = part_info[2]; # the last vertex index (by one-based index in the face list) of this mesh # Read the point lines. Each line contains the x, y, z coords for 2 vertices (=2 x 3 numbers), the last line may of # course only contain the coords for a single vertex. diff --git a/R/write_fs_surface.R b/R/write_fs_surface.R index a0f1680..f735b79 100644 --- a/R/write_fs_surface.R +++ b/R/write_fs_surface.R @@ -9,7 +9,7 @@ #' #' @param 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 FreeSurfer style, i.e., all indices will have 1 substracted, so that the index of the first vertex will be zero. #' -#' @param format character string, the format to use. One of 'bin' for FreeSurfer binary surface format, 'asc' for FreeSurfer ASCII format, 'vtk' for VTK ASCII legacy format, 'ply' for Standford PLY format, 'off' for Object File Format, 'obj' for Wavefront object format, 'gii' for GIFTI format, or 'auto' to derive the format from the file extension given in parameter 'filepath'. With 'auto', a path ending in '.asc' is interpreted as 'asc', a path ending in '.vtk' as vtk, and so on for the other formats. Everything not matching any of these is interpreted as 'bin', i.e., FreeSurfer binary surface format. +#' @param format character string, the format to use. One of 'bin' for FreeSurfer binary surface format, 'asc' for FreeSurfer ASCII format, 'vtk' for VTK ASCII legacy format, 'ply' for Standford PLY format, 'off' for Object File Format, 'obj' for Wavefront object format, 'gii' for GIFTI format, 'mz3' for Surf-Ice MZ3 fomat, 'byu' for Brigham Young University (BYU) mesh format, or 'auto' to derive the format from the file extension given in parameter 'filepath'. With 'auto', a path ending in '.asc' is interpreted as 'asc', a path ending in '.vtk' as vtk, and so on for the other formats. Everything not matching any of these is interpreted as 'bin', i.e., FreeSurfer binary surface format. #' #' @return character string, the format that was written. One of "tris" or "quads". Currently only triangular meshes are supported, so always 'tris'. #' @@ -31,8 +31,8 @@ #' @export write.fs.surface <- function(filepath, vertex_coords, faces, format='auto') { - if(!(format %in% c('auto', 'bin', 'asc', 'vtk', 'obj', 'off', 'ply', 'gii', 'mz3'))) { - stop("Format must be one of c('auto', 'bin', 'asc', 'vtk', 'obj', 'off', 'ply', 'gii', 'mz3')."); + if(!(format %in% c('auto', 'bin', 'asc', 'vtk', 'obj', 'off', 'ply', 'gii', 'mz3', 'byu'))) { + stop("Format must be one of c('auto', 'bin', 'asc', 'vtk', 'obj', 'off', 'ply', 'gii', 'mz3', 'byu')."); } if(ncol(vertex_coords) != 3L) { @@ -70,6 +70,10 @@ write.fs.surface <- function(filepath, vertex_coords, faces, format='auto') { return(write.fs.surface.mz3(filepath, vertex_coords, faces)); } + if(format == 'byu' | (format == 'auto' & filepath.ends.with(filepath, c('.byu')))) { + return(write.fs.surface.byu(filepath, vertex_coords, faces)); + } + TRIS_MAGIC_FILE_TYPE_NUMBER = 16777214L; OLD_QUAD_MAGIC_FILE_TYPE_NUMBER = 16777215L; NEW_QUAD_MAGIC_FILE_TYPE_NUMBER = 16777213L; @@ -595,7 +599,7 @@ write.fs.surface.gii <- function(filepath, vertex_coords, faces) { #' write.fs.surface.mz3(tempfile(fileext=".mz3"), mesh$vertices, mesh$faces); #' } #' -#' @note This format is used by the surf-ice renderer. +#' @note This format is used by the surf-ice renderer. The format spec is at \url{https://github.com/neurolabusc/surf-ice/tree/master/mz3}. #' #' @export write.fs.surface.mz3 <- function(filepath, vertex_coords, faces, gzipped=TRUE) { @@ -649,16 +653,21 @@ write.fs.surface.mz3 <- function(filepath, vertex_coords, faces, gzipped=TRUE) { #' #' @param align_right logical, whether to align the integers to the right. As you may have guessed, set to `FALSE` to align to the left. #' -#' @return character string, the formatted data. May contain newlines. +#' @return vector of character strings, the formatted data lines. #' -#' @export +#' @keywords internal fixed.vec.format.int <- function(vdata, num_chars_per_entry, max_entries_per_line=NULL, align_right=TRUE) { num_chars_per_entry = as.integer(num_chars_per_entry); if(align_right) { - format_string = sprintf("%%%dd", num_chars_per_entry); + format_string = sprintf("%% %dd", num_chars_per_entry); } else { - format_string = sprintf("%%-%dd", num_chars_per_entry); + format_string = sprintf("%% -%dd", num_chars_per_entry); } + return(fixed.format.lines(vdata, format_string, max_entries_per_line = max_entries_per_line)); +} + +#' @keywords internal +fixed.format.lines <- function(vdata, format_string, max_entries_per_line=NULL) { if(is.null(max_entries_per_line)) { return(paste(sprintf(format_string, vdata), collapse="")); } else { @@ -672,22 +681,40 @@ fixed.vec.format.int <- function(vdata, num_chars_per_entry, max_entries_per_lin end_idx = length(vdata); } num_written = end_idx - start_idx + 1L; - #cat(sprintf("%d written: from index %d to %d (total %d, %d per line).\n", num_written, start_idx, end_idx, length(vdata), max_entries_per_line)); this_line = paste(sprintf(format_string, vdata[start_idx:end_idx]), collapse=""); - if(is.null(result_string)) { - result_string = this_line; - } else { - result_string = paste(result_string, this_line, sep = "\n"); - } + result_string = c(result_string, this_line); num_left = num_left - num_written; start_idx = end_idx + 1L; } + return(result_string); } - return(result_string); } - +#' @title Write mesh to file in BYU ASCII format. +#' +#' @param filepath string. Full path to the output surface file, should end with '.byu', but that is not enforced. +#' +#' @inheritParams write.fs.surface +#' +#' @return string the format that was written. One of "tris" or "quads". Currently only triangular meshes are supported, so always 'tris'. +#' +#' @family mesh functions +#' +#' @examples +#' \donttest{ +#' # 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.byu(tempfile(fileext=".byu"), mesh$vertices, mesh$faces); +#' } +#' +#' @note This is a fixed field length ASCII format. Keep in mind that the BYU format expects the coordinates to be in the cube -1 to +1 on all three axes. +#' +#' @export write.fs.surface.byu <- function(filepath, vertex_coords, faces) { num_verts = nrow(vertex_coords); @@ -700,18 +727,35 @@ write.fs.surface.byu <- function(filepath, vertex_coords, faces) { stop("Parameter 'faces' must be a matrix with 3 columns (the indices of the vertices making up the faces)."); } - fh = file(filepath, "w"); + # The BYU format expects the coordinates to be in the cube -1 to +1 on all axes. Warn if that is not the case. + coord_min = min(min(vertex_coords[,1]), min(vertex_coords[,2]), min(vertex_coords[,3])); + coord_max = max(max(vertex_coords[,1]), max(vertex_coords[,2]), max(vertex_coords[,3])); + if(coord_min < -1.0 | coord_max > 1.0) { + stop(sprintf("Exported BYU mesh contains vertex coordinates outside of expected range -1 to 1 (coord range of mesh is %f to %f). Consider rescaling.\n", coord_min, coord_max)); + } + fh = file(filepath, "w"); # write header num_meshes = 1L; - header_data = c(num_meshes, num_verts, num_faces, (num_verts * 3L), 0L); - header_line = fixed.vec.format.intfunction(header_data, num_chars_per_entry=6L); + header_data = c(num_meshes, num_verts, num_faces, (num_faces * 3L), 0L); + header_line = fixed.vec.format.int(header_data, num_chars_per_entry=6L); # write the lines identifying the start and stop of the meshes in the faces list. Only one mesh in our case, that spans the entire list. - part_line = fixed.vec.format.intfunction(c(1L, (num_verts * 3L)), num_chars_per_entry=6L); + part_line = fixed.vec.format.int(c(1L, (num_faces * 3L)), num_chars_per_entry=6L); writeLines(c(header_line, part_line), fh); # write the vertex coordinates + vertex_coords_vec = as.double(t(vertex_coords)); + vertex_lines = fixed.format.lines(vertex_coords_vec, format_string="% 1.5e", max_entries_per_line=6L); + writeLines(vertex_lines, fh); + + # Write faces. + # Turn matrix of vertex indices into a vector and make the index of the last vertex of each face negative: + face_vertex_indices = as.integer(t(faces)); + last_vertices_of_faces_indices = seq.int(3L, length(face_vertex_indices), by=3L); + face_vertex_indices[last_vertices_of_faces_indices] = -face_vertex_indices[last_vertices_of_faces_indices]; + face_lines = fixed.vec.format.int(face_vertex_indices, num_chars_per_entry=6L, max_entries_per_line=16L); + writeLines(face_lines, fh); close(fh); } diff --git a/man/faces.quad.to.tris.Rd b/man/faces.quad.to.tris.Rd index 0ac6e60..62d476b 100644 --- a/man/faces.quad.to.tris.Rd +++ b/man/faces.quad.to.tris.Rd @@ -28,6 +28,7 @@ Other mesh functions: \code{\link{read_nisurfacefile}()}, \code{\link{read_nisurface}()}, \code{\link{write.fs.surface.asc}()}, +\code{\link{write.fs.surface.byu}()}, \code{\link{write.fs.surface.gii}()}, \code{\link{write.fs.surface.mz3}()}, \code{\link{write.fs.surface.vtk}()}, diff --git a/man/fixed.vec.format.int.Rd b/man/fixed.vec.format.int.Rd index 09ee328..203d33f 100644 --- a/man/fixed.vec.format.int.Rd +++ b/man/fixed.vec.format.int.Rd @@ -21,8 +21,9 @@ fixed.vec.format.int( \item{align_right}{logical, whether to align the integers to the right. As you may have guessed, set to `FALSE` to align to the left.} } \value{ -character string, the formatted data. May contain newlines. +vector of character strings, the formatted data lines. } \description{ Write fixed width integers to one or several lines. } +\keyword{internal} diff --git a/man/read.fs.curv.Rd b/man/read.fs.curv.Rd index 1fc26cd..69c7cd8 100644 --- a/man/read.fs.curv.Rd +++ b/man/read.fs.curv.Rd @@ -22,7 +22,7 @@ Read vertex-wise brain morphometry data from a file in FreeSurfer 'curv' format. curvfile = system.file("extdata", "lh.thickness", package = "freesurferformats", mustWork = TRUE); ct = read.fs.curv(curvfile); - cat(sprintf("Read data for \%d vertices. Values: min=\%f, mean=\%f, max=\%f.\\n", + cat(sprintf("Read data for \%d vertices. Values: min=\%f, mean=\%f, max=\%f.\n", length(ct), min(ct), mean(ct), max(ct))); } diff --git a/man/read.fs.mgh.Rd b/man/read.fs.mgh.Rd index 29af728..a327af7 100644 --- a/man/read.fs.mgh.Rd +++ b/man/read.fs.mgh.Rd @@ -34,7 +34,7 @@ Read multi-dimensional brain imaging data from a file in FreeSurfer binary MGH o package = "freesurferformats", mustWork = TRUE); vd = read.fs.mgh(brain_image); - cat(sprintf("Read voxel data with dimensions \%s. Values: min=\%d, mean=\%f, max=\%d.\\n", + cat(sprintf("Read voxel data with dimensions \%s. Values: min=\%d, mean=\%f, max=\%d.\n", paste(dim(vd), collapse = ' '), min(vd), mean(vd), max(vd))); # Read it again with full header data: vdh = read.fs.mgh(brain_image, with_header = TRUE); diff --git a/man/read.fs.morph.Rd b/man/read.fs.morph.Rd index 90c3c1c..790a364 100644 --- a/man/read.fs.morph.Rd +++ b/man/read.fs.morph.Rd @@ -21,14 +21,14 @@ Read vertex-wise brain surface data from a file. The file can be in any of the s curvfile = system.file("extdata", "lh.thickness", package = "freesurferformats", mustWork = TRUE); ct = read.fs.morph(curvfile); - cat(sprintf("Read data for \%d vertices. Values: min=\%f, mean=\%f, max=\%f.\\n", + cat(sprintf("Read data for \%d vertices. Values: min=\%f, mean=\%f, max=\%f.\n", length(ct), min(ct), mean(ct), max(ct))); mghfile = system.file("extdata", "lh.curv.fwhm10.fsaverage.mgz", package = "freesurferformats", mustWork = TRUE); curv = read.fs.morph(mghfile); - cat(sprintf("Read data for \%d vertices. Values: min=\%f, mean=\%f, max=\%f.\\n", + cat(sprintf("Read data for \%d vertices. Values: min=\%f, mean=\%f, max=\%f.\n", length(ct), min(ct), mean(ct), max(ct))); } diff --git a/man/read.fs.surface.Rd b/man/read.fs.surface.Rd index a5f70e6..e0d8a84 100644 --- a/man/read.fs.surface.Rd +++ b/man/read.fs.surface.Rd @@ -21,7 +21,7 @@ Read a brain surface mesh consisting of vertex and face data from a file in Free surface_file = system.file("extdata", "lh.tinysurface", package = "freesurferformats", mustWork = TRUE); mesh = read.fs.surface(surface_file); - cat(sprintf("Read data for \%d vertices and \%d faces. \\n", + cat(sprintf("Read data for \%d vertices and \%d faces. \n", nrow(mesh$vertices), nrow(mesh$faces))); } @@ -35,6 +35,7 @@ Other mesh functions: \code{\link{read_nisurfacefile}()}, \code{\link{read_nisurface}()}, \code{\link{write.fs.surface.asc}()}, +\code{\link{write.fs.surface.byu}()}, \code{\link{write.fs.surface.gii}()}, \code{\link{write.fs.surface.mz3}()}, \code{\link{write.fs.surface.vtk}()}, diff --git a/man/read.fs.surface.asc.Rd b/man/read.fs.surface.asc.Rd index c4657f4..2ffbcf0 100644 --- a/man/read.fs.surface.asc.Rd +++ b/man/read.fs.surface.asc.Rd @@ -28,6 +28,7 @@ Other mesh functions: \code{\link{read_nisurfacefile}()}, \code{\link{read_nisurface}()}, \code{\link{write.fs.surface.asc}()}, +\code{\link{write.fs.surface.byu}()}, \code{\link{write.fs.surface.gii}()}, \code{\link{write.fs.surface.mz3}()}, \code{\link{write.fs.surface.vtk}()}, diff --git a/man/read.fs.surface.gii.Rd b/man/read.fs.surface.gii.Rd index cb33a92..f977f9d 100644 --- a/man/read.fs.surface.gii.Rd +++ b/man/read.fs.surface.gii.Rd @@ -25,6 +25,7 @@ Other mesh functions: \code{\link{read_nisurfacefile}()}, \code{\link{read_nisurface}()}, \code{\link{write.fs.surface.asc}()}, +\code{\link{write.fs.surface.byu}()}, \code{\link{write.fs.surface.gii}()}, \code{\link{write.fs.surface.mz3}()}, \code{\link{write.fs.surface.vtk}()}, diff --git a/man/read.fs.surface.ply.Rd b/man/read.fs.surface.ply.Rd index 3a299e3..96f8e98 100644 --- a/man/read.fs.surface.ply.Rd +++ b/man/read.fs.surface.ply.Rd @@ -28,6 +28,7 @@ Other mesh functions: \code{\link{read_nisurfacefile}()}, \code{\link{read_nisurface}()}, \code{\link{write.fs.surface.asc}()}, +\code{\link{write.fs.surface.byu}()}, \code{\link{write.fs.surface.gii}()}, \code{\link{write.fs.surface.mz3}()}, \code{\link{write.fs.surface.vtk}()}, diff --git a/man/read.fs.surface.vtk.Rd b/man/read.fs.surface.vtk.Rd index 6a8ff84..291e140 100644 --- a/man/read.fs.surface.vtk.Rd +++ b/man/read.fs.surface.vtk.Rd @@ -28,6 +28,7 @@ Other mesh functions: \code{\link{read_nisurfacefile}()}, \code{\link{read_nisurface}()}, \code{\link{write.fs.surface.asc}()}, +\code{\link{write.fs.surface.byu}()}, \code{\link{write.fs.surface.gii}()}, \code{\link{write.fs.surface.mz3}()}, \code{\link{write.fs.surface.vtk}()}, diff --git a/man/read.fs.volume.Rd b/man/read.fs.volume.Rd index 38434cd..1ae7daa 100644 --- a/man/read.fs.volume.Rd +++ b/man/read.fs.volume.Rd @@ -34,7 +34,7 @@ Read multi-dimensional brain imaging data from a file. package = "freesurferformats", mustWork = TRUE); vd = read.fs.volume(brain_image); - cat(sprintf("Read voxel data with dimensions \%s. Values: min=\%d, mean=\%f, max=\%d.\\n", + cat(sprintf("Read voxel data with dimensions \%s. Values: min=\%d, mean=\%f, max=\%d.\n", paste(dim(vd), collapse = ' '), min(vd), mean(vd), max(vd))); # Read it again with full header data: vdh = read.fs.volume(brain_image, with_header = TRUE); diff --git a/man/read_nisurface.Rd b/man/read_nisurface.Rd index 0af0b30..2d04573 100644 --- a/man/read_nisurface.Rd +++ b/man/read_nisurface.Rd @@ -39,6 +39,7 @@ Other mesh functions: \code{\link{read.fs.surface}()}, \code{\link{read_nisurfacefile}()}, \code{\link{write.fs.surface.asc}()}, +\code{\link{write.fs.surface.byu}()}, \code{\link{write.fs.surface.gii}()}, \code{\link{write.fs.surface.mz3}()}, \code{\link{write.fs.surface.vtk}()}, diff --git a/man/read_nisurfacefile.Rd b/man/read_nisurfacefile.Rd index 95876e0..5e33a2b 100644 --- a/man/read_nisurfacefile.Rd +++ b/man/read_nisurfacefile.Rd @@ -36,6 +36,7 @@ Other mesh functions: \code{\link{read.fs.surface}()}, \code{\link{read_nisurface}()}, \code{\link{write.fs.surface.asc}()}, +\code{\link{write.fs.surface.byu}()}, \code{\link{write.fs.surface.gii}()}, \code{\link{write.fs.surface.mz3}()}, \code{\link{write.fs.surface.vtk}()}, diff --git a/man/write.fs.surface.Rd b/man/write.fs.surface.Rd index 54de1e9..2436446 100644 --- a/man/write.fs.surface.Rd +++ b/man/write.fs.surface.Rd @@ -13,7 +13,7 @@ write.fs.surface(filepath, vertex_coords, faces, format = "auto") \item{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 FreeSurfer style, i.e., all indices will have 1 substracted, so that the index of the first vertex will be zero.} -\item{format}{character string, the format to use. One of 'bin' for FreeSurfer binary surface format, 'asc' for FreeSurfer ASCII format, 'vtk' for VTK ASCII legacy format, 'ply' for Standford PLY format, 'off' for Object File Format, 'obj' for Wavefront object format, 'gii' for GIFTI format, or 'auto' to derive the format from the file extension given in parameter 'filepath'. With 'auto', a path ending in '.asc' is interpreted as 'asc', a path ending in '.vtk' as vtk, and so on for the other formats. Everything not matching any of these is interpreted as 'bin', i.e., FreeSurfer binary surface format.} +\item{format}{character string, the format to use. One of 'bin' for FreeSurfer binary surface format, 'asc' for FreeSurfer ASCII format, 'vtk' for VTK ASCII legacy format, 'ply' for Standford PLY format, 'off' for Object File Format, 'obj' for Wavefront object format, 'gii' for GIFTI format, 'mz3' for Surf-Ice MZ3 fomat, 'byu' for Brigham Young University (BYU) mesh format, or 'auto' to derive the format from the file extension given in parameter 'filepath'. With 'auto', a path ending in '.asc' is interpreted as 'asc', a path ending in '.vtk' as vtk, and so on for the other formats. Everything not matching any of these is interpreted as 'bin', i.e., FreeSurfer binary surface format.} } \value{ character string, the format that was written. One of "tris" or "quads". Currently only triangular meshes are supported, so always 'tris'. @@ -45,6 +45,7 @@ Other mesh functions: \code{\link{read_nisurfacefile}()}, \code{\link{read_nisurface}()}, \code{\link{write.fs.surface.asc}()}, +\code{\link{write.fs.surface.byu}()}, \code{\link{write.fs.surface.gii}()}, \code{\link{write.fs.surface.mz3}()}, \code{\link{write.fs.surface.vtk}()} diff --git a/man/write.fs.surface.asc.Rd b/man/write.fs.surface.asc.Rd index 37efa46..2ecc303 100644 --- a/man/write.fs.surface.asc.Rd +++ b/man/write.fs.surface.asc.Rd @@ -42,6 +42,7 @@ Other mesh functions: \code{\link{read.fs.surface}()}, \code{\link{read_nisurfacefile}()}, \code{\link{read_nisurface}()}, +\code{\link{write.fs.surface.byu}()}, \code{\link{write.fs.surface.gii}()}, \code{\link{write.fs.surface.mz3}()}, \code{\link{write.fs.surface.vtk}()}, diff --git a/man/write.fs.surface.byu.Rd b/man/write.fs.surface.byu.Rd new file mode 100644 index 0000000..349fb3c --- /dev/null +++ b/man/write.fs.surface.byu.Rd @@ -0,0 +1,53 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/write_fs_surface.R +\name{write.fs.surface.byu} +\alias{write.fs.surface.byu} +\title{Write mesh to file in BYU ASCII format.} +\usage{ +write.fs.surface.byu(filepath, vertex_coords, faces) +} +\arguments{ +\item{filepath}{string. Full path to the output surface file, should end with '.byu', but that is not enforced.} + +\item{vertex_coords}{n x 3 matrix of doubles. Each row defined the x,y,z coords for a vertex.} + +\item{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 FreeSurfer style, i.e., all indices will have 1 substracted, so that the index of the first vertex will be zero.} +} +\value{ +string the format that was written. One of "tris" or "quads". Currently only triangular meshes are supported, so always 'tris'. +} +\description{ +Write mesh to file in BYU ASCII format. +} +\note{ +This is a fixed field length ASCII format. Keep in mind that the BYU format expects the coordinates to be in the cube -1 to +1 on all three axes. +} +\examples{ +\donttest{ + # 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.byu(tempfile(fileext=".byu"), mesh$vertices, mesh$faces); +} + +} +\seealso{ +Other mesh functions: +\code{\link{faces.quad.to.tris}()}, +\code{\link{read.fs.surface.asc}()}, +\code{\link{read.fs.surface.gii}()}, +\code{\link{read.fs.surface.ply}()}, +\code{\link{read.fs.surface.vtk}()}, +\code{\link{read.fs.surface}()}, +\code{\link{read_nisurfacefile}()}, +\code{\link{read_nisurface}()}, +\code{\link{write.fs.surface.asc}()}, +\code{\link{write.fs.surface.gii}()}, +\code{\link{write.fs.surface.mz3}()}, +\code{\link{write.fs.surface.vtk}()}, +\code{\link{write.fs.surface}()} +} +\concept{mesh functions} diff --git a/man/write.fs.surface.gii.Rd b/man/write.fs.surface.gii.Rd index f622eb0..67c0635 100644 --- a/man/write.fs.surface.gii.Rd +++ b/man/write.fs.surface.gii.Rd @@ -42,6 +42,7 @@ Other mesh functions: \code{\link{read_nisurfacefile}()}, \code{\link{read_nisurface}()}, \code{\link{write.fs.surface.asc}()}, +\code{\link{write.fs.surface.byu}()}, \code{\link{write.fs.surface.mz3}()}, \code{\link{write.fs.surface.vtk}()}, \code{\link{write.fs.surface}()} diff --git a/man/write.fs.surface.mz3.Rd b/man/write.fs.surface.mz3.Rd index 189ebb6..1e0575d 100644 --- a/man/write.fs.surface.mz3.Rd +++ b/man/write.fs.surface.mz3.Rd @@ -22,7 +22,7 @@ string the format that was written. One of "tris" or "quads". Currently only tri Write mesh to file in mz3 binary format. } \note{ -This format is used by the surf-ice renderer. +This format is used by the surf-ice renderer. The format spec is at \url{https://github.com/neurolabusc/surf-ice/tree/master/mz3}. } \examples{ \donttest{ @@ -47,6 +47,7 @@ Other mesh functions: \code{\link{read_nisurfacefile}()}, \code{\link{read_nisurface}()}, \code{\link{write.fs.surface.asc}()}, +\code{\link{write.fs.surface.byu}()}, \code{\link{write.fs.surface.gii}()}, \code{\link{write.fs.surface.vtk}()}, \code{\link{write.fs.surface}()} diff --git a/man/write.fs.surface.vtk.Rd b/man/write.fs.surface.vtk.Rd index f99a065..94018ff 100644 --- a/man/write.fs.surface.vtk.Rd +++ b/man/write.fs.surface.vtk.Rd @@ -42,6 +42,7 @@ Other mesh functions: \code{\link{read_nisurfacefile}()}, \code{\link{read_nisurface}()}, \code{\link{write.fs.surface.asc}()}, +\code{\link{write.fs.surface.byu}()}, \code{\link{write.fs.surface.gii}()}, \code{\link{write.fs.surface.mz3}()}, \code{\link{write.fs.surface}()}