[vtkusers] Add scalars to vtk file (vtk 3.0 legacy) in Python

Rojj ruggiero.guida at gmail.com
Wed Feb 18 10:30:27 EST 2015


I am trying to add a calculated scalar to an existing VTK file. 

A simplified version of my code is the following 

    import vtk 
    import os 
    import numpy as np 

    reader = vtk.vtkDataSetReader()   
    reader.SetFileName(vtk_file_name) 
    reader.ReadAllScalarsOn() 
    reader.Update() 
    data = reader.GetOutput() #This contains all data from the VTK 
    cell_data = data.GetCellData() #This contains just the cells data 
    scalar_data1 = cell_data.GetArray('scalar1') 
    scalar_data2 = cell_data.GetArray('scalar2') 

    scalar1 = np.array([scalar_data1.GetValue(i) for i in
range(data.GetNumberOfCells())]) 
    scalar2 = np.array([scalar_data2.GetValue(i) for i in
range(data.GetNumberOfCells())]) 
    
    scalar3 = scalar1 - scalar2 

    writer = vtk.vtkDataSetWriter() 

At this point I assume that I need to add a vtkArray to data by using
data.SetCell 

The problem is that SetCell asks for a vtkCellArray and I have not managed
yet to convert my array scalar3 to a vtkCellArray. 

Is this the right approach? Any suggestion? Thanks a lot!!



--
View this message in context: http://vtk.1045678.n5.nabble.com/Add-scalars-to-vtk-file-vtk-3-0-legacy-in-Python-tp5730428.html
Sent from the VTK - Users mailing list archive at Nabble.com.


More information about the vtkusers mailing list