-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
297 additions
and
159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# internal function | ||
# read a mesh representing a neuron and return a mesh3d object | ||
read.neuron.mesh <- function(x, ...) { | ||
ext=tools::file_ext(x) | ||
|
||
if(ext=="ply") { | ||
if(!requireNamespace('Rvcg', quietly = TRUE)) | ||
stop("Please install suggested library Rvcg to read .ply files!") | ||
Rvcg::vcgPlyRead(x, updateNormals=F, ...) | ||
} else if(ext=="obj") { | ||
if(!requireNamespace('readobj', quietly = TRUE)) | ||
stop("Please install suggested library readobj to read .obj files!") | ||
res=readobj::read.obj(x, convert.rgl = TRUE) | ||
if(length(res)>1) | ||
warning("Only reading 1/",length(res)," objects in: ",x) | ||
res[[1]] | ||
} else { | ||
stop("Unrecognised mesh file format!") | ||
} | ||
} | ||
|
||
is.ply<-function(f=NULL, bytes=NULL) { | ||
if(!is.null(bytes) && is.character(f) && length(f)>1) | ||
stop("Can only check bytes for a single file") | ||
tocheck=if(is.null(bytes)) f else bytes | ||
generic_magic_check(tocheck, "ply") | ||
} | ||
|
||
write.neuron.ply <- function(x, file, binary=TRUE, ...) { | ||
write.neuron.mesh(x, file=file, format="ply", binary=binary, ...) | ||
} | ||
|
||
write.neuron.obj <- function(x, file, ... ) { | ||
write.neuron.mesh(x, file=file, format="obj", ...) | ||
} | ||
|
||
write.neuron.mesh <- function(x, file, format=c("ply", "obj"), ...) { | ||
if(!requireNamespace('Rvcg', quietly = TRUE)) | ||
stop("Please install suggested library Rvcg to write .",format," files!") | ||
if(!inherits(x, 'mesh3d')) { | ||
x=tryCatch(as.mesh3d(x), error=function(e) stop("Unable to convert x to mesh3d object! Only neuron meshes can be written in ",format," format!")) | ||
} | ||
if(format=="ply") | ||
Rvcg::vcgPlyWrite(x, filename=file, writeCol = F, writeNormals = F, ...) | ||
else if(format=="obj") | ||
Rvcg::vcgObjWrite(x, filename=file, writeNormals=F, ...) | ||
else stop("Unknown format") | ||
|
||
} |
Oops, something went wrong.