[vtkusers] Extract field from .vtu file

Meehan, Bernard MEEHANBT at nv.doe.gov
Wed Jul 16 12:37:14 EDT 2014


Hi Hector - I'm far from an expert, and usually use ParaView for anything
complex.

I wasn't able to figure out anything as good as the slice tool in paraview
for instance, but this might get you going in the right direction. I have
a file with one vector stored in an XML unstructured grid that I did a few
things with:

import vtk

reader = vtk.vtkXMLUnstructuredGridReader()
reader.SetFileName("waveguide_h000022.vtu")
reader.SetPointArrayStatus("H", 1)

#------------------------#
# outline of the dataset #
#------------------------#
get_polydata = vtk.vtkGeometryFilter()
get_polydata.SetInputConnection(reader.GetOutputPort())

outline = vtk.vtkExtractEdges()
outline.SetInputConnection(get_polydata.GetOutputPort())

outline_mapper = vtk.vtkPolyDataMapper()
outline_mapper.SetInputConnection(outline.GetOutputPort())

outline_actor = vtk.vtkActor()
outline_actor.SetMapper(outline_mapper)
outline_actor.GetProperty().SetColor(0.5, 1.0, 0.5)
outline_actor.GetProperty().SetOpacity(0.25)

#---------------------------------------#
# clip with plane normal to z at origin #
#---------------------------------------#
plane = vtk.vtkPlane()
plane.SetOrigin(0.0, 0.0, 0.0)
plane.SetNormal(1.0, 0.0, 1.0)

# re-use the polydata created above
clipper = vtk.vtkClipPolyData()
clipper.SetInputConnection(get_polydata.GetOutputPort())
clipper.SetClipFunction(plane)
clipper.GenerateClipScalarsOn()
clipper.GenerateClippedOutputOn()
clipper.SetValue(0.0)

clip_mapper = vtk.vtkPolyDataMapper()
clip_mapper.SetInputConnection(clipper.GetOutputPort())

clip_actor = vtk.vtkActor()
clip_actor.SetMapper(clip_mapper)

#----------------------#
# vectors in the field #
#----------------------#
arrow = vtk.vtkArrowSource()
glyph_filter = vtk.vtkGlyph3D()
glyph_filter.SetSourceConnection(arrow.GetOutputPort())
glyph_filter.SetInputConnection(reader.GetOutputPort())
glyph_filter.SetScaleModeToScaleByVector()
glyph_filter.SetScaleFactor(0.0007)
glyph_filter.Update()

glyph_mapper = vtk.vtkDataSetMapper()
glyph_mapper.SetInputConnection(glyph_filter.GetOutputPort())

glyph_actor = vtk.vtkActor()
glyph_actor.SetMapper(glyph_mapper)

# --- #
ren = vtk.vtkRenderer()
ren.AddActor(outline_actor)
ren.AddActor(clip_actor)
ren.AddActor(glyph_actor)
ren.SetBackground(1.0, 1.0, 1.0)

renw = vtk.vtkRenderWindow()
renw.AddRenderer(ren)
renw.SetSize(640, 480)

iren = vtk.vtkRenderWindowInteractor()
iren.SetRenderWindow(renw)

renw.Render()
iren.Start()


From:  Hector Dejea <hectordejea at gmail.com>
Date:  Wednesday, July 16, 2014 2:18 AM
To:  "vtkusers at vtk.org" <vtkusers at vtk.org>
Subject:  [vtkusers]  Extract field from .vtu file


Hi all,


I am trying to visualize a field contained in a .vtu file but all I got is
a solid colored image. Does anybody know how to visualize the field on the
geometry?


Thank you




More information about the vtkusers mailing list