# VTK extrusion normal has self intersection cells

**URL:** https://discourse.vtk.org/t/vtk-extrusion-normal-has-self-intersection-cells/10583
**Category:** Support
**Created:** [February 1, 2023, 3:24pm UTC](https://discourse.vtk.org/t/vtk-extrusion-normal-has-self-intersection-cells/10583 "2023-02-01T15:24:04Z")
**Posts on this page:** 16
**Page:** 1

<div class="post-metadata">

### Author: ![Hanxin\_Hua](https://discourse.vtk.org/user_avatar/discourse.vtk.org/hanxin_hua/32/3787_2.png) [@Hanxin\_Hua](https://discourse.vtk.org/u/Hanxin_Hua)
#### Post date: [February 1, 2023, 3:24pm UTC](https://discourse.vtk.org/t/vtk-extrusion-normal-has-self-intersection-cells/10583/1 "2023-02-01T15:24:04Z")

</div>

Hi, I have a very irregular surface and then called the extrusion with the normal direction. And then I found that it has all the self intersection cells. I can’t just remove them because the whole polydata will be removed. Is there a good way to avoid it?

The red part is the self intersection cells

![1675265019489](https://discourse.vtk.org/uploads/default/original/2X/4/43d3b219c24bb8bf32380cd7f5b56b6c79dbcae3.png)

---

<div class="post-metadata">

### Author: ![rexthor](https://discourse.vtk.org/user_avatar/discourse.vtk.org/rexthor/32/6481_2.png) [@rexthor](https://discourse.vtk.org/u/rexthor)
#### Post date: [February 2, 2023, 6:57pm UTC](https://discourse.vtk.org/t/vtk-extrusion-normal-has-self-intersection-cells/10583/2 "2023-02-02T18:57:50Z")

</div>

Perhaps a filter like: [https://vtk.org/doc/nightly/html/classvtkCleanPolyData.html](https://vtk.org/doc/nightly/html/classvtkCleanPolyData.html)?

---

<div class="post-metadata">

### Author: ![Hanxin\_Hua](https://discourse.vtk.org/user_avatar/discourse.vtk.org/hanxin_hua/32/3787_2.png) [@Hanxin\_Hua](https://discourse.vtk.org/u/Hanxin_Hua)
#### Post date: [February 2, 2023, 7:17pm UTC](https://discourse.vtk.org/t/vtk-extrusion-normal-has-self-intersection-cells/10583/3 "2023-02-02T19:17:59Z")

</div>

Yeah. I tried that already. It is not working

---

<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: [February 2, 2023, 7:22pm UTC](https://discourse.vtk.org/t/vtk-extrusion-normal-has-self-intersection-cells/10583/4 "2023-02-02T19:22:42Z")

</div>

Most concave surfaces will self-intersect when extruded, what do you expect to happen? What are you trying to accomplish?

To solve it you’d have to use advanced techniques like isocontouring a distance function.

---

<div class="post-metadata">

### Author: ![Hanxin\_Hua](https://discourse.vtk.org/user_avatar/discourse.vtk.org/hanxin_hua/32/3787_2.png) [@Hanxin\_Hua](https://discourse.vtk.org/u/Hanxin_Hua)
#### Post date: [February 2, 2023, 7:49pm UTC](https://discourse.vtk.org/t/vtk-extrusion-normal-has-self-intersection-cells/10583/5 "2023-02-02T19:49:13Z")

</div>

![1675367208305](https://discourse.vtk.org/uploads/default/original/2X/e/e64b395e2125e23cdf748c5ed4e6b0088fbf5834.png)  
 ![1675367192569](https://discourse.vtk.org/uploads/default/original/2X/1/130cd1d24059a1b23bd296c334ab91e12a6a963b.png)

Basically, I have this kind of surface. What I want to do is to add a thickness to it. What I use is extrusion with the normal direction, which looks perfect from outside with two issue:

1. Self intersection cells inside (because I need to use boolean operations on it later)
2. Some of extra extrusion is not desired. Basically, I only want more thickness towards the outside not inside

---

<div class="post-metadata">

### Author: ![rexthor](https://discourse.vtk.org/user_avatar/discourse.vtk.org/rexthor/32/6481_2.png) [@rexthor](https://discourse.vtk.org/u/rexthor)
#### Post date: [February 2, 2023, 8:09pm UTC](https://discourse.vtk.org/t/vtk-extrusion-normal-has-self-intersection-cells/10583/6 "2023-02-02T20:09:18Z")

</div>

VTK has a signed distance function class (that I have never used):  
[https://vtk.org/doc/nightly/html/classvtkSignedDistance.html](https://vtk.org/doc/nightly/html/classvtkSignedDistance.html), you might be able to use that and then isocontour it, like @will.schroeder mentioned.

---

<div class="post-metadata">

### Author: ![Hanxin\_Hua](https://discourse.vtk.org/user_avatar/discourse.vtk.org/hanxin_hua/32/3787_2.png) [@Hanxin\_Hua](https://discourse.vtk.org/u/Hanxin_Hua)
#### Post date: [February 2, 2023, 9:37pm UTC](https://discourse.vtk.org/t/vtk-extrusion-normal-has-self-intersection-cells/10583/7 "2023-02-02T21:37:38Z")

</div>

Can you explain a little more?

---

<div class="post-metadata">

### Author: ![rexthor](https://discourse.vtk.org/user_avatar/discourse.vtk.org/rexthor/32/6481_2.png) [@rexthor](https://discourse.vtk.org/u/rexthor)
#### Post date: [February 2, 2023, 9:42pm UTC](https://discourse.vtk.org/t/vtk-extrusion-normal-has-self-intersection-cells/10583/8 "2023-02-02T21:42:21Z")

</div>

If I understand the vtkSignedDistanceFunction class, it determines a normal distance field from the surface, and it determines an “inside” and “outside”. You would then find an isosurface of the result in order to get a surface that is everywhere “d” units away from your input surface. I’ll see if I can get an example working, and I’ll post it back … if I can figure it out.

---

<div class="post-metadata">

### Author: ![Hanxin\_Hua](https://discourse.vtk.org/user_avatar/discourse.vtk.org/hanxin_hua/32/3787_2.png) [@Hanxin\_Hua](https://discourse.vtk.org/u/Hanxin_Hua)
#### Post date: [February 2, 2023, 9:43pm UTC](https://discourse.vtk.org/t/vtk-extrusion-normal-has-self-intersection-cells/10583/9 "2023-02-02T21:43:08Z")

</div>

Thank you!

---

<div class="post-metadata">

### Author: ![Hanxin\_Hua](https://discourse.vtk.org/user_avatar/discourse.vtk.org/hanxin_hua/32/3787_2.png) [@Hanxin\_Hua](https://discourse.vtk.org/u/Hanxin_Hua)
#### Post date: [February 2, 2023, 9:44pm UTC](https://discourse.vtk.org/t/vtk-extrusion-normal-has-self-intersection-cells/10583/10 "2023-02-02T21:44:16Z")

</div>

If it works, is there a method we can use to connect these two surfaces and make it one polydata?  
Actually, I can also try the scale from vtkTransform too

---

<div class="post-metadata">

### Author: ![rexthor](https://discourse.vtk.org/user_avatar/discourse.vtk.org/rexthor/32/6481_2.png) [@rexthor](https://discourse.vtk.org/u/rexthor)
#### Post date: [February 2, 2023, 10:30pm UTC](https://discourse.vtk.org/t/vtk-extrusion-normal-has-self-intersection-cells/10583/11 "2023-02-02T22:30:37Z")

</div>

Ok this _doesn’t work_ … but here is what I was thinking:

```python

import vtk

# I think that vtkSignedDistance samples values in a cube?
SUBDIVISIONS = 128 # cube edge subdivisions
WIDTH = 2 # cube width
OFFSET = 0.2 # signed distance offset

f = vtk.vtkParametricBoy()

s = vtk.vtkParametricFunctionSource()
s.SetParametricFunction(f)
s.SetUResolution(50)
s.SetVResolution(50)
s.GenerateTextureCoordinatesOn()
s.Update()

n = vtk.vtkPolyDataNormals()
n.SetInputConnection(s.GetOutputPort())
n.Update()

# if you write out the file here - you get an object 
d = vtk.vtkSignedDistance()
d.SetInputConnection(n.GetOutputPort())
d.SetRadius(0.1) # just a guess
d.SetDimensions(SUBDIVISIONS, SUBDIVISIONS, SUBDIVISIONS)
d.SetBounds(-WIDTH/2, WIDTH/2,
            -WIDTH/2, WIDTH/2,
            -WIDTH/2, WIDTH/2)

g = vtk.vtkContourFilter()
g.SetValue(0, OFFSET)
g.SetInputConnection(d.GetOutputPort())

w = vtk.vtkPolyDataWriter()
w.SetInputConnection(g.GetOutputPort())
w.SetFileName('test.vtk')
w.Write()

# sadly - I get no surface here and don't have time to figure out why

```

---

<div class="post-metadata">

### Author: ![rexthor](https://discourse.vtk.org/user_avatar/discourse.vtk.org/rexthor/32/6481_2.png) [@rexthor](https://discourse.vtk.org/u/rexthor)
#### Post date: [February 2, 2023, 10:37pm UTC](https://discourse.vtk.org/t/vtk-extrusion-normal-has-self-intersection-cells/10583/12 "2023-02-02T22:37:53Z")

</div>

Also, your question about appending the data: I think the documentation for vtkSignedDistance indicates that it appends the data as a side effect.

---

<div class="post-metadata">

### Author: ![Hanxin\_Hua](https://discourse.vtk.org/user_avatar/discourse.vtk.org/hanxin_hua/32/3787_2.png) [@Hanxin\_Hua](https://discourse.vtk.org/u/Hanxin_Hua)
#### Post date: [February 3, 2023, 3:30pm UTC](https://discourse.vtk.org/t/vtk-extrusion-normal-has-self-intersection-cells/10583/13 "2023-02-03T15:30:29Z")

</div>

Thank you though, that is a good try.

---

<div class="post-metadata">

### Author: ![Hanxin\_Hua](https://discourse.vtk.org/user_avatar/discourse.vtk.org/hanxin_hua/32/3787_2.png) [@Hanxin\_Hua](https://discourse.vtk.org/u/Hanxin_Hua)
#### Post date: [February 3, 2023, 10:04pm UTC](https://discourse.vtk.org/t/vtk-extrusion-normal-has-self-intersection-cells/10583/14 "2023-02-03T22:04:43Z")

</div>

Yeah. I tried vtkSignedDistance several examples, it did not work

---

<div class="post-metadata">

### Author: ![rexthor](https://discourse.vtk.org/user_avatar/discourse.vtk.org/rexthor/32/6481_2.png) [@rexthor](https://discourse.vtk.org/u/rexthor)
#### Post date: [February 3, 2023, 10:10pm UTC](https://discourse.vtk.org/t/vtk-extrusion-normal-has-self-intersection-cells/10583/15 "2023-02-03T22:10:58Z")

</div>

The only thing that I can think of is that the example I was using as a reference used vtkImageMapToColors … but I was way over my head at that point. I’m sort of hoping that one of the experts will chime in …

---

<div class="post-metadata">

### Author: ![lujean](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/l/da6949/32.png) [@lujean](https://discourse.vtk.org/u/lujean)
#### Post date: [February 16, 2023, 12:01am UTC](https://discourse.vtk.org/t/vtk-extrusion-normal-has-self-intersection-cells/10583/16 "2023-02-16T00:01:31Z")

</div>

Is there qny further solution？I meet the same problem
