<div dir="ltr">Hi<div><br></div><div>Sorry for the crossposting. I have posted this message also on <a href="http://vtk.1045678.n5.nabble.com/">http://vtk.1045678.n5.nabble.com/</a> but it says that it has been rejected. </div><div><br></div><div><br></div><div><br></div><div><span style="font-size:12.8000001907349px">I am trying to add a calculated scalar to an existing VTK file.</span><br style="font-size:12.8000001907349px"><br style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">A simplified version of my code is the following</span><br style="font-size:12.8000001907349px"><br style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">    import vtk</span><br style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">    import os</span><br style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">    import numpy as np</span><br style="font-size:12.8000001907349px"><br style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">    reader = vtk.vtkDataSetReader()</span><br style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">    reader.SetFileName(vtk_file_</span><span style="font-size:12.8000001907349px">name)</span><br style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">    reader.ReadAllScalarsOn()</span><br style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">    reader.Update()</span><br style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">    data = reader.GetOutput() #This contains all data from the VTK</span><br style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">    cell_data = data.GetCellData() #This contains just the cells data</span><br style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">    scalar_data1 = cell_data.GetArray('scalar1')</span><br style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">    scalar_data2 = cell_data.GetArray('scalar2')</span><br style="font-size:12.8000001907349px"><br style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">    scalar1 = np.array([scalar_data1.</span><span style="font-size:12.8000001907349px">GetValue(i) for i in</span><br style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">range(data.GetNumberOfCells())</span><span style="font-size:12.8000001907349px">])</span><br style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">    scalar2 = np.array([scalar_data2.</span><span style="font-size:12.8000001907349px">GetValue(i) for i in</span><br style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">range(data.GetNumberOfCells())</span><span style="font-size:12.8000001907349px">])</span><br style="font-size:12.8000001907349px"><br style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">    scalar3 = scalar1 - scalar2</span><br style="font-size:12.8000001907349px"><br style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">    writer = vtk.vtkDataSetWriter()</span><br style="font-size:12.8000001907349px"><br style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">At this point I assume that I need to add a vtkArray to data by using</span><br style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">data.SetCell</span><br style="font-size:12.8000001907349px"><br style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">The problem is that SetCell asks for a vtkCellArray and I have not managed</span><br style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">yet to convert my array scalar3 to a vtkCellArray.</span><br style="font-size:12.8000001907349px"><br style="font-size:12.8000001907349px"><span style="font-size:12.8000001907349px">Is this the right approach? Any suggestion? Thanks a lot!!</span><br style="font-size:12.8000001907349px"></div></div>