How to speed up point loop in programmable filter


I have written a programmable filter to perform Euler transformations based on a poly data set and a csv input. The code boils down to a loop over the mesh points and a set of standard matrix transformations of the form

for i in range(0, numPoints):
    coord = pdi.GetPoint(i)
    x, y, z = coord[:3]
    x : rotate around ZYX with psi, theta, phi
    y : rotate around ZYX with psi, theta, phi
    z : rotate around ZYX with psi, theta, phi
    newPoints.InsertPoint(i, x, y, z)

The transformations work as intended but are extremely slow. For a 5 million points surface mesh it takes an hour to do just one transformation and I have to do 4000 of them (for each of the 4000 time steps). When I apply the Transform filter, it takes just a few seconds. Unfortunately I cannot use the transform filter to achieve what I need, because I have to transform around custom axes.

I have the following questions:

  • is the slow speed related to the “for loop”? Is there a way to optimise the loop, by using some VTK (C++?) loop for example?
  • is there an alternative to the Transform filter, which uses the Euler rotation around body fixed axes? Perhaps there is some VTK transformation which can be exposed in the programmable filter.


Use numpy insteady of for loops, e.g.,

import numpy as np

# R: 3x3 rotation matrix
R = np.array([[1,0,0],[0,0,-1],[0,1,0]])

output.Points =[0].Points.T).T

Note, the Points attribute contains the 3D coordinates as rows.

That worked like a charm, thanks!