vtkClipClosedSurface bad result

Hi friends,

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 :slight_smile:

PS : I’ve tested the VTP with FeatureEdges to see if my geometry is OK, and this is the case.

Result is OK

Result is bad

clip ko.vtp (18.5 KB)

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.

Much more simple sample that exhibits the same behavior.

clip 2.vtp (3.4 KB)

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 :wink:
Above trick (offaxis) doesn’t work for that one.
But I guess the problem comes from vtkContourTriangulator …

clip 3.vtp (284.1 KB)

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.

Ok David.
In my spare time maybe I’ll make a ProgrammableFilter which leverage another tessellator.
Thanks for you help.