# How to speed up point loop in programmable filter

**URL:** https://discourse.paraview.org/t/how-to-speed-up-point-loop-in-programmable-filter/5934
**Category:** ParaView Support
**Tags:** vtk
**Created:** [November 30, 2020, 11:48am UTC](https://discourse.paraview.org/t/how-to-speed-up-point-loop-in-programmable-filter/5934 "2020-11-30T11:48:58Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Lukasz](https://discourse.paraview.org/user_avatar/discourse.paraview.org/lukasz/32/5392_2.png) [@Lukasz](https://discourse.paraview.org/u/Lukasz)
#### Post date: [November 30, 2020, 11:48am UTC](https://discourse.paraview.org/t/how-to-speed-up-point-loop-in-programmable-filter/5934/1 "2020-11-30T11:48:58Z")

</div>

Hi,

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

```auto
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)
pdo.SetPoints(newPoints)

```

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.

Thanks

---

<div class="post-metadata">

### Author: ![lhofmann](https://discourse.paraview.org/letter_avatar_proxy/v4/letter/l/9e8a1a/32.png) [@lhofmann](https://discourse.paraview.org/u/lhofmann)
#### Post date: [December 1, 2020, 9:55am UTC](https://discourse.paraview.org/t/how-to-speed-up-point-loop-in-programmable-filter/5934/2 "2020-12-01T09:55:26Z")

</div>

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

```python
import numpy as np

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

output.Points = R.dot(inputs[0].Points.T).T

```

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

---

<div class="post-metadata">

### Author: ![Lukasz](https://discourse.paraview.org/user_avatar/discourse.paraview.org/lukasz/32/5392_2.png) [@Lukasz](https://discourse.paraview.org/u/Lukasz)
#### Post date: [December 2, 2020, 8:35am UTC](https://discourse.paraview.org/t/how-to-speed-up-point-loop-in-programmable-filter/5934/3 "2020-12-02T08:35:47Z")

</div>

That worked like a charm, thanks!
