# Filters with non-optional ports ?

**URL:** https://discourse.vtk.org/t/filters-with-non-optional-ports/7583
**Category:** Support
**Created:** [January 6, 2022, 10:23pm UTC](https://discourse.vtk.org/t/filters-with-non-optional-ports/7583 "2022-01-06T22:23:15Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Nicholas\_Yue](https://discourse.vtk.org/user_avatar/discourse.vtk.org/nicholas_yue/32/3751_2.png) [@Nicholas\_Yue](https://discourse.vtk.org/u/Nicholas_Yue)
#### Post date: [January 6, 2022, 10:23pm UTC](https://discourse.vtk.org/t/filters-with-non-optional-ports/7583/1 "2022-01-06T22:23:15Z")

</div>

Hi,

I am looking for vtkAlgorithm derived classes in VTK that requires two or more non-optional inputs ?

Any recommendations ?

At this stage of my VTK study, I am not after repeatable inputs yet.

Cheers

---

<div class="post-metadata">

### Author: ![Andrew](https://discourse.vtk.org/user_avatar/discourse.vtk.org/andrew/32/3861_2.png) [@Andrew](https://discourse.vtk.org/u/Andrew)
#### Post date: [January 7, 2022, 12:26am UTC](https://discourse.vtk.org/t/filters-with-non-optional-ports/7583/2 "2022-01-07T00:26:31Z")

</div>

In a vtkAlgorithm you can override the FillInputPortInformation function to set port info like types, optional, required, etc. Here’s one with two input ports with types & one being optional.

In the header.

```auto
MyFilterSubclass() { SetNumberOfInputPorts(2); }
int FillInputPortInformation(int port, vtkInformation* info)

```

Later in the source

```auto
int MyFilterSubclass::FillInputPortInformation(int port, vtkInformation* info)
{
	if (port == 0)
	{
		info->Set(vtkDataObject::DATA_TYPE_NAME(), "vtkPolyData");
		return 1;
	}
	else if (port == 1)
	{
		info->Set(vtkDataObject::DATA_TYPE_NAME(), "vtkImageData");
		info->Set(vtkAlgorithm::INPUT_IS_OPTIONAL(), 1); // true
		return 1;
	}
	return 0;
}

```

---

<div class="post-metadata">

### Author: ![Nicholas\_Yue](https://discourse.vtk.org/user_avatar/discourse.vtk.org/nicholas_yue/32/3751_2.png) [@Nicholas\_Yue](https://discourse.vtk.org/u/Nicholas_Yue)
#### Post date: [January 7, 2022, 12:48am UTC](https://discourse.vtk.org/t/filters-with-non-optional-ports/7583/3 "2022-01-07T00:48:30Z")

</div>

I am not trying to write a new class, I want to find out if there are classes in the VTK source example that already requires 2 or more non-optional ports.
