# Combine two surface meshes and stitch edges

**URL:** <https://discourse.slicer.org/t/combine-two-surface-meshes-and-stitch-edges/39467>\
**Category:** Development\
**Created:** [October 1, 2024, 8:45am UTC](https://discourse.slicer.org/t/combine-two-surface-meshes-and-stitch-edges/39467 "2024-10-01T08:45:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![darabi](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/darabi/32/66736_2.png) [@darabi](https://discourse.slicer.org/u/darabi)\
**Post date:** [October 1, 2024, 8:45am UTC](https://discourse.slicer.org/t/combine-two-surface-meshes-and-stitch-edges/39467/1 "2024-10-01T08:45:29Z")

</div>

Hello,  
I have two surfaces which are generated with a 3D scanner and registered using Fiducial Registration. Irrelevant parts of the scan are removed after registration by cutting along a manually placed curve on the surface of the two models.

Now, I would like to combine the two surfaces into a closed surface, by filling the holes which are created inevitably as the cut curves along the two different surfaces will always have some displacement.

I have tried ‘Combine Models’ but it ends with ‘[VTK] Contact ends suddenly.’ without creating a result for which I found this vtkbool issue: [Difference of meshes sometimes an empty mesh · Issue #40 · zippy84/vtkbool · GitHub](https://github.com/zippy84/vtkbool/issues/40).

I hope that there is a way to achieve this without manual intervention as it is one step in a series of operations which are automated in a custom extension.

In the following screenshot, the blue and yellow surfaces are separated by gaps on the left side while they intersect on the right side:

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/c/a/ca3c1b877dab12f6dc6957140ac40fb34d83a195.jpeg)

Thank you

Kambiz

---

<div class="post-metadata">

**Author:** ![cpinter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/cpinter/32/7995_2.png) [@cpinter](https://discourse.slicer.org/u/cpinter)\
**Post date:** [October 1, 2024, 8:55am UTC](https://discourse.slicer.org/t/combine-two-surface-meshes-and-stitch-edges/39467/2 "2024-10-01T08:55:34Z")

</div>

It would be extremely difficult to automatically stitch the two surface patches correctly. I handle similar situations by voxelizing the appended mesh using a grid where the sampling direction is set such that it does not “flow out”, i.e. the sampling lines likely do not meet a hole between the patches. What this means is that I 1) append the meshes, 2) create a segmentation and set a reference geometry according to the desired voxelization directions, 3) import the mesh, 4) convert to binary labelmap representation.

---

<div class="post-metadata">

**Author:** ![JASON](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jason/32/13419_2.png) [@JASON](https://discourse.slicer.org/u/JASON)\
**Post date:** [October 2, 2024, 2:40am UTC](https://discourse.slicer.org/t/combine-two-surface-meshes-and-stitch-edges/39467/3 "2024-10-02T02:40:15Z")

</div>

You could try making a pointcloud from the vertices of both meshes and then mesh the pointcloud using something like this :

[https://examples.vtk.org/site/Cxx/Points/CompareExtractSurface/](https://examples.vtk.org/site/Cxx/Points/CompareExtractSurface/)
