# Merging points of neighbour cells with vtkCleanPolyData

**URL:** https://discourse.vtk.org/t/merging-points-of-neighbour-cells-with-vtkcleanpolydata/6782
**Category:** Support
**Created:** [October 8, 2021, 8:00am UTC](https://discourse.vtk.org/t/merging-points-of-neighbour-cells-with-vtkcleanpolydata/6782 "2021-10-08T08:00:03Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![Martin3d](https://discourse.vtk.org/user_avatar/discourse.vtk.org/martin3d/32/4303_2.png) [@Martin3d](https://discourse.vtk.org/u/Martin3d)
#### Post date: [October 8, 2021, 8:00am UTC](https://discourse.vtk.org/t/merging-points-of-neighbour-cells-with-vtkcleanpolydata/6782/1 "2021-10-08T08:00:03Z")

</div>

Hi,

I wish to extract the outer surface of a shape made of hexahedron. [vtkGeometryFilter unfortunately can’t do it because these hexahedron are not sharing points](https://discourse.vtk.org/t/vtkgeometryfilter-and-its-evil-spawn-vtkdatasetsurfacefilter/4083/4).

 ![Capture d’écran 2021-10-08 à 09.55.45](https://discourse.vtk.org/uploads/default/original/2X/5/58e9e6a1e785e792d9ea63ddac8cd45dcf2472d6.png)

@will.schroeder suggested to use vtkCleanPolyData : [PointMergingOn setting](https://vtk.org/doc/nightly/html/classvtkCleanPolyData.html#a36ac9703ea2e6ad9cec5e84d56d26d22) enabling [vtkMergePoints](https://vtk.org/doc/nightly/html/classvtkMergePoints.html) is exactly what I need.

Unfortunately the algorithm destroy my polygons as shown on the right side picture, despite defining a 0 tolerance to only merge points that are equal (left part highlight all points that appear more than once in the whole piece, which proves all these hexahedron are all disconnected).

 ![Capture d’écran 2021-10-08 à 09.35.23](https://discourse.vtk.org/uploads/default/original/2X/c/cbbb237af7e577e0d778ebc02afda46bd0d87b03.jpeg)

Defining tolerance as absolute produce another kind of monster where all hexahedron faces turn to triangle instead of quads, despite all degenerate geometry transformation are forbidden by settings.

 ![Capture d’écran 2021-10-08 à 09.48.24](https://discourse.vtk.org/uploads/default/original/2X/2/290736810ab3766702a9fe4aebbf450cc4c83382.png)

I think I enabled the settings as suggested by the algorithm documentation :

```auto
// This is supposed to filter outer surface, but actually does not filter 
// anything when input is made of hexahedron with non merged points but
// converts source to polygons, which is our goal here
convertToPoly = new vtkGeometryFilter();
convertToPoly.SetInputConnection(output);

// This will merge doublon points only if their coordinates exactly match
cleanPolyData = new vtkCleanPolyData();
cleanPolyData.SetInputConnection(convertToPoly.GetOutputPort());
cleanPolyData.SetTolerance(0.0);
cleanPolyData.ToleranceIsAbsoluteOff(); // relative to bounding box

cleanPolyData.PointMergingOn();

cleanPolyData.ConvertLinesToPointsOff();
cleanPolyData.ConvertPolysToLinesOff();
cleanPolyData.ConvertStripsToPolysOff();

```

I should mention I am working with VTK Java Wrapper and that rendering is performed with JOGL on MacOS instead of VTK (because [VTK rendering crashes in this case](https://discourse.vtk.org/t/simplevtk-java-example-crashing-on-macos)).

Would anyone suggest a better setting or algorithm to merge points that are duplicated?

Thanks!
