Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENH] topoDotprops modified #502

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions R/dotprops.R
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,11 @@ dotprops.neuron<-function(x, Labels=NULL, resample=NA, topo=FALSE, ...) {
if(is.null(Labels) || isTRUE(Labels)) Labels=x$d$Label
else if(is.logical(labels) && labels==FALSE) Labels=NULL
topo_features <- NULL
if (isTRUE(topo)) topo_features <- get_topo_features(x)
if (isTRUE(topo)) {
topo_features <- get_topo_features(x)
topo_features$Parent <- x$d$Parent
topo_features$PointNo <- x$d$PointNo
}
dotprops(xyzmatrix(x), Labels=Labels, topo_features=topo_features, ...)
}

Expand Down Expand Up @@ -261,17 +265,33 @@ dotprops.default<-function(x, k=NULL, Labels=NULL, na.rm=FALSE, topo_features=NU
vect[i,]=v1d1$vectors[,1]
}
rlist=list(points=x,alpha=alpha,vect=vect)

rlist$labels=Labels

if (!is.null(topo_features)) {
# orient vectors so they look at their parent
vect_orientations <- rep(TRUE, npoints)
for (i in 1:npoints) {
par_id = topo_features$Parent[[i]]
if (par_id == -1) next
pnt_idx = which(topo_features$PointNo == par_id)
vect_orientations[[i]] <- is_pointing_towards(x[pnt_idx,], x[i,], vect[i])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is direction in Euclidean sense not geodesic (across the graph). Can you help me understand why that is @dokato?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just figured that it's faster to compute with respect to an arbitrary point (soma in this case). Otherwise, I'd need to iterate point by point to change the orientation. I guess, as long as it's consisted it shouldn't matter too much, unless you can think of some counterexample?

}
vect[!vect_orientations,] <- -vect[!vect_orientations,]
rlist$vect = vect
topo_features$Parent <- NULL
topo_features$PointNo <- NULL
rlist$topo <- topo_features
}

attr(rlist,'k')=k
return(as.dotprops(rlist))
}

is_pointing_towards <- function(soma_position, point_pos, vects) {
to_point <- soma_position - point_pos
dotprod(to_point, vects) > 0
}

# internal function to convert a dotprops object to SWC
# representation.
dotprops2swc<-function(x, label=0L, veclength=1, radius=0) {
Expand Down