Still having problems with pointsinside.
load("/GD/LMBD/Papers/2017FAFB/bocklab_public/temca2data/geometry_analysis/data/pns.RData")
lhr=as.mesh3d(subset(FAFB13NP.surf, 'LH_R'))
pns.lh=nlapply(pns, subset, function(x) pointsinside(x, lhr))
pns.lh includes a lot of stuff outside the LH for some reason – only things that are distant though.
One option, given below would be to use a bounding box check to speed up computation as well as rejecting distant points.
# pointsinside seems to be misbehaving for points a long way away
contains_points <- function(obj, points, ...) UseMethod("contains_points")
contains_points.boundingbox <- function(obj, points, ...) {
xyz=xyzmatrix(points)
xyz[,1] >= obj[1,1] & xyz[,2] >= obj[1,2] & xyz[,3] >= obj[1,3] &
xyz[,1] <= obj[2,1] & xyz[,2] <= obj[2,2] & xyz[,3] <= obj[2,3]
}
contains_points.mesh3d <- function(obj, points, ...) {
xyz=xyzmatrix(points)
inbb=contains_points(boundingbox(obj), xyz, ...)
iosurf=pointsinside(xyz[inbb,], surf = obj, ...)
res=inbb
res[inbb]=iosurf
res
}
contains_points.hxsurf<-contains_points.mesh3d
Still having problems with
pointsinside.pns.lh includes a lot of stuff outside the LH for some reason – only things that are distant though.
One option, given below would be to use a bounding box check to speed up computation as well as rejecting distant points.