I am working on a Python script to process an OpenFOAM simulation automatically. I’d like to do in Python with vtk, because the rest of my post processing is also in Python. My goal is to render all the cutting planes I created in OpenFOAM in the vtk-format (shown in the following section) and to safe images of these planes in png-format or something similar. Currently my problem is that I don’t get the geometry coloured with the field data. The only thing I get is a grey representation of the planes geometry.
I am using version ‘8.2.0’ of vtk for Python.
The file I’d like to process looks like this: #vtk DataFile Version 2.0
sampleSurface
ASCII
DATASET POLYDATA
POINTS 3540 float
-0.0314316 0.00495 0.000881417 -0.031924 0.00495 0.000968241 -0.031924 0.00495 0.00102257 -0.0314316 0.00495 #many lines following with coordinates
0.02412 0.00495 -7.30676e-05 0.02484 0.00495 -0.0001 0.02556 0.00495 -0.0001
POLYGONS 3382 16910
4 0 1 2 3 4 4 0 3 5 4 #many lines following
POINT_DATA 3540
FIELD attributes 1
H2O 1 3540 float
0.042 0.042 0.042 0.042 0.042 0.042 0.042 0.042 0.042 0.042 0.042 #many lines with data following
My rendering code looks like this:
pathToPlane =‘pathToData’ #print(pathToPlane)
reader = vtk.vtkDataSetReader()
reader.SetFileName(pathToPlane)
reader.ReadAllScalarsOn()
reader.ReadAllColorScalarsOn()
reader.ReadAllNormalsOn()
reader.ReadAllTCoordsOn()
reader.ReadAllVectorsOn()
reader.Update() # Needed because of GetScalarRange
polydata = reader.GetOutput()
Hi, thanks for the link. Looks quite interesting.
I managed to find my error: My cutting plane only contains point data. Therefore the mapper must be set to mapper.SetScalarModeToUsePointFieldData()
The whole script with export of the screenshot looks like:
pathToPlane = casePath + ‘postProcessing/surfaces/’ + time + ‘/’ + fieldName + ‘_’ + cuttingPlaneName + ‘.vtk’ #print(pathToPlane)