I’m trying to improve my understanding of both paraview and vtk’s python module by generating small point sets and viewing them in paraview using the Trivial Producer. I succeed in getting points drawn to the screen with this code when I use
Run Script in paraview, but there’s no clear way to see the scalar data set on the points.
import numpy as np from paraview.simple import * import paraview.vtk as vtk from paraview.vtk.numpy_interface import dataset_adapter as dsa import paraview.vtk.util.numpy_support as vnp node = np.array( [[0.0, 0.0, 0.0], [1.0, 0.0, 0.0], [1.0, 1.0, 0.0], [0.0, 1.0, 0.0]], dtype=np.float) NC = cell.shape points = vtk.vtkPoints() points.SetData(vnp.numpy_to_vtk(node)) vpoly = vtk.vtkPolyData() vpoly.SetPoints(points) # create scalars s = vtk.vtkFloatArray() s.InsertTuple1(0,20.0) s.InsertTuple1(1,30.0) s.InsertTuple1(2,50.0) s.InsertTuple1(3,50.0) vcells = vtk.vtkCellArray() for i in range(node.shape): vcells.InsertNextCell(1) vcells.InsertCellPoint(i) vpoly.SetVerts(vcells) vpoly.GetPointData().SetScalars(s) # how to put uGrid into the following codes view = GetActiveViewOrCreate('RenderView') # create a trivial producer to bridge between the VTK object and ParaView tp = TrivialProducer() tp.GetClientSideObject().SetOutput(vpoly) dispaly = Show(tp) #Interact()
Funnily enough if I use the vtp extractor then I can open a resulting vtp file and see the scalar data, but I’d prefer not to do those several extra steps just to view some small changes in the values I write in the python script.
Here’s what things look like in paraview. I’m unsure if the error that comes up is related to the missing data displayed
So the question is, how can I use trivial producer to show scalar data on a vtkPolyData object I’ve written from scratch? In a larger sense this question is also asking “what is the preferred way to use vtk and paraview scripting together?”
Thanks for any support on this matter!