# Extract closed Surface or Generate 3D mesh or volume from two non-closed surface

**URL:** https://discourse.vtk.org/t/extract-closed-surface-or-generate-3d-mesh-or-volume-from-two-non-closed-surface/3016
**Category:** Support
**Created:** [April 10, 2020, 8:28am UTC](https://discourse.vtk.org/t/extract-closed-surface-or-generate-3d-mesh-or-volume-from-two-non-closed-surface/3016 "2020-04-10T08:28:32Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![rezaramdhan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/rezaramdhan/32/3335_2.png) [@rezaramdhan](https://discourse.vtk.org/u/rezaramdhan)
#### Post date: [April 10, 2020, 8:28am UTC](https://discourse.vtk.org/t/extract-closed-surface-or-generate-3d-mesh-or-volume-from-two-non-closed-surface/3016/1 "2020-04-10T08:28:32Z")

</div>

Hi Fellas,

I am currently developing a tool to create a 3D mesh or volume from two non-closed surface using vtk.

For illustration: Imagine a Digital Elevation Model (surface model) that lies on top of another DEM with a vertical distance between them (the first has an average altitude of 200 m, and the second is 100 m above sea level).

The problem is, I was successfully visualize both surfaces using vtkDelaunay2D (input file XYZ points), but I had a problem when i am going to fill (or close) the space between them, since I need to get a closed surface (or volume).

I have tried using vtkExtractSurface, vtkDelaunay3D, and vtkUnstructuredGridVolumeRayCastMapper, unfortunately non of them give a decent result.

Do you guys have a suggestion which vtk filter fits best for my case? Any suggestion will be very helpful.

 ![Capture.PNG](https://discourse.vtk.org/uploads/default/original/2X/1/1fcaa03421d4ad7093120e1531443876c7109b40.jpeg)

---

<div class="post-metadata">

### Author: ![banesullivan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/banesullivan/32/7143_2.png) [@banesullivan](https://discourse.vtk.org/u/banesullivan)
#### Post date: [April 13, 2020, 1:52pm UTC](https://discourse.vtk.org/t/extract-closed-surface-or-generate-3d-mesh-or-volume-from-two-non-closed-surface/3016/2 "2020-04-13T13:52:17Z")

</div>

This is definitely non-trivial. In order to make a 3D volumetric mesh, you’ll first need to create a closed, manifold surface from the two surfaces you have. To create the closed surface, there are tons of techniques, but perhaps you could try using the `vtkLinearExtrusionFilter` to extrude one surface, clip that mesh by the other surface, clean the resulting mesh, and try a meshing algorithm like vtkDelaunay3D or [PyVista’s wrapper of TetGen](https://tetgen.pyvista.org) on the closed surface.

Or you could use both surfaces to clip something like an imagedata mesh that shares the same extent and use that result as the full 3D mesh?

Lots of creative ways to go about this but its definitely difficult to find a methodology that you can rely on working regardless of inputs - in my experience, your routine will have to make assumptions about the input meshes.

---

<div class="post-metadata">

### Author: ![rezaramdhan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/rezaramdhan/32/3335_2.png) [@rezaramdhan](https://discourse.vtk.org/u/rezaramdhan)
#### Post date: [April 14, 2020, 1:43pm UTC](https://discourse.vtk.org/t/extract-closed-surface-or-generate-3d-mesh-or-volume-from-two-non-closed-surface/3016/3 "2020-04-14T13:43:40Z")

</div>

Hi Bane,

Thanks a lot for your advice. That is really helpful.

Now I can build a 3D mesh by extruding the upper surface using **vtkLinearExtrusionFilter**. I also have managed to clip the mesh with a plane simply by using **vtkClipClosedSurface** (though that is not what I need).

However, it always failed when turns to the clipping the 3D mesh using the surface underneath, I have also tried to use **vtkClipPolyData** but neither giving an expected result.

Do you think those methods could do the task with surface / delaunay2D as an input? Or do I need another method/filter type?

 ![Capture1.PNG](https://discourse.vtk.org/uploads/default/original/2X/7/7a0d8a2ebb7aba67f29b90f85c52bda00d67a11a.jpeg)

---

<div class="post-metadata">

### Author: ![Altertango](https://discourse.vtk.org/user_avatar/discourse.vtk.org/altertango/32/4491_2.png) [@Altertango](https://discourse.vtk.org/u/Altertango)
#### Post date: [January 7, 2022, 1:52pm UTC](https://discourse.vtk.org/t/extract-closed-surface-or-generate-3d-mesh-or-volume-from-two-non-closed-surface/3016/4 "2022-01-07T13:52:49Z")

</div>

Hi @rezaramdhan, I’ve run into the same problem, did you managed to create this tool in the end?

Cheers,  
Ignacio

---

<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 8, 2022, 5:12pm UTC](https://discourse.vtk.org/t/extract-closed-surface-or-generate-3d-mesh-or-volume-from-two-non-closed-surface/3016/5 "2022-01-08T17:12:39Z")

</div>

For Boolean operation between meshes, [vtkbool](https://github.com/zippy84/vtkbool) library works quite well.

---

<div class="post-metadata">

### Author: ![Altertango](https://discourse.vtk.org/user_avatar/discourse.vtk.org/altertango/32/4491_2.png) [@Altertango](https://discourse.vtk.org/u/Altertango)
#### Post date: [January 11, 2022, 9:26am UTC](https://discourse.vtk.org/t/extract-closed-surface-or-generate-3d-mesh-or-volume-from-two-non-closed-surface/3016/6 "2022-01-11T09:26:25Z")

</div>

Woah ! Thanks, looks very promising. I was just searching from the official documentation.

Cheers

---

<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: [January 23, 2024, 1:11pm UTC](https://discourse.vtk.org/t/extract-closed-surface-or-generate-3d-mesh-or-volume-from-two-non-closed-surface/3016/7 "2024-01-23T13:11:43Z")

</div>

@Charles_Gueunet

---

<div class="post-metadata">

### Author: ![Charles\_Gueunet](https://discourse.vtk.org/user_avatar/discourse.vtk.org/charles_gueunet/32/239_2.png) [@Charles\_Gueunet](https://discourse.vtk.org/u/Charles_Gueunet)
#### Post date: [January 23, 2024, 2:15pm UTC](https://discourse.vtk.org/t/extract-closed-surface-or-generate-3d-mesh-or-volume-from-two-non-closed-surface/3016/8 "2024-01-23T14:15:00Z")

</div>

If the goal is to keep as much of the original mesh as possible, an approach based linear extrusion + boolean operation may be envisaged. In addition to vtkbool, we can also mention [vespa](https://gitlab.kitware.com/vtk/meshing/vespa). Based on CGAL, it provides with boolean operation, and useful remeshing algorithms.

Best,  
Charles

---

<div class="post-metadata">

### Author: ![Altertango](https://discourse.vtk.org/user_avatar/discourse.vtk.org/altertango/32/4491_2.png) [@Altertango](https://discourse.vtk.org/u/Altertango)
#### Post date: [January 23, 2024, 2:39pm UTC](https://discourse.vtk.org/t/extract-closed-surface-or-generate-3d-mesh-or-volume-from-two-non-closed-surface/3016/9 "2024-01-23T14:39:34Z")

</div>

Thanks, in the end I used a script to simply project one mesh of triangles in the other mesh to get the volume between two topographies. I used locator.IntersectWithLine to intersect a vertical line with the other topography and then calculated the volume between each triangle of the first mesh and the newly created triangles resulting from those intersections. I found it to be the most simple way to do it using the tools I already knew. The only problem is that for very dens meshes this can get very long. So I created a tool to make a XY discretization of both surfaces to limit the amount of vertices. Of course, since im dealing with approximate values, the error in the discretization process is negligible, but might be a deal breaker for others.

---

<div class="post-metadata">

### Author: ![will.schroeder](https://discourse.vtk.org/user_avatar/discourse.vtk.org/will.schroeder/32/233_2.png) [@will.schroeder](https://discourse.vtk.org/u/will.schroeder)
#### Post date: [January 23, 2024, 3:33pm UTC](https://discourse.vtk.org/t/extract-closed-surface-or-generate-3d-mesh-or-volume-from-two-non-closed-surface/3016/10 "2024-01-23T15:33:38Z")

</div>

One thing that might be worth trying, and I’m not sure this is going to work, but it’s quick, is to use vtkRuledSurfaceFilter (with CloseSurface enabled).

Here’s how. Assuming each “DEM” surface is manifold (no holes etc) then if you extract the boundary edges (vtkFeatureEdges) and link them into a single continuous loop (might need vtkStripper), and you do this for each of the two surfaces, you end up with two loops. The vtkRuledSurfaceFilter then may be able to create a “skirt” that connects the two surfaces.
