# How to extract surface from polydata

**URL:** https://discourse.vtk.org/t/how-to-extract-surface-from-polydata/321
**Category:** Support
**Created:** [February 25, 2019, 11:14am UTC](https://discourse.vtk.org/t/how-to-extract-surface-from-polydata/321 "2019-02-25T11:14:54Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![Frank](https://discourse.vtk.org/user_avatar/discourse.vtk.org/frank/32/43_2.png) [@Frank](https://discourse.vtk.org/u/Frank)
#### Post date: [February 25, 2019, 11:14am UTC](https://discourse.vtk.org/t/how-to-extract-surface-from-polydata/321/1 "2019-02-25T11:14:54Z")

</div>

I use `vtkCylinderSource` and `vtkAppendPolyData` to create some cylinders that intersect. Now I want to extract the surface of them. How can I do that.

The data looks like the following.

 ![1](https://discourse.vtk.org/uploads/default/original/1X/140dc8a2b3901221000ea4ae728adcc1c0a37e32.png)

---

<div class="post-metadata">

### Author: ![cory.quammen](https://discourse.vtk.org/user_avatar/discourse.vtk.org/cory.quammen/32/6751_2.png) [@cory.quammen](https://discourse.vtk.org/u/cory.quammen)
#### Post date: [February 25, 2019, 1:15pm UTC](https://discourse.vtk.org/t/how-to-extract-surface-from-polydata/321/2 "2019-02-25T13:15:02Z")

</div>

`vtkAppendPolyData` produces a surface, so there may not be anything you need to do.

Or do you mean you wish to get the surface of the union of the two cylinders? If that’s the case you can use [vtkBooleanOperationPolyDataFilter](https://vtk.org/doc/nightly/html/classvtkBooleanOperationPolyDataFilter.html), though be forewarned that the filter is a little unstable.

---

<div class="post-metadata">

### Author: ![Frank](https://discourse.vtk.org/user_avatar/discourse.vtk.org/frank/32/43_2.png) [@Frank](https://discourse.vtk.org/u/Frank)
#### Post date: [February 26, 2019, 6:59am UTC](https://discourse.vtk.org/t/how-to-extract-surface-from-polydata/321/3 "2019-02-26T06:59:14Z")

</div>

Thank you for your help. But I still get some problem.

I want to get tube connection ultimately. I tried to use `vtkAppendPolyData` to append two tubes that intersected. But inside the junction there are some face I do not need. So I have a idea that create two intersected cylinder and extract their outside face.

I run the following code but get some error and output nothing.

```auto
    auto c1 = vtkSmartPointer<vtkCylinderSource>::New();
    auto c2 = vtkSmartPointer<vtkCylinderSource>::New();

    c1->SetHeight(20);
    c2->SetHeight(20);

// rotate c1
    auto transform = vtkSmartPointer<vtkTransform>::New();
    auto transformFilter = vtkSmartPointer<vtkTransformPolyDataFilter>::New();
    transform->RotateZ(90);
    transformFilter->SetTransform(transform);
    transformFilter->SetInputConnection(c1->GetOutputPort());

// auto append = vtkSmartPointer<vtkAppendPolyData>::New();
// append->AddInputConnection(transformFilter->GetOutputPort());
// append->AddInputConnection(c2->GetOutputPort());

    auto filter = vtkSmartPointer<vtkBooleanOperationPolyDataFilter>::New();
    filter->AddInputConnection(c1->GetOutputPort());
    filter->AddInputConnection(c2->GetOutputPort());
    filter->SetOperationToUnion();

    auto mapper = vtkSmartPointer<vtkPolyDataMapper>::New();
    mapper->SetInputConnection(filter->GetOutputPort());

    auto actor = vtkSmartPointer<vtkActor>::New();
    actor->SetMapper(mapper);

    auto renderer = vtkSmartPointer<vtkRenderer>::New();
    renderer->AddActor(actor);

    auto renderWindow = vtkSmartPointer<vtkRenderWindow>::New();
    renderWindow->AddRenderer(renderer);

    auto style = vtkSmartPointer<vtkInteractorStyleTrackballCamera>::New();
    auto interactor = vtkSmartPointer<vtkRenderWindowInteractor>::New();
    interactor->SetRenderWindow(renderWindow);
    interactor->SetInteractorStyle(style);
    interactor->Start();

```

The following is error info.

```auto
ERROR: In /opt/VTK/VTK-8.2.0.rc2/Common/ExecutionModel/vtkDemandDrivenPipeline.cxx, line 719
vtkCompositeDataPipeline (0x5612405a9790): Input port 0 of algorithm vtkBooleanOperationPolyDataFilter(0x5612405a8d50) has 2 connections but is not repeatable.

ERROR: In /opt/VTK/VTK-8.2.0.rc2/Common/ExecutionModel/vtkDemandDrivenPipeline.cxx, line 709
vtkCompositeDataPipeline (0x5612405a9790): Input port 1 of algorithm vtkBooleanOperationPolyDataFilter(0x5612405a8d50) has 0 connections but is not optional.

ERROR: In /opt/VTK/VTK-8.2.0.rc2/Common/ExecutionModel/vtkDemandDrivenPipeline.cxx, line 719
vtkCompositeDataPipeline (0x5612405a9790): Input port 0 of algorithm vtkBooleanOperationPolyDataFilter(0x5612405a8d50) has 2 connections but is not repeatable.

ERROR: In /opt/VTK/VTK-8.2.0.rc2/Common/ExecutionModel/vtkDemandDrivenPipeline.cxx, line 709
vtkCompositeDataPipeline (0x5612405a9790): Input port 1 of algorithm vtkBooleanOperationPolyDataFilter(0x5612405a8d50) has 0 connections but is not optional.

ERROR: In /opt/VTK/VTK-8.2.0.rc2/Common/ExecutionModel/vtkDemandDrivenPipeline.cxx, line 719
vtkCompositeDataPipeline (0x5612405a9790): Input port 0 of algorithm vtkBooleanOperationPolyDataFilter(0x5612405a8d50) has 2 connections but is not repeatable.

ERROR: In /opt/VTK/VTK-8.2.0.rc2/Common/ExecutionModel/vtkDemandDrivenPipeline.cxx, line 709
vtkCompositeDataPipeline (0x5612405a9790): Input port 1 of algorithm vtkBooleanOperationPolyDataFilter(0x5612405a8d50) has 0 connections but is not optional.

ERROR: In /opt/VTK/VTK-8.2.0.rc2/Common/ExecutionModel/vtkDemandDrivenPipeline.cxx, line 719
vtkCompositeDataPipeline (0x5612405a9790): Input port 0 of algorithm vtkBooleanOperationPolyDataFilter(0x5612405a8d50) has 2 connections but is not repeatable.

ERROR: In /opt/VTK/VTK-8.2.0.rc2/Common/ExecutionModel/vtkDemandDrivenPipeline.cxx, line 709
vtkCompositeDataPipeline (0x5612405a9790): Input port 1 of algorithm vtkBooleanOperationPolyDataFilter(0x5612405a8d50) has 0 connections but is not optional.

```

---

<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: [February 27, 2019, 2:55am UTC](https://discourse.vtk.org/t/how-to-extract-surface-from-polydata/321/4 "2019-02-27T02:55:06Z")

</div>

~~@cory.quammen, I also cannot get the `vtk.vtkBooleanOperationPolyDataFilter` filter to work:~~  
The `vtk.vtkBooleanOperationPolyDataFilter` needs triangulated poly data as inputs.

```python
import vtki
import vtk

# create cylinders and triangulate the meshes
c1 = vtki.Cylinder((0,0,0), (1,0,0), 2, 20).tri_filter()
c2 = vtki.Cylinder((0,0,0), (1,1,0), 2, 20).tri_filter()

tubes = vtki.MultiBlock([c1, c2])
merged = tubes.combine()
merged.plot(show_edges=True)

```

 ![download](https://discourse.vtk.org/uploads/default/original/1X/2310d324c3d42d197b4667167fe81687ba655efa.png)

Apply the filter

```python
# Get the intersection:
alg = vtk.vtkBooleanOperationPolyDataFilter()
alg.SetInputData(0, c1)
alg.SetInputData(1, c2)
alg.SetOperationToIntersection()
alg.Update()
intersection = vtki.wrap(alg.GetOutput())
alg.SetOperationToUnion()
alg.Update()
union = vtki.wrap(alg.GetOutput())

```

And plot up the result:

```python
p = vtki.Plotter()
p.add_mesh(union, opacity=0.75, color='w')
p.add_mesh(intersection, color='r')
p.show()

```

 ![download](https://discourse.vtk.org/uploads/default/original/1X/8cadeef55165c90f0bfca0e301faedc97c166127.png)

---

<div class="post-metadata">

### Author: ![Frank](https://discourse.vtk.org/user_avatar/discourse.vtk.org/frank/32/43_2.png) [@Frank](https://discourse.vtk.org/u/Frank)
#### Post date: [February 27, 2019, 2:30pm UTC](https://discourse.vtk.org/t/how-to-extract-surface-from-polydata/321/5 "2019-02-27T14:30:11Z")

</div>

@cory.quammen@banesullivan I tried but get some black strips on the union. The strips disappear when tubes are orthogonal.

I have another question. Since `vtkBooleanOperationPolyDataFilter` can only handle with two polydata. **How can I get more than two tubes union**

 ![1](https://discourse.vtk.org/uploads/default/original/1X/e220dde5641ded569ba2287d9459924b79cc37b1.png)

```auto
 auto l1 = vtkSmartPointer<vtkLineSource>::New();
    auto l2 = vtkSmartPointer<vtkLineSource>::New();
    l1->SetPoint1(-2, 0, 0);
    l1->SetPoint2(2, 0, 0);
    l2->SetPoint1(1, -2, 0);
    l2->SetPoint2(-1, 2, 0);

    auto c1 = vtkSmartPointer<vtkTubeFilter>::New();
    auto c2 = vtkSmartPointer<vtkTubeFilter>::New();

    c1->SetInputConnection(l1->GetOutputPort());
    c1->SetNumberOfSides(30);
    c2->SetInputConnection(l2->GetOutputPort());
    c2->SetNumberOfSides(30);

    auto triFilter1 = vtkSmartPointer<vtkTriangleFilter>::New();
    triFilter1->SetInputConnection(c1->GetOutputPort());

    auto triFilter2 = vtkSmartPointer<vtkTriangleFilter>::New();
    triFilter2->SetInputConnection(c2->GetOutputPort());

    auto filter = vtkSmartPointer<vtkBooleanOperationPolyDataFilter>::New();
    filter->SetInputConnection(0, triFilter1->GetOutputPort());
    filter->SetInputConnection(1, triFilter2->GetOutputPort());
    filter->SetOperationToUnion();

```

---

<div class="post-metadata">

### Author: ![cory.quammen](https://discourse.vtk.org/user_avatar/discourse.vtk.org/cory.quammen/32/6751_2.png) [@cory.quammen](https://discourse.vtk.org/u/cory.quammen)
#### Post date: [March 1, 2019, 4:31am UTC](https://discourse.vtk.org/t/how-to-extract-surface-from-polydata/321/6 "2019-03-01T04:31:13Z")

</div>

The dark strips could just be incorrect normals produced by the filter. Recall I mentioned that the filter is a little unstable - geometric algorithms are hard to get right! You could try to generate new normals by adding a `vtkPolyDataNormals` filter to the output of the boolean operations filter.

> [@Frank](#):
>
> How can I get more than two tubes union

You’ll need to create additional boolean operation filters, setting one input to the accumulating running union object and the other input to the additional tube.

---

<div class="post-metadata">

### Author: ![Frank](https://discourse.vtk.org/user_avatar/discourse.vtk.org/frank/32/43_2.png) [@Frank](https://discourse.vtk.org/u/Frank)
#### Post date: [March 1, 2019, 9:20am UTC](https://discourse.vtk.org/t/how-to-extract-surface-from-polydata/321/7 "2019-03-01T09:20:54Z")

</div>

Thank you. `vtkPolyDataNormals` works well

> [@cory.quammen](#):
>
> The dark strips could just be incorrect normals produced by the filter. Recall I mentioned that the filter is a little unstable - geometric algorithms are hard to get right! You could try to generate new normals by adding a `vtkPolyDataNormals` filter to the output of the boolean operations filter.
> 
> > [@Frank](#):
> >
> > How can I get more than two tubes union
> 
> You’ll need to create additional boolean operation filters, setting one input to the accumulating running union object and the other input to the additional tube.

---

<div class="post-metadata">

### Author: ![at123](https://discourse.vtk.org/user_avatar/discourse.vtk.org/at123/32/748_2.png) [@at123](https://discourse.vtk.org/u/at123)
#### Post date: [August 5, 2019, 2:28pm UTC](https://discourse.vtk.org/t/how-to-extract-surface-from-polydata/321/8 "2019-08-05T14:28:19Z")

</div>

Hi,

If I use vtkBooleanOperationPolyDataFilter to get the union of multiple vtkAppendPolyData, can I pass it to vtkDelaunay3D to graph it? What would be the syntax for passing in arguments, etc. Thanks.

---

<div class="post-metadata">

### Author: ![cory.quammen](https://discourse.vtk.org/user_avatar/discourse.vtk.org/cory.quammen/32/6751_2.png) [@cory.quammen](https://discourse.vtk.org/u/cory.quammen)
#### Post date: [August 5, 2019, 2:42pm UTC](https://discourse.vtk.org/t/how-to-extract-surface-from-polydata/321/9 "2019-08-05T14:42:13Z")

</div>

> [@at123](#):
>
> If I use vtkBooleanOperationPolyDataFilter to get the union of multiple vtkAppendPolyData, can I pass it to vtkDelaunay3D to graph it?

Sure.

> [@at123](#):
>
> What would be the syntax for passing in arguments, etc. Thanks.

What have you tried so far?

---

<div class="post-metadata">

### Author: ![at123](https://discourse.vtk.org/user_avatar/discourse.vtk.org/at123/32/748_2.png) [@at123](https://discourse.vtk.org/u/at123)
#### Post date: [August 5, 2019, 2:53pm UTC](https://discourse.vtk.org/t/how-to-extract-surface-from-polydata/321/10 "2019-08-05T14:53:00Z")

</div>

This is what I have done so far:

[code.txt](https://discourse.vtk.org/uploads/short-url/joqqNZEVCiphmtb4y5gr7AbufHU.txt) (2.4 KB)

I keep getting these errors:

```
ERROR: In /work/standalone-x64-build/VTK-source/Common/ExecutionModel/vtkDemandDrivenPipeline.cxx, line 709
vtkCompositeDataPipeline (0x915f840): Input port 0 of algorithm vtkBooleanOperationPolyDataFilter(0x7f48bc00eda0) has 0 connections but is not optional.

ERROR: In /work/standalone-x64-build/VTK-source/Common/ExecutionModel/vtkDemandDrivenPipeline.cxx, line 709
vtkCompositeDataPipeline (0x915f840): Input port 1 of algorithm vtkBooleanOperationPolyDataFilter(0x7f48bc00eda0) has 0 connections but is not optional.
```

---

<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: [August 5, 2019, 3:00pm UTC](https://discourse.vtk.org/t/how-to-extract-surface-from-polydata/321/11 "2019-08-05T15:00:49Z")

</div>

@at123 : please avoid asking the same question in multiple posts.

> [@Problems using vtkContourWidget, vtkAppendPolyData, and vtkDelaunay3D](https://discourse.vtk.org/t/problems-using-vtkcontourwidget-vtkappendpolydata-and-vtkdelaunay3d/1480):
>
> Hello, I have a ImageResliceVTKWidget. I can move across a series of medical images. Say I am moving from left to right between images. To create a contour on a certain image, I use the vtkContourWidget. I click multiple points and create a closed loop. First I create a large circle, then move to the right. Then I create a smaller circle. Then move to the right. Then create a large circle again. I would like to create a volume using these contours. So I use the vtkAppendPolyData. I do someth…

---

<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: [August 5, 2019, 3:01pm UTC](https://discourse.vtk.org/t/how-to-extract-surface-from-polydata/321/12 "2019-08-05T15:01:20Z")

</div>



---

<div class="post-metadata">

### Author: ![cory.quammen](https://discourse.vtk.org/user_avatar/discourse.vtk.org/cory.quammen/32/6751_2.png) [@cory.quammen](https://discourse.vtk.org/u/cory.quammen)
#### Post date: [August 5, 2019, 3:13pm UTC](https://discourse.vtk.org/t/how-to-extract-surface-from-polydata/321/13 "2019-08-05T15:13:47Z")

</div>

One of your `vtkBooleanOperationPolyDataFilter` objects doesn’t have any inputs when it is being updated. There is probably a logic error in your loop. You can check which filter has no input on port 0 by calling `booleanOperation->GetNumberOfInputConnections(0)`. I suggest tracking down which one does this and going from there.
