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

ENH: spatial: implement alpha shapes #11502

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
Draft

ENH: spatial: implement alpha shapes #11502

wants to merge 12 commits into from

Conversation

pmla
Copy link
Contributor

@pmla pmla commented Feb 12, 2020

What does this implement/fix?

This implements alpha shapes in the scipy.spatial module.
https://en.wikipedia.org/wiki/Alpha_shape

Most of the work is done by the Delaunay class. The main additions are a stable calculation of the simplex circumcenters and calculation of the alpha intervals in which a facet is on the surface. The approach I have taken is to do the hard work once (calculation of circumradii and alpha intervals) which makes it cheap to test different alpha thresholds.

I would like to add a connected component analysis, so that a suitable alpha value can be chosen automagically, but this requires a fast disjoint-set data structure. We don't appear to have one in scipy. I can't find any reference to it on the SciPy github page or on the mailing list. Does anyone know if this has been discussed previously?
Edit: I have added a disjoint set data structure in cython. I might move more of the _calculate_connectivity_thresholds function into the cython module to get better performance.

Additional information

This PR is WIP for the purpose of collecting feedback. Comments are very welcome.

@tylerjereddy tylerjereddy added enhancement A new feature or improvement scipy.spatial labels Feb 12, 2020
@tylerjereddy
Copy link
Contributor

Cool, it may take me a bit to get around to reviewing this. I think I still need to go back to some of your previous enhancement PRs.

@pmla
Copy link
Contributor Author

pmla commented Oct 1, 2020

@tylerjereddy this needs some more work before it is ready for review.

I can now use the DisjointSet structure in scipy.cluster.hierarchy which will make the changeset here a lot smaller. Looking over it again it could use some polish too.

@ilayn ilayn marked this pull request as draft October 2, 2020 09:50
@ilayn
Copy link
Member

ilayn commented Oct 2, 2020

I like this draft mode so converted to it but feel free to dismiss it


# solve stack of linear systems of equations with `pinv` (`rcond` handles
# rank-deficient simplices).
Ainv = np.linalg.pinv(A, rcond=rcond)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ilayn I'm using pinv to solve a stack of least-squares problems. Is there a better way? I would use lstsq but it doesn't support stacks and looping is too slow.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For now, I guess we have to live with it. pinv uses SVD so I am surprised that loop is slower. But it is what it is I guess.

@lucascolley lucascolley changed the title WIP: alpha shapes ENH: spatial: alpha shapes Mar 14, 2024
@lucascolley lucascolley changed the title ENH: spatial: alpha shapes ENH: spatial: implement alpha shapes Mar 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement A new feature or improvement scipy.spatial
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants