Detection of self intersection for pyvista.polydata type
See original GitHub issueHello everyone. Some time ago, I was generating new shapes (non-closed 3d surfaces) through a statistical shape model (SSM). Sometimes the SSM was giving shapes that self-intersected. By self-intersection, I mean when some part of the surface touches another part of the surface of the same pyvista.Polydata. I have attached an image to be as clear as possible.
I could not find any solution online to detect this kind of problem. The (not very robust) solution I came up with is to generate an inflated version of the same surface and then run the pyvista.Polydata.intersection()
method to check if the two shapes intersect. This is the implementation:
def check_self_intersections(mesh_orig):
mesh_inflated = mesh_orig.copy()
mesh_inflated = mesh_inflated.compute_normals(
consistent_normals=True,
cell_normals=False,
split_vertices=True
)
mesh_inflated.points = mesh_inflated.points + mesh_inflated['Normals']*1.
intersection = mesh_orig.intersection(mesh_inflated)
return intersection[0].n_points
The problems with this solution are multiple:
- VTK does not seem to like when
intersection
has zero points, i.e., the mesh does not intersect. In fact, some warning is always launched in the background; intersection
can have a small number of points even if there are no intersections. In fact, I check for self-intersections by asserting thatintersection.n_points < THRESHOLD_VALUE
.
I would like to know if there are some better solutions to the problem and, in that case, create a pull request with this feature.
Thanks everyone!
Issue Analytics
- State:
- Created 2 years ago
- Comments:13 (5 by maintainers)
Top GitHub Comments
Ok, thank you very much. I will look into these in these days. As soon as I come up with something I will update this issue. Thanks !!
yes, this is it
and it is used simply like this
check_intersections(surfaceMesh)
wheresurfaceMesh
is a polydata object.Probably the implementation is not very clear, so for any doubt ask me anything. I am also open to any suggestion / modification.
Thanks for your interest