Skip to content

Commit

Permalink
Add xform/xyzmatrix/nvertices for shapelist3d
Browse files Browse the repository at this point in the history
* These changes should allow rgl::shapelist3d objects to be xformed 
  using the xform.list method.
* closes #419
  • Loading branch information
jefferis committed Nov 3, 2019
1 parent 7d37a62 commit 00aa254
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 1 deletion.
3 changes: 3 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ S3method("xyzmatrix<-",igraph)
S3method("xyzmatrix<-",neuron)
S3method("xyzmatrix<-",neuronlist)
S3method("xyzmatrix<-",shape3d)
S3method("xyzmatrix<-",shapelist3d)
S3method(Ops,dotprops)
S3method(Ops,hxsurf)
S3method(Ops,mesh3d)
Expand Down Expand Up @@ -105,6 +106,7 @@ S3method(nvertices,default)
S3method(nvertices,dotprops)
S3method(nvertices,neuron)
S3method(nvertices,neuronlist)
S3method(nvertices,shapelist3d)
S3method(plot,dotprops)
S3method(plot,neuron)
S3method(plot,neuronlist)
Expand Down Expand Up @@ -172,6 +174,7 @@ S3method(xyzmatrix,igraph)
S3method(xyzmatrix,mesh3d)
S3method(xyzmatrix,neuron)
S3method(xyzmatrix,neuronlist)
S3method(xyzmatrix,shapelist3d)
export("boundingbox<-")
export("data.frame<-")
export("xyzmatrix<-")
Expand Down
12 changes: 12 additions & 0 deletions R/xform.R
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,10 @@ xyzmatrix.neuronlist<-function(x, ...) {
do.call(rbind, coords)
}

#' @export
#' @rdname xyzmatrix
xyzmatrix.shapelist3d <- xyzmatrix.neuronlist

#' @export
#' @rdname xyzmatrix
xyzmatrix.dotprops<-function(x, ...) x$points
Expand Down Expand Up @@ -391,6 +395,10 @@ xyzmatrix.mesh3d<-function(x, ...){
x
}

#' @export
#' @rdname xyzmatrix
`xyzmatrix<-.shapelist3d`<-`xyzmatrix<-.neuronlist`

#' Find the number of vertices in an object (or each element of a neuronlist)
#'
#' @param x An object with 3d vertices (e.g. neuron, surface etc)
Expand Down Expand Up @@ -423,6 +431,10 @@ nvertices.neuronlist <- function(x, ...) {
sapply(x, nvertices)
}

#' @rdname nvertices
#' @export
nvertices.shapelist3d <- nvertices.neuronlist

#' Mirror 3D object about a given axis, optionally using a warping registration
#'
#' @description mirroring with a warping registration can be used to account
Expand Down
3 changes: 3 additions & 0 deletions man/nvertices.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions man/xyzmatrix.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion tests/testthat/test-hxsurf.R
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@ test_that("we can convert boundingbox to rgl::mesh3d",{
expect_equal(as.mesh3d(bb), rgl::cube3d())
})

test_that("we can convert use xyzmatrix on shapelist3d object",{
m=as.mesh3d(MBL.surf)
expect_equal(xyzmatrix(shapelist3d(m, plot=F)),
xyzmatrix(m))
})

test_that("we can convert ashape3d to rgl::mesh3d",{
skip_if_not_installed('alphashape3d')
kcs20.a=alphashape3d::ashape3d(xyzmatrix(kcs20), alpha = 10)
Expand All @@ -135,7 +141,6 @@ test_that("we can convert ashape3d to rgl::mesh3d",{
expect_true(all(pointsinside(kcs20, kcs20.a)))
})


test_that("we can save and re-read hxsurf object", {
surffile <- tempfile()
on.exit(unlink(surffile))
Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test-xform.R
Original file line number Diff line number Diff line change
Expand Up @@ -207,4 +207,5 @@ test_that("we can extract/replace coords and xform shape3d objects",{
expect_equal(dim(xyz), c(1068L, 3L))
# dummy transformation
expect_equal(xform(m, function(x,...) x), m)
expect_equal(xform(shapelist3d(m, plot = F), function(x,...) x)[[1]], m)
})

0 comments on commit 00aa254

Please sign in to comment.