# clipping a polydata using the implicit of another polydata via vtkClipPolyData leads to a big hole on the cut side.

**URL:** https://discourse.vtk.org/t/clipping-a-polydata-using-the-implicit-of-another-polydata-via-vtkclippolydata-leads-to-a-big-hole-on-the-cut-side/7534
**Category:** Development
**Created:** [December 30, 2021, 3:46pm UTC](https://discourse.vtk.org/t/clipping-a-polydata-using-the-implicit-of-another-polydata-via-vtkclippolydata-leads-to-a-big-hole-on-the-cut-side/7534 "2021-12-30T15:46:57Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![aveek-brahmachari](https://discourse.vtk.org/user_avatar/discourse.vtk.org/aveek-brahmachari/32/4481_2.png) [@aveek-brahmachari](https://discourse.vtk.org/u/aveek-brahmachari)
#### Post date: [December 30, 2021, 3:46pm UTC](https://discourse.vtk.org/t/clipping-a-polydata-using-the-implicit-of-another-polydata-via-vtkclippolydata-leads-to-a-big-hole-on-the-cut-side/7534/1 "2021-12-30T15:46:58Z")

</div>

```auto
vtkSmartPointer<vtkPolyData> clipMesh (const vtkSmartPointer<vtkPolyData> &mesh1, const vtkSmartPointer<vtkPolyData> &mesh2) {

	vtkNew<vtkImplicitPolyDataDistance> implicit_distance_2;
	implicit_distance_2->SetInput(mesh2);

	vtkNew<vtkClipPolyData> clip;
	clip->SetInputData(mesh1);
	clip->SetClipFunction(implicit_distance_2);
	clip->Update();

	return clip->GetOutput();
}

```

I dont understand why the mesh returned has a no surface on the clipped side.  
Please let me know how I can improve this function to have a water tight mesh.

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mwestphal/32/19_2.png) [@mwestphal](https://discourse.vtk.org/u/mwestphal)
#### Post date: [December 30, 2021, 4:05pm UTC](https://discourse.vtk.org/t/clipping-a-polydata-using-the-implicit-of-another-polydata-via-vtkclippolydata-leads-to-a-big-hole-on-the-cut-side/7534/2 "2021-12-30T16:05:50Z")

</div>

use vtkClipClosedSurface instead.

---

<div class="post-metadata">

### Author: ![aveek-brahmachari](https://discourse.vtk.org/user_avatar/discourse.vtk.org/aveek-brahmachari/32/4481_2.png) [@aveek-brahmachari](https://discourse.vtk.org/u/aveek-brahmachari)
#### Post date: [December 30, 2021, 5:48pm UTC](https://discourse.vtk.org/t/clipping-a-polydata-using-the-implicit-of-another-polydata-via-vtkclippolydata-leads-to-a-big-hole-on-the-cut-side/7534/3 "2021-12-30T17:48:39Z")

</div>

vtkClipClosedSurface does not work with implicit functions as far as I have checked, they work with planes. If they do, please let me know how.

---

<div class="post-metadata">

### Author: ![mwestphal](https://discourse.vtk.org/user_avatar/discourse.vtk.org/mwestphal/32/19_2.png) [@mwestphal](https://discourse.vtk.org/u/mwestphal)
#### Post date: [December 31, 2021, 9:17am UTC](https://discourse.vtk.org/t/clipping-a-polydata-using-the-implicit-of-another-polydata-via-vtkclippolydata-leads-to-a-big-hole-on-the-cut-side/7534/4 "2021-12-31T09:17:16Z")

</div>

Indeed, then I think you need to work with a volumic dataset. Something like this would be costly but should work:

- Delaunay3D
- Clip with implicit Function
- ExtractSurface

---

<div class="post-metadata">

### Author: ![aveek-brahmachari](https://discourse.vtk.org/user_avatar/discourse.vtk.org/aveek-brahmachari/32/4481_2.png) [@aveek-brahmachari](https://discourse.vtk.org/u/aveek-brahmachari)
#### Post date: [December 31, 2021, 3:50pm UTC](https://discourse.vtk.org/t/clipping-a-polydata-using-the-implicit-of-another-polydata-via-vtkclippolydata-leads-to-a-big-hole-on-the-cut-side/7534/5 "2021-12-31T15:50:23Z")

</div>

Yes, I know the 3D method, but it would both be costly and inaccurate due to sampling or tolerance. The above method is too close to a fast and accurate result except that it is not closed. Since we are clipping at a point, we should be able to recover those points on the clipped side.

By the way, can you provide a code snippet for how exactly you propose to do this ?

---

<div class="post-metadata">

### Author: ![lassoan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lassoan/32/50_2.png) [@lassoan](https://discourse.vtk.org/u/lassoan)
#### Post date: [January 6, 2022, 6:49pm UTC](https://discourse.vtk.org/t/clipping-a-polydata-using-the-implicit-of-another-polydata-via-vtkclippolydata-leads-to-a-big-hole-on-the-cut-side/7534/6 "2022-01-06T18:49:22Z")

</div>

vtkImplicitPolyDataDistance is in the group of filters that have been added to VTK to implement Boolean operations on meshes. All these filters are broken in the sense that they randomly give incorrect output for completely valid inputs.

Intersection of polygonal meshes is an extremely complicated problem (practically unsolvable for arbitrarily complex meshes). If you don’t want to solve the problem in the image domain (convert to binary images, combine, and remesh) then the only robust implementation with non-restrictive license that I know of is [vtkbool](https://github.com/zippy84/vtkbool). Fortunately, it is VTK-based, so you can conveniently use it from VTK.

I hope that vtkbool will become part of VTK core or will be made available as a VTK remote module. Until then, if you don’t want to build it yourself then it is available 3D Slicer (with GUI or Python scripting) and in Paraview.

---

<div class="post-metadata">

### Author: ![aveek-brahmachari](https://discourse.vtk.org/user_avatar/discourse.vtk.org/aveek-brahmachari/32/4481_2.png) [@aveek-brahmachari](https://discourse.vtk.org/u/aveek-brahmachari)
#### Post date: [January 12, 2022, 6:12pm UTC](https://discourse.vtk.org/t/clipping-a-polydata-using-the-implicit-of-another-polydata-via-vtkclippolydata-leads-to-a-big-hole-on-the-cut-side/7534/7 "2022-01-12T18:12:00Z")

</div>

Thanks, I am aware of vtkbool and the complexities of mesh booleans. My question was specific to the code snippet I shared.

---

<div class="post-metadata">

### Author: ![cory.quammen](https://discourse.vtk.org/user_avatar/discourse.vtk.org/cory.quammen/32/6751_2.png) [@cory.quammen](https://discourse.vtk.org/u/cory.quammen)
#### Post date: [January 12, 2022, 7:33pm UTC](https://discourse.vtk.org/t/clipping-a-polydata-using-the-implicit-of-another-polydata-via-vtkclippolydata-leads-to-a-big-hole-on-the-cut-side/7534/8 "2022-01-12T19:33:48Z")

</div>

> [@lassoan](#):
>
> vtkImplicitPolyDataDistance is in the group of filters that have been added to VTK to implement Boolean operations on meshes. All these filters are broken in the sense that they randomly give incorrect output for completely valid inputs.

`vtkImplicitPolyDataDistance` is one of the more robust filters in the set. It isn’t doing any complex geometric cutting operations, so it shouldn’t fail as often as, say, the `vtkIntersectionPolyDataFilter`, which is performing the complex geometry cutting.

---

<div class="post-metadata">

### Author: ![cory.quammen](https://discourse.vtk.org/user_avatar/discourse.vtk.org/cory.quammen/32/6751_2.png) [@cory.quammen](https://discourse.vtk.org/u/cory.quammen)
#### Post date: [January 12, 2022, 7:34pm UTC](https://discourse.vtk.org/t/clipping-a-polydata-using-the-implicit-of-another-polydata-via-vtkclippolydata-leads-to-a-big-hole-on-the-cut-side/7534/9 "2022-01-12T19:34:28Z")

</div>

> [@aveek-brahmachari](#):
>
> I dont understand why the mesh returned has a no surface on the clipped side.

Invoke `clip->GenerateClippedOutputOn()` to produce a second output containing the clipped portion of the dataset.

---

<div class="post-metadata">

### Author: ![aveek-brahmachari](https://discourse.vtk.org/user_avatar/discourse.vtk.org/aveek-brahmachari/32/4481_2.png) [@aveek-brahmachari](https://discourse.vtk.org/u/aveek-brahmachari)
#### Post date: [January 12, 2022, 8:55pm UTC](https://discourse.vtk.org/t/clipping-a-polydata-using-the-implicit-of-another-polydata-via-vtkclippolydata-leads-to-a-big-hole-on-the-cut-side/7534/10 "2022-01-12T20:55:55Z")

</div>

I agree on your robustness remark on vtkImplicitPolyDataDistance.

We would need the clipped surface from the cutting mesh (can be done by reversing the order in the above function). In this case, the surfaces would be disjoint and the boundaries clipped would not come out perfect. Stitching would be non-trivial.

---

<div class="post-metadata">

### Author: ![cory.quammen](https://discourse.vtk.org/user_avatar/discourse.vtk.org/cory.quammen/32/6751_2.png) [@cory.quammen](https://discourse.vtk.org/u/cory.quammen)
#### Post date: [January 12, 2022, 9:30pm UTC](https://discourse.vtk.org/t/clipping-a-polydata-using-the-implicit-of-another-polydata-via-vtkclippolydata-leads-to-a-big-hole-on-the-cut-side/7534/11 "2022-01-12T21:30:24Z")

</div>

> [@aveek-brahmachari](#):
>
> We would need the clipped surface from the cutting mesh

Perhaps [`vtkImprintFilter`](https://vtk.org/doc/nightly/html/classvtkImprintFilter.html#details) would work better for your needs.
