Programmable filter: get arrays from vtkCellDataToPointData

(Miguel Angel AGUIRRE) #1


I am using a programmable filter capable of reading cell centered data. It converts some arrays from cell data to point data and then it performs some calculations with the new point-based data (see code below).

However, this firstly requires sending the converted point data arrays to the output and then to call them again in order to perform further calculations with these arrays. This is not memory efficient because I only want to have the new arrays in the output (not the converted ones).

So, how can I read the new point based arrays from vtkCellDataToPointData without storing it in the output?

I provided some data in order to show this. I want only the “NewArray” in the output.

Thanks in advance!


CellDataToPointData.pvsm (619.8 KB)
PV_ERROR_TEST.cas (298.6 KB)
PV_ERROR_TEST.dat (491.3 KB)

import vtk

use pass arrays to extract a copy with the arrays of interest


use CellToPoints to operate on the arrays we care about

c2p = vtk.vtkCellDataToPointData()

iterate over blocks and copy in the result

iter=dsa.MultiCompositeDataIterator([c2p.GetOutputDataObject(0), output])
for in_block, output_block in iter:
output_block.PointData.append(in_block.VTKObject.GetPointData().GetArray(‘X_VELOCITY’), “Vx”)
output_block.PointData.append(in_block.VTKObject.GetPointData().GetArray(‘Y_VELOCITY’), “Vy”)

Further calculation with the point data:

Vx = output_block.PointData[“Vx”]
Vy = output_block.PointData[“Vx”]
NewArray = VxVx+VyVy

output.PointData.append(NewArray, “NewArray”)

(Mathieu Westphal (Kitware)) #2

Sorry, it is not very clear what you are trying to achive without success.

(Miguel Angel AGUIRRE) #3

Hello Mathieu,

I attached an image explaining what I have and what I need (An image is worth a thousand words…).

PS: my only constraint is that I really need to use point based data A and B to calculate new_array (it is not an option to calculate new_array from cell based data A and B, and then convert new_array from cell data to point data before sending it to the output).

Thanks again!


(Mathieu Westphal (Kitware)) #4

First, why do you want to use a ProgrammableFilter ?
You can do that with a CellDataToPointData followed by a Calculator/Python Calculator

Second, you do not need to Send A and B to output before Reading them from output, just use the output of the CellDataToPointData directly.

(Miguel Angel AGUIRRE) #5

Hello Mathieu,

Thanks for your answer.

I’m trying to merge both filters (CellDataToPointData + Calculator) into a single programmable filter because this will be used to read several types of file formats, which can be either cell data or point data.

Regarding your second point. Thanks for the tip. I used the following script to have acces to the “c2p” (vtk cell to points) output :

DATA = dsa.WrapDataObject(c2p.GetOutput())
print DATA.PointData[‘X_VELOCITY’]

Note: for those who may have had the same problem, sometimes It throws the following error mesage:

AttributeError: ‘NoneType’ object has no attribute ‘IsA’

This is avoided by using “MergeBlocks” filter before using the programmable filter.

Best regards,