# vtkImageMathematics as a pipeline?

**URL:** https://discourse.vtk.org/t/vtkimagemathematics-as-a-pipeline/10154
**Category:** Support
**Created:** [December 11, 2022, 8:57am UTC](https://discourse.vtk.org/t/vtkimagemathematics-as-a-pipeline/10154 "2022-12-11T08:57:50Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![XGDragon](https://discourse.vtk.org/user_avatar/discourse.vtk.org/xgdragon/32/6239_2.png) [@XGDragon](https://discourse.vtk.org/u/XGDragon)
#### Post date: [December 11, 2022, 8:57am UTC](https://discourse.vtk.org/t/vtkimagemathematics-as-a-pipeline/10154/1 "2022-12-11T08:57:50Z")

</div>

I have learned that using a.SetInputConnection(b.GetOutputPort()), you establish a pipeline connection such that when you b.Update(), it will also update a.

For vtkImageMathematics, it appears there is no way to establish such a pipeline. You have to use a.SetInput1Data(b.GetOutput()), which breaks the line. How do I maintain a pipeline if my pipeline is to include some vtkImageMathematics?

---

<div class="post-metadata">

### Author: ![Aron\_Helser](https://discourse.vtk.org/user_avatar/discourse.vtk.org/aron_helser/32/14_2.png) [@Aron\_Helser](https://discourse.vtk.org/u/Aron_Helser)
#### Post date: [December 11, 2022, 5:07pm UTC](https://discourse.vtk.org/t/vtkimagemathematics-as-a-pipeline/10154/2 "2022-12-11T17:07:27Z")

</div>

`vtkImageMathematics` is a standard VTK filter, so you can use `SetInputConnection()` - it seems that you are missing the fact that the second overload lets you specify the input port, so you can say:

```auto
a.SetInputConnection(0, b.GetOutputPort())
a.SetInputConnection(1, c.GetOutputPort())

```

to set the two inputs.

HTH,  
Aron

---

<div class="post-metadata">

### Author: ![XGDragon](https://discourse.vtk.org/user_avatar/discourse.vtk.org/xgdragon/32/6239_2.png) [@XGDragon](https://discourse.vtk.org/u/XGDragon)
#### Post date: [December 11, 2022, 5:21pm UTC](https://discourse.vtk.org/t/vtkimagemathematics-as-a-pipeline/10154/3 "2022-12-11T17:21:58Z")

</div>

Hey Aron, thank you for your reply.

This is what I hoped, but I was dissuaded due to

```auto
a = vtkImageMathematics()
a.GetInputPortInformation(0) -> vtkInformation
a.GetInputPortInformation(1) -> vtkAlgorithm.cxx:878 ERR| vtkImageMathematics (000001EFEA65B210): Attempt to get information object for input port index 1 for an algorithm with 1 input ports.
a.GetNumberOfInputPorts() -> 1

```

but I assume I can simply ignore this and assume it works as expected.

---

<div class="post-metadata">

### Author: ![Aron\_Helser](https://discourse.vtk.org/user_avatar/discourse.vtk.org/aron_helser/32/14_2.png) [@Aron\_Helser](https://discourse.vtk.org/u/Aron_Helser)
#### Post date: [December 12, 2022, 4:30pm UTC](https://discourse.vtk.org/t/vtkimagemathematics-as-a-pipeline/10154/4 "2022-12-12T16:30:11Z")

</div>

Looking at the code, `vtkImageMathematics` actually uses any number of connections on the first port, so you can add or multiply several inputs. After you add two input connections, `a.GetNumberOfInputConnections(0)` will return 2, and I think `a.GetInputPortInformation(0).GetInformationObject(i)` or something similar will give you the info object for `i = 0, 1, 2 ...`
