Programmable filter: integrate variables/attributes

Hello!

I would like to know if it is possible to integrate the input variables by using a Programmable Filter. I found that a so-called “vtkIntegrateAttributes” exists but I could not find an example explaining how to use it in a Python Programmable Filter…
Do you have some code snippet in order to have an idea what to do?

Thanks in advance!

Miguel

Just curious: is using the Integrate Variables filter not appropriate in your use case?

Using vtkIntegrateAttributes should be reasonably easy. Try something like this:

import vtk.vtkFiltersParallel

integrate = vtk.vtkIntegrateAttributes()
integrate.SetInputData(self.GetInput())
integrate.SetDivideAllCellDataByVolume(1)
integrate.Update()

integrated = integrate.GetOutput()
pd = integrated.GetPointData()
cd = integrated.GetCellData()
print("Integrated point data")
for i in range(pd.GetNumberOfArrays()):
    arrayName = pd.GetArray(i).GetName()
    arrayValue = pd.GetArray(i).GetTuple(0)[0]
    print("%s: %f" % (arrayName, arrayValue))

print("Integrated cell data")
for i in range(cd.GetNumberOfArrays()):
    arrayName = cd.GetArray(i).GetName()
    arrayValue = cd.GetArray(i).GetTuple(0)[0]
    print("%s: %f" % (arrayName, arrayValue))

Hello Cory,

Thank you very much for your answer. This works perfectly fine.

I am exploring this alternative for several reasons.

• The first reason is that sometimes I need to create new arrays with a Programmable Filter. Then I integrate a specific array and I use this result to keep performing further calculations in a second Programmable Filter:

InputData à Programmable filter 1 àPass Arrays àIntegrateVariablesàProgrammable Filter 2

It would be nice to merge these four steps into a single one. Of course, so far I have been using a Custom Filter to do so, but I would like to do all that in a single programmable filter.

• The second reason (still the same case explained before) is that I find it annoying for cases when the output of the first ProgrammableFilter has a lot of variables and you just need to integrate some of them. This requires searching and picking the desired variables (let’s say, 10 to 20 variables) in the GUI of the Pass Array filter: looking for 20 variables spread among several others variables (a lot) is time consuming and prone to errors. So, I asked myself if a programmable filter may provide a better solution…

Thanks again.

Miguel

1 Like