I'm trying to display an EnSight file in a Qt/VTK application. More precisely, I want to display a specific EnSight part and color it by the magnitude of one of the vector variables. As far as I understand, the output of the VTK reader is a vtkMultiBlockDataSet
, with one block per part. Each block is a vtkUnstructuredGrid
and the variables are specific arrays in the pointdata
.
The code I have so far is below. Unfortunately, it shows a uniform color (when the same file loaded in ParaView it shows some local variations).
Obviously I'm missing something, but I can't figure where. I'd be grateful for any hints.
casefile = "data/Results/exported/blahblah.case"
part_id = 0
var_id = 2
reader = vtk.vtkGenericEnSightReader()
reader.SetCaseFileName(casefile)
reader.Update()
# Color map
colormap = vtk.vtkLookupTable()
colormap.SetHueRange(0.667, 0.0)
colormap.SetVectorModeToMagnitude()
colormap.Build()
multiblock = reader.GetOutput()
ugrid = multiblock.GetBlock(part_id)
pointdata = ugrid.GetPointData()
data = pointdata.GetArray(var_id)
data_range = data.GetRange(-1)
mesh_mapper = vtk.vtkDataSetMapper()
mesh_mapper.SetInput(ugrid)
mesh_mapper.SetColorModeToDefault()
mesh_mapper.SetScalarRange(data_range)
mesh_mapper.SetScalarVisibility(True)
mesh_mapper.SetLookupTable(colormap)
#
mesh_actor = vtk.vtkActor()
mesh_actor.SetMapper(mesh_mapper)
mesh_actor.GetProperty().SetDiffuseColor(1., 1., 1.)
renderer = vtk.vtkRenderer()
renderer.AddActor(mesh_actor)
renderer.AddActor2D(colorbar)