# cap a vtkClipPolyData does not work propertly. Weird behaviour

**URL:** https://discourse.vtk.org/t/cap-a-vtkclippolydata-does-not-work-propertly-weird-behaviour/2655
**Category:** Support
**Created:** [February 19, 2020, 12:02pm UTC](https://discourse.vtk.org/t/cap-a-vtkclippolydata-does-not-work-propertly-weird-behaviour/2655 "2020-02-19T12:02:36Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![zandarina](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/z/4af34b/32.png) [@zandarina](https://discourse.vtk.org/u/zandarina)
#### Post date: [February 19, 2020, 12:02pm UTC](https://discourse.vtk.org/t/cap-a-vtkclippolydata-does-not-work-propertly-weird-behaviour/2655/1 "2020-02-19T12:02:36Z")

</div>

Hi i´d like to cap the parts i clip and i used the code of this example

[http://www.vtk.org/Wiki/VTK/Examples/Cxx/Meshes/CapClip](http://www.vtk.org/Wiki/VTK/Examples/Cxx/Meshes/CapClip)

And i also tried this:

```
		for (int i = 0; i < (int)clipFilters_.size(); i++) {

			clipFilters_[i]->SetClipFunction(boolean_opsEahcPlane[i]);
			clipFilters_[i]->InsideOutOn();
			clipFilters_[i]->Update();
			clipFilters_[i]->Modified();

		}
		

		// Now extract feature edges
		auto boundaryEdges = vtkSmartPointer<vtkFeatureEdges>::New();
		boundaryEdges->SetInputConnection(clipFilters_[clipFilters_.size() - 1]->GetOutputPort());
		boundaryEdges->BoundaryEdgesOn();
		boundaryEdges->FeatureEdgesOff();
		boundaryEdges->NonManifoldEdgesOff();
		boundaryEdges->ManifoldEdgesOff();

		auto boundaryStrips = vtkSmartPointer<vtkStripper>::New();
		boundaryStrips->SetInputConnection(boundaryEdges->GetOutputPort());
		boundaryStrips->Update();

		// Triangulate the polyline contour
		vtkSmartPointer<vtkContourTriangulator> triangulator =
			vtkSmartPointer<vtkContourTriangulator>::New();
		triangulator->SetInputConnection(boundaryStrips->GetOutputPort());
		triangulator->Update();

		vtkSmartPointer<vtkAppendPolyData> appendFilter =
			vtkSmartPointer<vtkAppendPolyData>::New();
		appendFilter->AddInputConnection(triangulator->GetOutputPort());
		appendFilter->AddInputConnection(clipFilters_[clipFilters_.size() - 1]->GetOutputPort());

		// Remove any duplicate points.
		vtkSmartPointer<vtkCleanPolyData> cleanFilter =
			vtkSmartPointer<vtkCleanPolyData>::New();
		cleanFilter->SetInputConnection(appendFilter->GetOutputPort());
		cleanFilter->Update();
		
		 
                    Actor->GetMapper()->SetInputConnection(cleanFilter->GetOutputPort());
		Actor->GetMapper()->Update();

```

but it does not work for me. I get a weird behaviour. Is there any other fiter to close the gaps or to clip with cap?. Thanks

 ![clip_empty](https://discourse.vtk.org/uploads/default/original/2X/b/b76b9e32d0315399a8ca8d378ca102f035478782.png)

![cap_clipping](https://discourse.vtk.org/uploads/default/original/2X/b/bf28114948eb527a74b232e62ddddedfa9a5e6d0.png)

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [February 26, 2020, 12:10pm UTC](https://discourse.vtk.org/t/cap-a-vtkclippolydata-does-not-work-propertly-weird-behaviour/2655/2 "2020-02-26T12:10:54Z")

</div>

Can you reduce de scene complexity? I mean, try to clip a simple triangulated sphere with your code and try to get the same unexpected behavior. The likelyhood of diagnosing bugs is far greater when we reproduce the problem with simpler data.

---

<div class="post-metadata">

### Author: ![Andrew](https://discourse.vtk.org/user_avatar/discourse.vtk.org/andrew/32/3861_2.png) [@Andrew](https://discourse.vtk.org/u/Andrew)
#### Post date: [February 27, 2020, 5:26am UTC](https://discourse.vtk.org/t/cap-a-vtkclippolydata-does-not-work-propertly-weird-behaviour/2655/3 "2020-02-27T05:26:38Z")

</div>

If you’re using a plane there is something specifically for closing while clipping. “[vtkClipClosedSurface](https://vtk.org/doc/nightly/html/classvtkClipClosedSurface.html#details)”. This requires manifold input (closed/watertight and non intersecting faces). It will also generate an open face if the normals or winding is backward. Use vtkReverseSense to fix that.

---

<div class="post-metadata">

### Author: ![zandarina](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/z/4af34b/32.png) [@zandarina](https://discourse.vtk.org/u/zandarina)
#### Post date: [March 5, 2020, 9:50am UTC](https://discourse.vtk.org/t/cap-a-vtkclippolydata-does-not-work-propertly-weird-behaviour/2655/4 "2020-03-05T09:50:00Z")

</div>

Sure, but i cannot always guarantee manifold input and I have boolean operations not only planes i also get weird results with vtkClipClosedSurface. I have solved it transforming to volume to close it. But it is slower.

Thanks for the suggestions
