0

I want to be able to modify vtk arrays in python without the need to copy them, modify them and then add them back to vtk polydata. In C++, I assume that this is feasible using references. Is there a solution a similar solution in python?

A MWE is as follows

from os import read
import vtk as vtk
import numpy as np
from helpers.numpy_support import *
def main():
    sphere = vtk.vtkPolyDataReader()
    sphere.SetFileName('sphere.vtk')
    sphere.Update()
    polyData=sphere.GetOutput()
    array = vtk_to_numpy(polyData.GetPointData().GetAbstractArray('Result'))
    for a in array:
        a*=5.0
    writer = vtk.vtkPolyDataWriter()
    writer.SetFileName('modifiedSphere.vtk')
    writer.SetInputData(polyData)
    writer.Write()

main()
Al-Farouq
  • 5
  • 3

1 Answers1

0

using the indices in the iteration solves the problem!

for i in range(len(array)):
   array[i]*=5
Al-Farouq
  • 5
  • 3