diff --git a/DESCRIPTION b/DESCRIPTION index fe19c086..540bc7d6 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -6,7 +6,8 @@ Authors@R: c( person("Gregory","Jefferis", email="jefferis@gmail.com", role = c("aut", "cre"), comment = c(ORCID = "0000-0002-0587-9355")), person("James", "Manton", role = c("aut"), comment = c(ORCID = "0000-0001-9260-3156")), - person("Sridhar", "Jagannathan", role = c("aut"), comment = c(ORCID = "0000-0002-2078-1145")) + person("Sridhar", "Jagannathan", role = c("aut"), comment = c(ORCID = "0000-0002-2078-1145")), + person("Dominik", "Krzeminski", role = c("ctb"), comment = c(ORCID = "0000-0003-4568-0583")) ) URL: https://github.com/natverse/nat, https://natverse.github.io BugReports: https://github.com/natverse/nat/issues diff --git a/NAMESPACE b/NAMESPACE index 04c277f5..bd4895ab 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -19,6 +19,7 @@ S3method("xyzmatrix<-",default) S3method("xyzmatrix<-",dotprops) S3method("xyzmatrix<-",hxsurf) S3method("xyzmatrix<-",igraph) +S3method("xyzmatrix<-",mesh3d) S3method("xyzmatrix<-",neuron) S3method("xyzmatrix<-",neuronlist) S3method("xyzmatrix<-",shape3d) @@ -184,6 +185,7 @@ S3method(xform,data.frame) S3method(xform,default) S3method(xform,dotprops) S3method(xform,list) +S3method(xform,mesh3d) S3method(xform,neuron) S3method(xform,neuronlist) S3method(xform,shape3d) diff --git a/NEWS.md b/NEWS.md index f4a68a9c..afae92a0 100644 --- a/NEWS.md +++ b/NEWS.md @@ -8,6 +8,9 @@ Some new features and bug fixes. Thanks to @PostPreAndCleft and @artxz for repor * Fix bug `pan3d()` not found (#447) * Added support for multi material binary Amira surface files while fixing "Bad triangle numbers" error in `read.hxsurf()` (#445) +* Add `xform()` and `xyzmatrix<-()` methods for `mesh3d` objects +* Don't clean `mesh3d` objects read from ply files by default +* `summary.neuron` now prints number of subtrees (#462, @dokato) # nat 1.10.2 diff --git a/R/dotprops.R b/R/dotprops.R index 45df2a3e..44f84be7 100644 --- a/R/dotprops.R +++ b/R/dotprops.R @@ -155,7 +155,7 @@ dotprops.neuronlist<-function(x, ..., OmitFailures=NA) { #' @param resample When finite, a new length to which all segmented edges will #' be resampled. See \code{\link{resample.neuron}}. #' @param topo flag that says whether or not to add topological features -#' (inverted Strahler's Order and distance from soma) +#' (reversed Strahler Order and distance from soma) #' @rdname dotprops dotprops.neuron<-function(x, Labels=NULL, resample=NA, topo=FALSE, ...) { if(is.finite(resample)) x=resample(x, stepsize = resample) @@ -212,7 +212,7 @@ get_distance_to_soma <- function(n) { #' behaviour for different classes of input object, \code{TRUE} always uses #' labels when an incoming object has them and \code{FALSE} never uses labels. #' @param na.rm Whether to remove \code{NA} points (default FALSE) -#' @param topo_features topological features of each dotprop +#' @param topo_features topological features of each dotprops #' @importFrom nabor knn #' @references The dotprops format is essentially identical to that developed #' in: diff --git a/R/neuron-mesh.R b/R/neuron-mesh.R index c4c8e503..e4074b7e 100644 --- a/R/neuron-mesh.R +++ b/R/neuron-mesh.R @@ -1,12 +1,15 @@ # internal function # read a mesh representing a neuron and return a mesh3d object -read.neuron.mesh <- function(x, ...) { +read.neuron.mesh <- function(x, updateNormals=FALSE, clean=FALSE, ...) { 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, ...) + m=Rvcg::vcgPlyRead(x, updateNormals=updateNormals, clean=clean, ...) + if(!inherits(m, 'shape3d')) + class(m)=union(class(m), 'shape3d') + m } else if(ext=="obj") { if(!requireNamespace('readobj', quietly = TRUE)) stop("Please install suggested library readobj to read .obj files!") diff --git a/R/summary.R b/R/summary.R index 239a7d6c..fd6a7cf6 100644 --- a/R/summary.R +++ b/R/summary.R @@ -39,6 +39,8 @@ summary.neuronlist<-function(object, ..., include.attached.dataframe=FALSE) { #' #' \item{cable.length} #' +#' \item{nTrees} +#' #' } #' @export #' @examples @@ -50,7 +52,8 @@ summary.neuron<-function(object, ...) { segments=object$NumSegs, branchpoints=length(object$BranchPoints), endpoints=length(object$EndPoints), - cable.length=total_cable(object)) + cable.length=total_cable(object), + nTrees=ifelse("nTrees" %in% names(object), object$nTrees, 1)) } #' @export diff --git a/R/xform.R b/R/xform.R index 7dee145d..ed4435b4 100644 --- a/R/xform.R +++ b/R/xform.R @@ -112,6 +112,10 @@ xform.list<-function(x, reg, FallBackToAffine=TRUE, na.action='error', ...){ #' @rdname xform xform.shape3d<-xform.list +#' @export +#' @rdname xform +xform.mesh3d<-xform.list + #' @export #' @rdname xform xform.neuron<-xform.list @@ -512,6 +516,11 @@ xyzmatrix.mesh3d<-function(x, ...){ x } +#' @export +#' @rdname xyzmatrix +`xyzmatrix<-.mesh3d`<-`xyzmatrix<-.shape3d` + + #' @export #' @rdname xyzmatrix `xyzmatrix<-.neuronlist`<-function(x, value){ diff --git a/man/dotprops.Rd b/man/dotprops.Rd index 4a5e6376..5d9d7008 100644 --- a/man/dotprops.Rd +++ b/man/dotprops.Rd @@ -55,11 +55,11 @@ labels when an incoming object has them and \code{FALSE} never uses labels.} be resampled. See \code{\link{resample.neuron}}.} \item{topo}{flag that says whether or not to add topological features -(inverted Strahler's Order and distance from soma)} +(reversed Strahler Order and distance from soma)} \item{na.rm}{Whether to remove \code{NA} points (default FALSE)} -\item{topo_features}{topological features of each dotprop} +\item{topo_features}{topological features of each dotprops} } \description{ \code{dotprops} makes dotprops representation from raw 3D points diff --git a/man/summary.neuron.Rd b/man/summary.neuron.Rd index 151ee596..26292048 100644 --- a/man/summary.neuron.Rd +++ b/man/summary.neuron.Rd @@ -44,6 +44,8 @@ A \code{data.frame} summarising the tree properties of the neuron \item{cable.length} + \item{nTrees} + } } \description{ diff --git a/man/xform.Rd b/man/xform.Rd index b67c83f2..23f9b3f4 100644 --- a/man/xform.Rd +++ b/man/xform.Rd @@ -6,6 +6,7 @@ \alias{xform.character} \alias{xform.list} \alias{xform.shape3d} +\alias{xform.mesh3d} \alias{xform.neuron} \alias{xform.data.frame} \alias{xform.dotprops} @@ -22,6 +23,8 @@ xform(x, reg, ...) \method{xform}{shape3d}(x, reg, FallBackToAffine = TRUE, na.action = "error", ...) +\method{xform}{mesh3d}(x, reg, FallBackToAffine = TRUE, na.action = "error", ...) + \method{xform}{neuron}(x, reg, FallBackToAffine = TRUE, na.action = "error", ...) \method{xform}{data.frame}(x, reg, subset = NULL, ...) diff --git a/man/xyzmatrix.Rd b/man/xyzmatrix.Rd index d024b1e7..4a6cbebf 100644 --- a/man/xyzmatrix.Rd +++ b/man/xyzmatrix.Rd @@ -19,6 +19,7 @@ \alias{xyzmatrix<-.hxsurf} \alias{xyzmatrix<-.igraph} \alias{xyzmatrix<-.shape3d} +\alias{xyzmatrix<-.mesh3d} \alias{xyzmatrix<-.neuronlist} \alias{xyzmatrix<-.shapelist3d} \title{Get and assign coordinates for classes containing 3D vertex data} @@ -59,6 +60,8 @@ xyzmatrix(x) <- value \method{xyzmatrix}{shape3d}(x) <- value +\method{xyzmatrix}{mesh3d}(x) <- value + \method{xyzmatrix}{neuronlist}(x) <- value \method{xyzmatrix}{shapelist3d}(x) <- value diff --git a/tests/testthat/test-summary.R b/tests/testthat/test-summary.R index 314d5dec..f23d394d 100644 --- a/tests/testthat/test-summary.R +++ b/tests/testthat/test-summary.R @@ -2,7 +2,7 @@ context("summary") test_that("summary.neuronlist behaves", { expect_is(s <- summary(Cell07PNs), 'data.frame') - expect_equal_to_reference(s, file = 'testdata/summary_cell07pns.rda', tolerance=1e-3) + expect_equal_to_reference(s, file = 'testdata/summary_cell07pns.rds', tolerance=1e-3) expect_is(summary(kcs20, veclength=1.2), 'data.frame') }) diff --git a/tests/testthat/testdata/summary_cell07pns.rda b/tests/testthat/testdata/summary_cell07pns.rda deleted file mode 100644 index f01e467e..00000000 Binary files a/tests/testthat/testdata/summary_cell07pns.rda and /dev/null differ diff --git a/tests/testthat/testdata/summary_cell07pns.rds b/tests/testthat/testdata/summary_cell07pns.rds new file mode 100644 index 00000000..c215298e Binary files /dev/null and b/tests/testthat/testdata/summary_cell07pns.rds differ