# All discussions to do with vtkClipDataSet, vtkCookieCutter, vtkCell::Clip, vtkCell::CookieCut(?)

**URL:** https://discourse.vtk.org/t/all-discussions-to-do-with-vtkclipdataset-vtkcookiecutter-vtkcell-clip-vtkcell-cookiecut/5421
**Category:** Development
**Tags:** proposal
**Created:** [March 22, 2021, 3:25pm UTC](https://discourse.vtk.org/t/all-discussions-to-do-with-vtkclipdataset-vtkcookiecutter-vtkcell-clip-vtkcell-cookiecut/5421 "2021-03-22T15:25:56Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![jaswantp](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jaswantp/32/10046_2.png) [@jaswantp](https://discourse.vtk.org/u/jaswantp)
#### Post date: [March 22, 2021, 3:25pm UTC](https://discourse.vtk.org/t/all-discussions-to-do-with-vtkclipdataset-vtkcookiecutter-vtkcell-clip-vtkcell-cookiecut/5421/1 "2021-03-22T15:25:56Z")

</div>

@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** :

1. Scalar-based: `vtkClipPolyData` can be used to clip 2D cells. This is scalar based clipping.
2. Geometric-based (precise intersections): `vtkCookieCutter` works alright. (cannot produce inverted output)

**Current state of 3D boolean ops in VTK** :

1. Scalar-based: At the moment, `vtkClipDataSet` seems to be the only filter that clips 3D cells.
2. Geometric-based: For simple surface booleans, [vtkBooleanPolyDataFilter](https://vtk.org/doc/nightly/html/classvtkBooleanOperationPolyDataFilter.html) 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`](https://vtk.org/doc/nightly/html/classvtkCookieCutter.html) with an ability to invert the cutting operation soon evolved to a side project [discourse](https://discourse.vtk.org/t/2d-surface-cutter-development/4481), [github](https://github.com/jaswantp/SurfaceCutter) 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](https://gitlab.kitware.com/vtk/vtk/-/merge_requests/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?

_Poll ([view on site](https://discourse.vtk.org/t/all-discussions-to-do-with-vtkclipdataset-vtkcookiecutter-vtkcell-clip-vtkcell-cookiecut/5421/1))_

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.
