Skip to content

Commit

Permalink
Merge pull request #428 from natverse/feature/more-elmr
Browse files Browse the repository at this point in the history
Remaining items to move from elmr
  • Loading branch information
jefferis committed Feb 23, 2020
2 parents 29122a6 + b1edd29 commit 4256f7b
Show file tree
Hide file tree
Showing 37 changed files with 321 additions and 137 deletions.
7 changes: 7 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ S3method(plot3d,dotprops)
S3method(plot3d,hxsurf)
S3method(plot3d,neuron)
S3method(plot3d,neuronlist)
S3method(plot3d,ngraph)
S3method(pointsinside,default)
S3method(potential_synapses,dotprops)
S3method(potential_synapses,neuron)
Expand Down Expand Up @@ -364,6 +365,7 @@ importFrom(igraph,V)
importFrom(igraph,add.edges)
importFrom(igraph,as.directed)
importFrom(igraph,as.undirected)
importFrom(igraph,as_edgelist)
importFrom(igraph,decompose.graph)
importFrom(igraph,degree)
importFrom(igraph,delete.vertices)
Expand All @@ -386,10 +388,15 @@ importFrom(nat.utils,RunCmdForNewerInput)
importFrom(nat.utils,is.gzip)
importFrom(nat.utils,makelock)
importFrom(nat.utils,removelock)
importFrom(rgl,arrow3d)
importFrom(rgl,par3d)
importFrom(rgl,plot3d)
importFrom(rgl,points3d)
importFrom(rgl,pop3d)
importFrom(rgl,rotationMatrix)
importFrom(rgl,scaleMatrix)
importFrom(rgl,spheres3d)
importFrom(rgl,text3d)
importFrom(stats,approx)
importFrom(stats,dnorm)
importFrom(stats,na.omit)
Expand Down
4 changes: 2 additions & 2 deletions R/nat-data.R
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,9 @@ NULL

#' Olfactory Projection Neuron reconstructed from EM data
#'
#' A DL1 olfactory projection neuuronobject traced in CATMAID from the FAFB
#' A DL1 olfactory projection neuron object traced in CATMAID from the FAFB
#' whole brain EM volume. This has a complex morphology that makes a good test
#' for pruning and simplifcation strategies.
#' for pruning and simplification strategies.
#'
#' @format A \code{neuron} object with additional class \code{catmaidneuron}
#' @source \url{http://www.diamondse.info/}
Expand Down
57 changes: 57 additions & 0 deletions R/neuron-plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -634,3 +634,60 @@ check_plotengine <- function(plotengine) {
'"', plotengine, '"',
"\nSee ?plot3d.neuronlist for details.", call.=FALSE))
}

#' Plot 3d representation of neuron (ngraph) with directed edges
#'
#' @param x A \code{\link{ngraph}} object
#' @param type They type of arrows (lines by default, see \code{\link{arrow3d}}
#' for details).
#' @param soma radius of soma (or \code{FALSE} to suppress plotting)
#' @param labels Whether to label nodes/all points with their raw index (not
#' id)
#' @param ... Additional arguments passed to \code{\link{arrow3d}}
#'
#' @export
#'
#' @importFrom igraph as_edgelist V
#' @importFrom rgl arrow3d par3d spheres3d text3d points3d pop3d
#' @examples
#' plot3d(as.ngraph(Cell07PNs[[1]]), labels='nodes')
plot3d.ngraph <- function(x, type='lines', soma=1,
labels=c('none', "nodes","all"), ...) {
labels=match.arg(labels)
el=igraph::as_edgelist(x, names=F)
xyz=xyzmatrix(x)

draw_edge <- function(edge, ...) {
e1=edge[1]
e2=edge[2]
if(e1 == e2) return()
p1=xyz[e1,]
p2=xyz[e2,]
if(any(is.na(c(p1,p2))) || all(p1==p2)) {
message("Bad edge: ", edge)
return()
}
# cat(edge,"\n")
arrow3d(xyz[edge[1],], xyz[edge[2],], type=type, ...)
}
# add points at each vertex so that scene dimensions
# are correctly set for arrows
pp=points3d(xyz, size=1)
op=par3d(skipRedraw=T)
on.exit(par3d(op))
on.exit(pop3d(id=pp), add = TRUE, after = TRUE)
apply(el, 1, draw_edge, ...)
rp=rootpoints(x)
if(isTRUE(all.equal(soma, FALSE))) {
# don't plot
} else spheres3d(xyz[rp,, drop=F], col='magenta', radius=soma)
if(labels!='none') {
all_points=igraph::V(x)
pointsel <- if(isTRUE(labels=='all')) {
all_points
} else {
unique(c(branchpoints(x), rootpoints(x), endpoints(x)))
}
text3d(xyz[pointsel,],texts = pointsel)
}
}
2 changes: 1 addition & 1 deletion R/ngraph.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
#' @family neuron
#' @seealso \code{\link{igraph}}, \code{\link[igraph]{set.vertex.attribute}},
#' \code{\link{subset.neuron}} for example of graph-based manipulation of a
#' neuron.
#' neuron, \code{\link{plot3d.ngraph}}
#' @export
#' @importFrom igraph V<-
#' @examples
Expand Down
1 change: 1 addition & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ reference:
- plot3d.hxsurf
- plot3d.neuron
- plot3d.cmtkreg
- plot3d.ngraph
- title: 3D Interaction with Objects
desc: Functions to review, identify, and modify objects by interactive selection in RGL windows.
contents:
Expand Down
8 changes: 4 additions & 4 deletions docs/articles/Installation.html

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

4 changes: 2 additions & 2 deletions docs/articles/NeuroGeometry.html

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 4256f7b

Please sign in to comment.