@will.schroeder @Yohann_Bearzi
This post should serve as a central site for all ideas, opinions, suggestions, thoughts about the state of 2D and 3D boolean capabilities in the VTK library. Scalar-based clipping is great from the visualization-aspect but not when precise geometric cuts are absolutely necessary. Whether VTK should really support the latter is open to discussion.
Common terms:
Clipper: The polygon used to cut.
Subject: polygon that’s being cut by the clip poly.
InsideOut On: Output portions of subject poly inside clip polygon
InsideOut Off: Output portions of subject poly outside clip polygon
Current state of 2D boolean ops in VTK:
- Scalar-based:
vtkClipPolyData
can be used to clip 2D cells. This is scalar based clipping. - Geometric-based (precise intersections):
vtkCookieCutter
works alright. (cannot produce inverted output)
Current state of 3D boolean ops in VTK:
- Scalar-based: At the moment,
vtkClipDataSet
seems to be the only filter that clips 3D cells. - Geometric-based: For simple surface booleans, vtkBooleanPolyDataFilter should suffice. There are no implementations that deal with 3D cells.
vtkCookieCutter
subclasses vtkPolyDataAlgorithm
, it cannot be used to cut 3D cells.
There were two efforts to add the InsideOut
feature to 2D cutting in VTK. When cutting polygons with InsideOut = off
, vtkCookieCutter
's algorithm inherently cannot work for certain scenarios (some of the clip polygon’s points are exactly on subject polygon’s edge). Straightforward from code. So, I had to work from scratch.
New algo from scratch:
What started as a small project that innocently hoped to extend vtkCookieCutter
with an ability to invert the cutting operation soon evolved to a side project discourse, github where I explored and developed an alternative algorithm that does perfect(not kidding) 2D boolean operations only on triangles and no other polys.
Extend existing vtkCookieCutter
At the same time, just so I can say I tried and prove that it indeed doesn’t work for the scenarios I mentioned in the beginning, an extension to the existing vtkCookieCutter
algorithm that distinctly recognizes interior and exterior geometry (verts, lines, polys) to clipper polygons was developed. See #7656. Soon, I extended the vtkCell API with a new method vtkCell::CookieCut()
(with hope it can be implemented in non-linear cells and probably 3D cells too)
The new algorithm is precise while the extension isn’t. Where to go from here?
- Implement your new 2D perfect algorithm in
vtkTriangle::CookieCut()
. Let other polys triangulate themselves and call upon it. - Leave things as they are in MR #7656. Let each cell derive and implement a CookieCut() method.
- Please do not touch
vtkCell
and related API. Implement everything using switch-case to infer cell-type and use the appropriate algorithm withinvtkCookieCutter
. - Move the implementation into
vtkCell::Clip
with an optional argument to do geometric precision cuts or default to simple scalar-clip.
0 voters
There’s a severe restriction. Both the implementations only work in the plane Z=0
. I think this can be worked around.
Tbh, the 3rd option seems the easiest and most low-maintenance but will definitely limit re-usability if someone wants to use those algorithms elsewhere outside of vtkCookieCutter
. Also makes it a pain to implement a boolean op for 3D cells, where I’d expect to reuse the algorithm to cut faces of a 3D cell.