# Mesh From Contours

**URL:** https://discourse.vtk.org/t/mesh-from-contours/896
**Category:** Support
**Created:** [May 3, 2019, 8:13am UTC](https://discourse.vtk.org/t/mesh-from-contours/896 "2019-05-03T08:13:10Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![medicalus](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/m/b3f665/32.png) [@medicalus](https://discourse.vtk.org/u/medicalus)
#### Post date: [May 3, 2019, 8:13am UTC](https://discourse.vtk.org/t/mesh-from-contours/896/1 "2019-05-03T08:13:10Z")

</div>

Hi Guys,  
I have a question regarding the algorithm from vtk to use for creating a mesh out of contours I have. The contours are not necessarily parallel and the structure is a vessel with one/two branches. What is the good way to convert this contour set to a mesh in VTK/ITK?  
Thanks

---

<div class="post-metadata">

### Author: ![marcomusy](https://discourse.vtk.org/user_avatar/discourse.vtk.org/marcomusy/32/95_2.png) [@marcomusy](https://discourse.vtk.org/u/marcomusy)
#### Post date: [May 5, 2019, 12:10am UTC](https://discourse.vtk.org/t/mesh-from-contours/896/2 "2019-05-05T00:10:13Z")

</div>

Maybe the [vtkRuledSurfaceFilter](https://vtk.org/doc/nightly/html/classvtkRuledSurfaceFilter.html#details) is what you are looking for.  
An example [here](https://lorensen.github.io/VTKExamples/site/Python/PolyData/RuledSurfaceFilter/).

---

<div class="post-metadata">

### Author: ![medicalus](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/m/b3f665/32.png) [@medicalus](https://discourse.vtk.org/u/medicalus)
#### Post date: [May 6, 2019, 10:19am UTC](https://discourse.vtk.org/t/mesh-from-contours/896/3 "2019-05-06T10:19:58Z")

</div>

Marco, thanks for the suggestions. I looked into the doc and can not see if it supports bifurcations. Do you know if it does? Thanks.

---

<div class="post-metadata">

### Author: ![marcomusy](https://discourse.vtk.org/user_avatar/discourse.vtk.org/marcomusy/32/95_2.png) [@marcomusy](https://discourse.vtk.org/u/marcomusy)
#### Post date: [May 6, 2019, 10:24am UTC](https://discourse.vtk.org/t/mesh-from-contours/896/4 "2019-05-06T10:24:30Z")

</div>

i’m not 100% sure but I suspect that it will try to link the last point of one bifurcation to the first of the second.

---

<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: [May 6, 2019, 12:57pm UTC](https://discourse.vtk.org/t/mesh-from-contours/896/5 "2019-05-06T12:57:49Z")

</div>

If you only have problem with branching, you can combine multiple meshes of single tubes using Boolean mesh operations. Boolean mesh filters (vtkBooleanOperationPolyDataFilter and related filter) in VTK are broken (often generate invalid results or crash for valid inputs), but you can always convert meshes to binary volumes, combine the volumes, and convert back to surface mesh. The drawback is that you may need very high resolution volume, lots of memory, and computation to minimize changes in the original mesh geometry.

[Planar contours to closed surface converter](https://github.com/SlicerRt/SlicerRT/blob/master/DicomRtImportExport/ConversionRules/vtkPlanarContourToClosedSurfaceConversionRule.cxx#L118) in [3D Slicer](https://www.slicer.org/)’s [SlicerRT extension](http://www.slicerrt.org) preserves all original contour points, can handle keyholes, branching, merging, provides smooth end-capping, and it is tested with a large number of data sets. We developed it for parallel contours but with some minor modifications it would probably work for slightly non-parallel contours, too.

Since reconstruction of closed surface from contours is an extremely difficult problem, you may consider alternative approaches that avoid this. For example, if your input is a 3D volume then you may generate surface directly from the volume (after optional vessel enhancement or segmentation steps) with simpler and more robust methods.

---

<div class="post-metadata">

### Author: ![medicalus](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/m/b3f665/32.png) [@medicalus](https://discourse.vtk.org/u/medicalus)
#### Post date: [May 8, 2019, 3:32am UTC](https://discourse.vtk.org/t/mesh-from-contours/896/6 "2019-05-08T03:32:50Z")

</div>

Hi Andras,  
Thanks for the code and the explanation, I will try with the tools you mentioned to see if I can get good results.  
Thanks!

---

<div class="post-metadata">

### Author: ![zhang-qiang-github](https://discourse.vtk.org/user_avatar/discourse.vtk.org/zhang-qiang-github/32/2519_2.png) [@zhang-qiang-github](https://discourse.vtk.org/u/zhang-qiang-github)
#### Post date: [October 7, 2019, 3:38am UTC](https://discourse.vtk.org/t/mesh-from-contours/896/7 "2019-10-07T03:38:57Z")

</div>

Have you resolve the problem? I meet the same requirement. Could you please share your code? Thank you very much!
