[vtkusers] XMLStructuredGridReader python 2 scalar phases
Alexandr Kuzmin
kuzmin at ualberta.ca
Thu Feb 3 00:14:19 EST 2011
Hello,
Could you please help me with the following issue:
I read my file data which contains two scalar fields with the velocity field. I want to create a contour filter to obtain a surface contour for a phase value 0.0. However, nothing works and not only for me (few of my friends tried to find a solution but without success). I tried to switch off other fields from the field data but it didn't help. Note that the same contour can be easily obtained by Paraview but not with python vtk.
Here is the snippet:
import vtk
import numpy
gridreader = vtk.vtkXMLStructuredGridReader()
gridreader.SetFileName(name)
#gridreader.SetPointArrayStatus("Density",0)
selection=gridreader.GetPointDataArraySelection()
selection.DisableArray("Density")
selection.DisableArray("Velocity")
gridreader.Update()
grid = gridreader.GetOutput()
data = grid.GetPointData()
points=grid.GetPoints()
dims =grid.GetDimensions()
phase= data.GetArray("Phase")
#velocity=data.GetArray("Velocity")
contour=vtk.vtkContourFilter()
contour.SetInputConnection(gridreader.GetOutputPort())
contour.SetValue(0,0.0)
#contour.GenerateValues(1, (0,0.01))
contourMapper = vtk.vtkPolyDataMapper()
#contourMapper.SetScalarRange(phase.GetRange())
contourMapper.SetInputConnection(contour.GetOutputPort())
stlActor = vtk.vtkActor()
stlActor.SetMapper(contourMapper)
ren = vtk.vtkRenderer()
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren)
iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renWin)
# Add the actors to the render; set the background and size
ren.AddActor(stlActor)
ren.SetBackground(1.0,1.0,1.0)
#ren.SetBackground(0.1, 0.2, 0.4)
renWin.SetSize(500, 500)
# Zoom in closer
ren.ResetCamera()
cam1 = ren.GetActiveCamera()
cam1.Zoom(1.4)
iren.Initialize()
renWin.Render()
iren.Start()
Thank you for your help,
Alex
More information about the vtkusers
mailing list