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

revamp/replace pointsinside #353

Closed
jefferis opened this issue Aug 24, 2017 · 7 comments
Closed

revamp/replace pointsinside #353

jefferis opened this issue Aug 24, 2017 · 7 comments

Comments

@jefferis
Copy link
Collaborator

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
@jefferis
Copy link
Collaborator Author

Just to note that the example above pns.lh works fine after Rvcg commit: zarquon42b/Rvcg@63329d0

@jefferis
Copy link
Collaborator Author

jefferis commented Aug 31, 2017

Could also add a method for ashape3d objects:

contains_points.ashape3d<-function(obj, points,  ...) {
  alphashape3d::inashape3d(obj, points=xyzmatrix(points), ...)
}

@jefferis
Copy link
Collaborator Author

jefferis commented Oct 6, 2017

contains_points.mesh3d <- function(obj, points,  ...) {
  xyz=xyzmatrix(points)
  inbb=contains_points(boundingbox(obj), xyz, ...)
  iosurf=pointsinside(xyz[inbb,,drop=F], surf = obj, ...)
  res=inbb
  res[inbb]=iosurf
  res
}

@jefferis
Copy link
Collaborator Author

@jefferis
Copy link
Collaborator Author

@fmlove this issue will be of interest

@jefferis
Copy link
Collaborator Author

Have to decided to merge to master as is (i.e. 0cc65c0). This may not be the last word, but it does seem to solve the majority of issues in the wild including the issues faced by @fmlove.

jefferis added a commit that referenced this issue May 21, 2018
* a good start at #353
* feature/improve-pointsinside:
  Document new pointsinside behaviour
  Initial work accelerating/hardening pointsinside
@jefferis
Copy link
Collaborator Author

jefferis commented Oct 5, 2019

closed by 3362ad8

@jefferis jefferis closed this as completed Oct 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant