subset.dotprops: Subset points in dotprops object that match given conditions

View source: R/dotprops.R

subset.dotpropsR Documentation

Subset points in dotprops object that match given conditions

Description

Subset points in dotprops object that match given conditions

Usage

## S3 method for class 'dotprops'
subset(x, subset, invert = FALSE, ...)

Arguments

x

A dotprops object

subset

A subset of points defined by indices, an expression or a function (see Details)

invert

Whether to invert the subset criteria - a convenience when selecting by function or indices.

...

Additional parameters (currently ignored)

Details

subset defines either logical or numeric indices, in which case these are simply applied to the matrices that define the points, vect fields of the dotprops object etc OR a function (which is called with the 3D points array and returns T/F. OR an expression vector).

Value

subsetted dotprops object

See Also

prune.dotprops, subset.neuron

Examples

## subset using indices ...
dp=kcs20[[10]]
dp1=subset(dp, 1:50)

# ... or an expression
dp2=subset(dp, alpha>0.7)
front=subset(dp, points[,'Z']<40)
# use a helper function
between=function(x, lower, upper) x>=lower & x<=upper
middle=middle=subset(dp, between(points[,'Z'], 40, 60))

# plot results in 3D

plot3d(front, col='red')
plot3d(middle, col='green')
plot3d(dp, col='blue')


## Not run: 

## subset using an selection function
s3d=select3d()
dp1=subset(dp, s3d(points))
# special case of previous version
dp2=subset(dp, s3d)
# keep the points that were removed from dp2
dp2.not=subset(dp, s3d, invert=TRUE)
# (another way of doing the same thing)
dp2.not=subset(dp, Negate(s3d))
stopifnot(all.equal(dp1, dp2))
dp2=subset(dp, alpha>0.5 & s3d(pointd))
dp3=subset(dp, 1:10)

## subset each dotprops object in a whole neuronlist
plot3d(kcs20)
s3d=select3d()
kcs20.partial = nlapply(kcs20, subset, s3d)
clear3d()
plot3d(kcs20.partial, col='red')
plot3d(kcs20, col='grey')

## End(Not run)

## Not run: 
## subset dotprops by mesh
#' library(nat.flybrains)
# extract calyx surface and convert to mesh3d
calyx=as.mesh3d(subset(MBL.surf, "MB_CA_L"))
# subset one neuron with this surface
kcs20.2_ca=subset(kcs20[[2]], function(x) pointsinside(x, calyx))
shade3d(calyx, alpha=0.2)
plot3d(kcs20.2_ca, lwd=3, col='black')

## subset neuronlist of dotprops by mesh
peduncle=as.mesh3d(subset(MBL.surf, "MB_PED_L"))
kcs20.ped=nlapply(kcs20, function(x) subset(x, pointsinside(x, peduncle)))
shade3d(peduncle, alpha=.2)
plot3d(kcs20.ped)

## End(Not run)

natverse/nat documentation built on Feb. 19, 2024, 7:19 a.m.