# vtk Boolean Operation Poly Data Filter

**URL:** https://discourse.vtk.org/t/vtk-boolean-operation-poly-data-filter/1476
**Category:** Development
**Created:** [August 2, 2019, 3:32pm UTC](https://discourse.vtk.org/t/vtk-boolean-operation-poly-data-filter/1476 "2019-08-02T15:32:31Z")
**Posts on this page:** 8
**Page:** 1

<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 2, 2019, 3:32pm UTC](https://discourse.vtk.org/t/vtk-boolean-operation-poly-data-filter/1476/1 "2019-08-02T15:32:31Z")

</div>

Hello, I have a vtkBooleanOperationPolyDataFilter and I want to add two polydata.

I keep getting this error:

Input port 0 of algorithm vtkBooleanOperationPolyDataFilter(0x7fd03000e4e0) has 0 connections but is not optional.  
Input port 1 of algorithm vtkBooleanOperationPolyDataFilter(0x7fd03000e4e0) has 0 connections but is not optional.

Can someone give me the general syntax structure for this input and output connection.

For my system, vtkBooleanOperationPolyDataFilter has the methods SetInputConnection, SetInputData, and AddInputData.

Thank you. Any help would be greatly appreciated.

---

<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 2, 2019, 3:46pm UTC](https://discourse.vtk.org/t/vtk-boolean-operation-poly-data-filter/1476/2 "2019-08-02T15:46:44Z")

</div>

You can use

```auto
  booleanOperation->SetInputData( 0, input1 );
  booleanOperation->SetInputData( 1, input2 );

```

or

```auto
  booleanOperation->SetInputConnection( 0, filter1->GetOutputPort() );
  booleanOperation->SetInputConnection( 1, filter2->GetOutputPort() );

```

Here is a full example on how to use it, linked from the [Doxygen documentation](https://vtk.org/doc/nightly/html/classvtkBooleanOperationPolyDataFilter.html) for the filter: [https://vtk.org/gitweb?p=VTK.git;a=blob;f=Filters/General/Testing/Cxx/TestBooleanOperationPolyDataFilter.cxx](https://vtk.org/gitweb?p=VTK.git;a=blob;f=Filters/General/Testing/Cxx/TestBooleanOperationPolyDataFilter.cxx)

---

<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 2, 2019, 3:49pm UTC](https://discourse.vtk.org/t/vtk-boolean-operation-poly-data-filter/1476/3 "2019-08-02T15:49:47Z")

</div>

What type/class does input1 and input2 have to be. I have a vtkAppendPolyData object that I would like to pass in.

Also, do you know how to convert a vtkAppendPolyData to vtkDataObject?

Thank you by the way!

---

<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 2, 2019, 3:57pm UTC](https://discourse.vtk.org/t/vtk-boolean-operation-poly-data-filter/1476/4 "2019-08-02T15:57:55Z")

</div>

Both inputs need to be a `vtkPolyData`, and consist of only triangles.

> [@at123](#):
>
> do you know how to convert a vtkAppendPolyData to vtkDataObject?

`vtkAppendPolyData` is a filter that produces a `vtkPolyData`. It is not an object that you can convert to a `vtkDataObject`.

You can set it up in a pipeline as follows:

```auto
vtkBooleanOperationPolyDataFilter* booleanFilter = ...;
vtkAppendPolyData* appendPolyData = ...;
booleanFilter->SetInputConnection(0, appendPolyData->GetOutputPort());

```

---

<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 2, 2019, 4:06pm UTC](https://discourse.vtk.org/t/vtk-boolean-operation-poly-data-filter/1476/5 "2019-08-02T16:06:28Z")

</div>

Thank you so much Cory Quammen!

It worked! 🙂  
By any chance do you know how I would pass a vtkBooleanOperationPolyDataFilter to vtkDelaunay3D() so that I can create a mapper and actor and render it?

---

<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 2, 2019, 4:47pm UTC](https://discourse.vtk.org/t/vtk-boolean-operation-poly-data-filter/1476/6 "2019-08-02T16:47:29Z")

</div>

```auto
vtkDelaunay3D* delaunay = ...;
delaunay->SetInputConnection(booleanFilter->GetOutputPort(0));

```

Setting up the mapper and actor can then be done the same as in [https://vtk.org/gitweb?p=VTK.git;a=blob;f=Filters/General/Testing/Cxx/TestBooleanOperationPolyDataFilter.cxx](https://vtk.org/gitweb?p=VTK.git;a=blob;f=Filters/General/Testing/Cxx/TestBooleanOperationPolyDataFilter.cxx), but instead of

```auto
mapper->SetInputConnection( boolFilter->GetOutputPort( 0 ) );

```

you would have

```auto
mapper->SetInputConnection( delaunay->GetOutputPort( 0 ) );

```

---

<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 2, 2019, 5:43pm UTC](https://discourse.vtk.org/t/vtk-boolean-operation-poly-data-filter/1476/7 "2019-08-02T17:43:24Z")

</div>

Thank you for helping me out. I really appreciate. After I added what you said in the previous post, I got 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.

I don’t know what went wrong. Could you look at my code. It would really help me out. By the way, the purpose of the code is to render a convex volume from multiple contours.Thanks.

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

---

<div class="post-metadata">

### Author: ![KeyboardMan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/keyboardman/32/968_2.png) [@KeyboardMan](https://discourse.vtk.org/u/KeyboardMan)
#### Post date: [October 9, 2019, 3:17am UTC](https://discourse.vtk.org/t/vtk-boolean-operation-poly-data-filter/1476/8 "2019-10-09T03:17:51Z")

</div>

- Why not use Cylinder
