Skip to content

Commit 1e7bba7

Browse files
committed
dotprops vectors direction included in topo
1 parent 49d578d commit 1e7bba7

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

R/dotprops.R

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,11 @@ dotprops.neuron<-function(x, Labels=NULL, resample=NA, topo=FALSE, ...) {
162162
if(is.null(Labels) || isTRUE(Labels)) Labels=x$d$Label
163163
else if(is.logical(labels) && labels==FALSE) Labels=NULL
164164
topo_features <- NULL
165-
if (isTRUE(topo)) topo_features <- get_topo_features(x)
165+
if (isTRUE(topo)) {
166+
topo_features <- get_topo_features(x)
167+
topo_features$Parent <- x$d$Parent
168+
topo_features$PointNo <- x$d$PointNo
169+
}
166170
dotprops(xyzmatrix(x), Labels=Labels, topo_features=topo_features, ...)
167171
}
168172

@@ -261,17 +265,33 @@ dotprops.default<-function(x, k=NULL, Labels=NULL, na.rm=FALSE, topo_features=NU
261265
vect[i,]=v1d1$vectors[,1]
262266
}
263267
rlist=list(points=x,alpha=alpha,vect=vect)
264-
265268
rlist$labels=Labels
266-
269+
267270
if (!is.null(topo_features)) {
271+
# orient vectors so they look at their parent
272+
vect_orientations <- rep(TRUE, npoints)
273+
for (i in 1:npoints) {
274+
par_id = topo_features$Parent[[i]]
275+
if (par_id == -1) next
276+
pnt_idx = which(topo_features$PointNo == par_id)
277+
vect_orientations[[i]] <- is_pointing_towards(x[pnt_idx,], x[i,], vect[i])
278+
}
279+
vect[!vect_orientations,] <- -vect[!vect_orientations,]
280+
rlist$vect = vect
281+
topo_features$Parent <- NULL
282+
topo_features$PointNo <- NULL
268283
rlist$topo <- topo_features
269284
}
270285

271286
attr(rlist,'k')=k
272287
return(as.dotprops(rlist))
273288
}
274289

290+
is_pointing_towards <- function(soma_position, point_pos, vects) {
291+
to_point <- soma_position - point_pos
292+
dotprod(to_point, vects) > 0
293+
}
294+
275295
# internal function to convert a dotprops object to SWC
276296
# representation.
277297
dotprops2swc<-function(x, label=0L, veclength=1, radius=0) {

0 commit comments

Comments
 (0)