# Meshing: Self-intersecting faces

**URL:** https://discourse.slicer.org/t/meshing-self-intersecting-faces/13588
**Category:** Support
**Tags:** segmentation, cleaver, meshing
**Created:** [September 21, 2020, 2:45pm UTC](https://discourse.slicer.org/t/meshing-self-intersecting-faces/13588 "2020-09-21T14:45:16Z")
**Posts on this page:** 14
**Page:** 1

<div class="post-metadata">

### Author: ![Fluvio\_Lobo](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fluvio_lobo/32/81262_2.png) [@Fluvio\_Lobo](https://discourse.slicer.org/u/Fluvio_Lobo)
#### Post date: [September 21, 2020, 2:45pm UTC](https://discourse.slicer.org/t/meshing-self-intersecting-faces/13588/1 "2020-09-21T14:45:16Z")

</div>

Hello,

These question may be a little outside the realm of Slicer, but it never hurts to ask!

Our team has been using Cleaver to create some amazing multi-material, conforming meshes. However, we have found mesh quality is sometimes dependent on the un-even-ness of the volume. In other words, we get better results when the input/base volume (DICOM volume is isotropic in size and voxel-spacing).

- Does anyone know why this happens?

We have also been trying to use tetgen, but it only seems to work with volumes that are fully enclosed. Otherwise, it throws a self-intersecting error.

- Has anyone figure our a way around this issue?
- Does anyone have any advice on methods for cleaning/correcting self-intersecting faces?
- Is there a way in slicer to use the raw nrrd or a label-map as an input to tetgen?

Thank you!

---

<div class="post-metadata">

### Author: ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)
#### Post date: [September 21, 2020, 3:29pm UTC](https://discourse.slicer.org/t/meshing-self-intersecting-faces/13588/2 "2020-09-21T15:29:06Z")

</div>

> [@Fluvio\_Lobo](#):
>
> Our team has been using Cleaver to create some amazing multi-material, conforming meshes.

Awesome! Could you share a few screenshots?

> [@Fluvio\_Lobo](#):
>
> we have found mesh quality is sometimes dependent on the un-even-ness of the volume. In other words, we get better results when the input/base volume (DICOM volume is isotropic in size and voxel-spacing).

This is expected. If spacing along any axis is significantly more than spacing along other axes then essentially your voxels are shaped like sticks, so you cannot represent arbitrary 3D shapes with them. If spacing difference along any of the image axis is more than a few ten percent then I use “Crop volume” module to resample the input volume to have isotropic spacing (and crop it to the region of interest to keep the volume size small).

> [@Fluvio\_Lobo](#):
>
> We have also been trying to use tetgen, but it only seems to work with volumes that are fully enclosed. Otherwise, it throws a self-intersecting error.

Tetgen is mainly added for reference, because 5-10 years ago it was a popular mesher and we wanted to make it easy to compare. It has restrictive license (you need to buy a license for commercial applications) and not robust (can crash quite easily for complex meshes that come out of medical image segmentation), so I would not recommend using it.

There are many other meshers, some of the popular ones include [netgen](https://github.com/NGSolve/netgen), [gmsh](https://gitlab.onelab.info/gmsh/gmsh), [TetWild](https://github.com/Yixin-Hu/TetWild) (see [this page](http://www.robertschneiders.de/meshgeneration/software.html) for lots of more - not very up-to-date but gives an idea how many meshers are out there.). As far as I know, @Sam_Horvath plans to add some more meshers to SegmentMesher.

---

<div class="post-metadata">

### Author: ![Fluvio\_Lobo](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fluvio_lobo/32/81262_2.png) [@Fluvio\_Lobo](https://discourse.slicer.org/u/Fluvio_Lobo)
#### Post date: [September 21, 2020, 3:37pm UTC](https://discourse.slicer.org/t/meshing-self-intersecting-faces/13588/3 "2020-09-21T15:37:25Z")

</div>

@lassoan,

I will get you some good screenshots by the end of the day for sure!

Regarding Cleaver, I have a few concerns;

1. The Cleaver team does not seem too active and the doc. seems to be very limited

2. We have issues with ‘holes’ in meshes with \>3 materials, which seems kind-of lame

3. It is not clear to me the dynamic between the scale and multiplier parameters. Could you provide some insight on the difference and use?

---

<div class="post-metadata">

### Author: ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)
#### Post date: [September 21, 2020, 4:05pm UTC](https://discourse.slicer.org/t/meshing-self-intersecting-faces/13588/4 "2020-09-21T16:05:06Z")

</div>

> [@Fluvio\_Lobo](#):
>
> Cleaver team does not seem too active

The SCI group is still very much active but it is true that not much development is going on for this particular project recently. My understanding is that they are still committed to maintaining their software and Kitware helps them in this, too. Latest release is 3 months old, so it is not too bad.

> [@Fluvio\_Lobo](#):
>
> We have issues with ‘holes’ in meshes with \>3 materials, which seems kind-of lame

Can you show examples? You should be able to resolve this, but you may need to increase the resolution of the mesh near boundaries. Cleaver is intended for biomedical applications, so it may smoothen sharp edges, and where multiple materials meet, sharp edges are inevitable. Also check out how the input segmentation looked like. There might have been 1-2 empty voxels at the junction point.

> [@Fluvio\_Lobo](#):
>
> It is not clear to me the dynamic between the scale and multiplier parameters. Could you provide some insight on the difference and use?

See this page: [GitHub - lassoan/SlicerSegmentMesher: Create volumetric mesh from segmentation using Cleaver2 or TetGen](https://github.com/lassoan/SlicerSegmentMesher#mesh-generation-parameters)

The main difference is that `scale` essentially specifies how densely the input is sampled (if you take few samples from the mesh then execution will be faster but you will lose lots of details), while `multiplier` controls element size (if you have large elements then you will have a simpler mesh but cannot represent small details).

---

<div class="post-metadata">

### Author: ![Fluvio\_Lobo](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fluvio_lobo/32/81262_2.png) [@Fluvio\_Lobo](https://discourse.slicer.org/u/Fluvio_Lobo)
#### Post date: [September 21, 2020, 4:25pm UTC](https://discourse.slicer.org/t/meshing-self-intersecting-faces/13588/5 "2020-09-21T16:25:47Z")

</div>

> [@lassoan](#):
>
> The main difference is that `scale` essentially specifies how densely the input is sampled (if you take few samples from the mesh then execution will be faster but you will lose lots of details), while `multiplier` controls element size (if you have large elements then you will have a simpler mesh but cannot represent small details).

Lets say we have a boundary layer we are measuring at **2 mm** , have does the value of multiplier and, thus, element size match to the units of the volume? Does a value of 0.2 mean I will have about 10 elements in that boundary?

---

<div class="post-metadata">

### Author: ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)
#### Post date: [September 21, 2020, 4:27pm UTC](https://discourse.slicer.org/t/meshing-self-intersecting-faces/13588/6 "2020-09-21T16:27:27Z")

</div>

I don’t remember these details (segmentation spacing may have an effect, too). The best is to experiment with this on simple examples and if you figure out something then share what you have found (we will add it to SegmentMesher documentation).

---

<div class="post-metadata">

### Author: ![Fluvio\_Lobo](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fluvio_lobo/32/81262_2.png) [@Fluvio\_Lobo](https://discourse.slicer.org/u/Fluvio_Lobo)
#### Post date: [September 21, 2020, 4:30pm UTC](https://discourse.slicer.org/t/meshing-self-intersecting-faces/13588/7 "2020-09-21T16:30:37Z")

</div>

Will do, here is what that looks like 😅

 ![thin_layer](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/6/1/61b46412461535c979f7839498e6f94cbf68b949.png)

We usually just thicken the layer, but I am feeling like reducing the multiplier value to see if that helps!

---

<div class="post-metadata">

### Author: ![Fluvio\_Lobo](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fluvio_lobo/32/81262_2.png) [@Fluvio\_Lobo](https://discourse.slicer.org/u/Fluvio_Lobo)
#### Post date: [September 22, 2020, 3:49am UTC](https://discourse.slicer.org/t/meshing-self-intersecting-faces/13588/8 "2020-09-22T03:49:36Z")

</div>

Here is one of the highest quality meshes we generated today;

 ![mesh](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/8/4/849722dd0b78416083e36825831e4e0609a92a55.png)

The mesh is about 13M tets, which I am not a fan of, but I need a solid starting point! There are 6 materials in the model. This is a breast cancer model, so the materials represent: chest cavity, soft tissue, fibro-glandular tissue, and masses/tumors. We get holes in areas/regions where 3 models intersect;

 ![mesh_holes](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/b/1/b1192f46068412bf3ceabcfde596863e2cc0855a.png)

Now here is the interesting part. Although I started with the **adaptive** parameters (scale, multiplier, etc.), these results were obtained using the **alpha** flags the developers presented [here](https://www.ncbi.nlm.nih.gov/pmc/articles/PMC4142801/)

I will continue to explore adaptive meshing parameters to see if better results are obtained.

Any suggestions or information would be greatly appreciated

---

<div class="post-metadata">

### Author: ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)
#### Post date: [September 22, 2020, 5:00am UTC](https://discourse.slicer.org/t/meshing-self-intersecting-faces/13588/9 "2020-09-22T05:00:37Z")

</div>

I guess you want to model breast deformation between imaging (prone) and surgery (supine) patient positions. These deformations are huge and with 13M elements it would be an extremely hard problem, not just because there are many elements (so computation time would be really long), but it would be very unstable (many of those millions of tiny elements would collapse and self-intersect if you want to get near realistic deformations).

You will need much larger elements, and some adaptive element sizing to have similar shapes as in the input segmentation.

Since you don’t have accurate parient-specific material properties anyway, you probably don’t need to worry about minor imperfections, such as slightly smoothed out boundaries or tiny holes at junction points.

---

<div class="post-metadata">

### Author: ![Fluvio\_Lobo](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fluvio_lobo/32/81262_2.png) [@Fluvio\_Lobo](https://discourse.slicer.org/u/Fluvio_Lobo)
#### Post date: [September 22, 2020, 12:23pm UTC](https://discourse.slicer.org/t/meshing-self-intersecting-faces/13588/10 "2020-09-22T12:23:03Z")

</div>

> [@lassoan](#):
>
> You will need much larger elements, and some adaptive element sizing to have similar shapes as in the input segmentation.

Agree 100! The problem is that as I start smoothing, holes begin to appear on the **skin** ;  
 ![holes_on_skin](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/0/d/0d3294fbeb7f5bb0c3f759a7c52a5d45a2be903c.png)

A balance needs to exist between the adaptive parameters, but I think it may come down to a **case-to-case** basis.

The adaptive parameters I used for the first adaptive mesh were;  
`--scale 1.00 --multiplier 2.00 --grading 5`

Starting with an aggressive **sigma blend** , the the holes show;  
`--scale 1.00 --multiplier 2.00 --grading 5 --blend_sigma 2.50`

---

<div class="post-metadata">

### Author: ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)
#### Post date: [September 22, 2020, 12:58pm UTC](https://discourse.slicer.org/t/meshing-self-intersecting-faces/13588/11 "2020-09-22T12:58:20Z")

</div>

I don’t think the meshing is that sensitive to input parameters that you would need tuning for each case. If you determine parameters for a specific image spacing then it should work well for all cases.

Blend-sigma controls strength of Gaussian smoothing applied to remove staircase artifacts. See documentation:

> Sigma of Gaussian smoothing filter that is applied to the input labelmap to remove step artifacts (anti-aliasing). Higher values may shrink structures and remove small details.

You should use the smallest possible value that removes staircase artifacts. If you use higher than necessary values then structures will shrink and holes will appear between them. If you find that holes appear and staircase artifacts are still visible then resample the input volume to have smaller spacing (using Crop volume module) and redo the segmentation.

---

<div class="post-metadata">

### Author: ![Fluvio\_Lobo](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fluvio_lobo/32/81262_2.png) [@Fluvio\_Lobo](https://discourse.slicer.org/u/Fluvio_Lobo)
#### Post date: [September 22, 2020, 1:30pm UTC](https://discourse.slicer.org/t/meshing-self-intersecting-faces/13588/12 "2020-09-22T13:30:02Z")

</div>

> [@lassoan](#):
>
> I don’t think the meshing is that sensitive to input parameters that you would need tuning for each case. **If you determine parameters for a specific image spacing** then it should work well for all cases.

I am going to keep this in my notes. Most of out data should end-up with about the same spacing.

> [@lassoan](#):
>
> You should use the smallest possible value that removes staircase artifacts. If you use higher than necessary values then structures will shrink and holes will appear between them. If you find that holes appear and staircase artifacts are still visible then resample the input volume to have smaller spacing (using Crop volume module) and redo the segmentation.

We actually do a considerable amount of smoothing, so perhaps I should keep the blend sigma low;

 ![smooth](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/d/c/dc32139b3fac8a0efc43b22f310b8a30e54d009f.png)

I will keep trying parameters and I will post results!

---

<div class="post-metadata">

### Author: ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)
#### Post date: [September 22, 2020, 1:42pm UTC](https://discourse.slicer.org/t/meshing-self-intersecting-faces/13588/13 "2020-09-22T13:42:45Z")

</div>

> [@Fluvio\_Lobo](#):
>
> I am going to keep this in my notes. Most of out data should end-up with about the same spacing.

Note that you can always crop&resample your input to the desired resolution and size as part of your image import process. Therefore, you can use the same meshing protocol for all images, even if their native resolution were different.

---

<div class="post-metadata">

### Author: ![Fluvio\_Lobo](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fluvio_lobo/32/81262_2.png) [@Fluvio\_Lobo](https://discourse.slicer.org/u/Fluvio_Lobo)
#### Post date: [October 2, 2020, 1:25am UTC](https://discourse.slicer.org/t/meshing-self-intersecting-faces/13588/15 "2020-10-02T01:25:13Z")

</div>

@lassoan,

Apologies for the double-post. I wanted to add more info but I was unable to edit the response itself. Here is a more detailed explanation of the current challenge.

First, here is perhaps the most extreme model we have been able to simulate.

 ![state0](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/f/1/f19781f86ca6af4816d4ab0be4ddd43e4507882a.png)  
 ![state75](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/e/c/ec844c0fc16f64ccf55503816aa999ce2768d9ba.png)  
If I did not mention this earlier, we are using FEBio for the FEA and PostView for visualization.

The initial mesh was generated using the `Segment Mesher` module and `Cleaver2`. The most effective parameters were `--scale 1.00 --multiplier 2.00 --grading 5.00 --blend_sigma 1.75`. I would also note that we are now smoothing the compartments heavily prior to meshing, so our latest `--blend_sigma` parameters are small. The resultant mesh features about **1.1M tets** and a **minimum dihedral angle = 4.80** , which is now the parameter we are tracking the most.

As is, using FEBio, we probably get about 20% of the simulation done before one or multiple tets invert (i.e. negative jacobian).

To solve this issue, we have approached the problem in two ways:

1. Remesh (using tetgen) the failed model and continue simulating from the failed time-step
2. Remesh (using tetgen) the original mesh and restart simulation

Thus far, we have had success in both approaches. The model depicted above still fails due to penetrating tets, which we will address differently.

Our questions are;

1. **Can we export an .ele and .node (or other mesh extensions) from segment mesher?** _–This would streamline the re-meshing process_
2. **Are there other means of remeshing using `Segment Mesher` and/or `Cleaver`?**
