@@ -162,7 +162,11 @@ dotprops.neuron<-function(x, Labels=NULL, resample=NA, topo=FALSE, ...) {
162
162
if (is.null(Labels ) || isTRUE(Labels )) Labels = x $ d $ Label
163
163
else if (is.logical(labels ) && labels == FALSE ) Labels = NULL
164
164
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
+ }
166
170
dotprops(xyzmatrix(x ), Labels = Labels , topo_features = topo_features , ... )
167
171
}
168
172
@@ -261,17 +265,33 @@ dotprops.default<-function(x, k=NULL, Labels=NULL, na.rm=FALSE, topo_features=NU
261
265
vect [i ,]= v1d1 $ vectors [,1 ]
262
266
}
263
267
rlist = list (points = x ,alpha = alpha ,vect = vect )
264
-
265
268
rlist $ labels = Labels
266
-
269
+
267
270
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
268
283
rlist $ topo <- topo_features
269
284
}
270
285
271
286
attr(rlist ,' k' )= k
272
287
return (as.dotprops(rlist ))
273
288
}
274
289
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
+
275
295
# internal function to convert a dotprops object to SWC
276
296
# representation.
277
297
dotprops2swc <- function (x , label = 0L , veclength = 1 , radius = 0 ) {
0 commit comments