I’m facing “many” bad results with capping done by vtkClipClosedSurface + vtkContourTriangulator …
vtkClipClosedSurface does a perfect job calculating the clipped triangles / lines, but capping is another story.
It seams that lines belonging to the capping plane are well calculated, but once passed to vtkContourTriangulator the result is often bad if the input is non convex and/or have nested holes.
I’ve attached a VTP to show the problem.
In Paraview, just have to add a “Clip Closed Surface” filter, put it on Z axis, and move it slowly
Any advice ?
Thanks
PS : I’ve tested the VTP with FeatureEdges to see if my geometry is OK, and this is the case.
Thanks for providing the file. Do you have any information about how this dataset was produced?
Interesting, if the clipping plane is off-axis (even by one part in a million), then the triangulation succeeds. After the polygons are generated by the cut, it definitely looks like some of the triangulator’s inside-outside checks are failing.
I’ve submitted patch !9695 to add a poly-in-poly tolerance that fixes vtkClipClosedSurface for these datasets.
As a work-around, I suggest that you avoid using a plane normal of (0.0, 0.0, 1.0), and instead use (1e-12, 1e-12, 1.0) which is far enough off-axis to avoid the bug in the code.
Thanks a lot for your quick and effective work !
The workaround works great for both samples.
Now, we can see with a more sophisticated one
Above trick (offaxis) doesn’t work for that one.
But I guess the problem comes from vtkContourTriangulator …
The failure on this one isn’t entirely the triangulator’s fault, it’s also due to the precision of the clipping.
To make a long story short, clipping is done by cutting each edge that is intersected by the clip plane, and the overall precision of this operation (as implemented) is approximately equal to the machine epsilon (around 1e-16) multiplied by the length of the edge. In this particular data set, the outer box has large triangles with long edges. So you get low precision when clipping these long edges, as compared to the fine detail of the implant, which causes triangulation artefacts. Tesselating the outer box with many small triangles might help.
This precision issue could possibly be solved by implementing an iterative algorithm for edge cutting instead of just using a geometrical equation (i.e. iterate until achieving the best result that is possible with double-precision values). Either that, or triangles with long edges could automatically be tesselated.
As an example of this precision issue, see !9696 which has a kludge for clip planes aligned with the x, y, or z axes. With this kludge, I’m able to clip your “clip 3.vtp” dataset along the Z axis without any artifacts.
Edit: after a little experimentation, it seems that improving the precision makes triangulation failures less common, but it definitely doesn’t eliminate them. A perfectly robust triangulator is probably the only solution.