# Preparing a surface for meshing

**URL:** <https://discourse.slicer.org/t/preparing-a-surface-for-meshing/35794>\
**Category:** VMTK\
**Created:** [April 29, 2024, 12:12pm UTC](https://discourse.slicer.org/t/preparing-a-surface-for-meshing/35794 "2024-04-29T12:12:42Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![benzwick](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/benzwick/32/80521_2.png) [@benzwick](https://discourse.slicer.org/u/benzwick)\
**Post date:** [April 29, 2024, 12:12pm UTC](https://discourse.slicer.org/t/preparing-a-surface-for-meshing/35794/1 "2024-04-29T12:12:43Z")

</div>

I am trying to prepare a surface mesh for use in a simulation. I need a surface with open ends that are perpendicular to the centerlines of the vessels.

I have a segmentation that looks like this:

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/9/6/96b010c798a1e3e0fba3010af32b022b9472cf89.jpeg)

I would like to cut the ends normal to the centrelines to obtain a model with open ends similar to this:

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/9/6/96d04918b64fea8009d01d22d55a7e14a75aefc2.jpeg)

Is it possible to do this using VMTK within 3D Slicer?

---

<div class="post-metadata">

**Author:** ![mikebind](https://avatars.discourse-cdn.com/v4/letter/m/71e660/32.png) [@mikebind](https://discourse.slicer.org/u/mikebind)\
**Post date:** [April 29, 2024, 7:12pm UTC](https://discourse.slicer.org/t/preparing-a-surface-for-meshing/35794/2 "2024-04-29T19:12:29Z")

</div>

Sounds like this might be helpful: [Vmtk surface clipping contribution](https://discourse.slicer.org/t/vmtk-surface-clipping-contribution/30456/1)

---

<div class="post-metadata">

**Author:** ![benzwick](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/benzwick/32/80521_2.png) [@benzwick](https://discourse.slicer.org/u/benzwick)\
**Post date:** [April 30, 2024, 5:34am UTC](https://discourse.slicer.org/t/preparing-a-surface-for-meshing/35794/3 "2024-04-30T05:34:52Z")

</div>

Thank you, this is exactly what I was looking for. I can get it to work when the vessels attached to the aneurysm are relatively long.

 ![clip-vessel-long](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/f/1/f11710c380fd48183e1049a9319bf21b52f87922.png)

However, if I try to shorten the segments as required for our analysis the top of the aneurysm gets clipped as well. Is there any way to avoid this?

 ![clip-vessel-short](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/b/2/b274d857a7c82ec8cd48fd8d25adcb74dbc4b14b.png)

---

<div class="post-metadata">

**Author:** ![DavidM](https://avatars.discourse-cdn.com/v4/letter/d/71e660/32.png) [@DavidM](https://discourse.slicer.org/u/DavidM)\
**Post date:** [April 30, 2024, 1:23pm UTC](https://discourse.slicer.org/t/preparing-a-surface-for-meshing/35794/4 "2024-04-30T13:23:38Z")

</div>

The issue here is that there is no centerline associated with the aneurysm so the logic does not recognize it as a separate region and hence exclude it from the clipping. It may work if you are able to add a centerline to the tip of the aneurysm. Otherwise I think you will have to clip it above the aneurysm.

---

<div class="post-metadata">

**Author:** ![benzwick](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/benzwick/32/80521_2.png) [@benzwick](https://discourse.slicer.org/u/benzwick)\
**Post date:** [April 30, 2024, 4:23pm UTC](https://discourse.slicer.org/t/preparing-a-surface-for-meshing/35794/5 "2024-04-30T16:23:33Z")

</div>

Thanks @DavidM I got it to work by adding a few centerlines within the aneurysm.

 ![clip-vessel-short-more-centerlines](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/6/b/6b3a2389b3e90affccb8bd10e7486b3e96406687.png)

---

<div class="post-metadata">

**Author:** ![benzwick](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/benzwick/32/80521_2.png) [@benzwick](https://discourse.slicer.org/u/benzwick)\
**Post date:** [May 1, 2024, 6:07am UTC](https://discourse.slicer.org/t/preparing-a-surface-for-meshing/35794/6 "2024-05-01T06:07:04Z")

</div>

Are there any examples for how to use VMTK scripts from within 3D Slicer?

For example, I would like to do the following after I clip the geometry:

```bash
vmtksurfacenormals -ifile "../processed NRRDs/artery_cut_remesh_clip.stl" -ofile "artery_cut_remesh_clip_vmtksurfacenormals.stl" \
  --pipe vmtksurfaceremeshing -elementsizemode edgelength -edgelength 0.3 -ofile "artery_cut_remesh_clip_vmtksurfacenormals_remesh.stl"

```

The reason for computing the surface normals is that the normals on the extrusions were in the opposite direction to those on the artery and aneurysm wall which causes problems when trying to create a volume mesh.

---

<div class="post-metadata">

**Author:** ![mikebind](https://avatars.discourse-cdn.com/v4/letter/m/71e660/32.png) [@mikebind](https://discourse.slicer.org/u/mikebind)\
**Post date:** [May 2, 2024, 4:53pm UTC](https://discourse.slicer.org/t/preparing-a-surface-for-meshing/35794/7 "2024-05-02T16:53:08Z")

</div>

The VMTK extension for Slicer ([https://github.com/vmtk/SlicerExtension-VMTK](https://github.com/vmtk/SlicerExtension-VMTK)) has several examples of using VMTK features from python. For example, [https://github.com/vmtk/SlicerExtension-VMTK/blob/master/ExtractCenterline/ExtractCenterline.py](https://github.com/vmtk/SlicerExtension-VMTK/blob/master/ExtractCenterline/ExtractCenterline.py) shows how to extract a centerline using VMTK and is a python module. It will take a little work to unpack the code there, but it and the other modules of the VMTK Slicer extension are definitely working examples you could start from. Perhaps there are other more straightforward resources that others could point you to.
