[vtkusers] XMLStructuredGridReader python 2 scalar phases

Aurélien Marsan aur.marsan at gmail.com
Thu Feb 3 04:04:05 EST 2011


I don't use vtk for rendering, but have you try to make a

   contour.Update()
   print contour.GetOutput()

before the polydatamapper, and see if the bounds of the returned polydata
are correct, in order to localise if the issue is in the rendering code or
in the contourfilter/reader ?
2011/2/3 Alexandr Kuzmin <kuzmin at ualberta.ca>

> 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
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20110203/a586a141/attachment.htm>


More information about the vtkusers mailing list