[vtkusers] No Contours for BandedPolyDataContourFilter()

Eric Miller eric.miller at padtinc.com
Mon May 12 23:40:50 EDT 2014


I'm trying to do a simple tool using VTK that creates banded contours on my unstructured mesh.  As you can tell below, I'm new to VTK.  I'm using python as well.

I got the first bits to work: read my mesh with scalar data, plot it, etc... Now I've set it up to just show the edges of my mesh and banded contours.  But it is not working.  My scalar data looks good, if I turn the ScalarVisibilityOn() it looks like it should.

I need the polygons that make up the bands for another application, that is why I'm using it.

Cnt is my contour filter, mapper2, and actor2 are the mapper and actor for that data.  I'm hoping I'm making a simple mistake.  Here is the code:

>>>>>>>>>>>>>>>>>>
#!/usr/bin/env python
import vtk

from vtk import *
# The source file
file_name = "tt1.vtk"
# Read the source file.
reader = vtkUnstructuredGridReader()
reader.SetFileName(file_name)
reader.Update() # Needed because of GetScalarRange
output = reader.GetOutput()
scalar_range = output.GetScalarRange()
# Create the mapper that corresponds the objects of the vtk file
# into graphics elements
mapper = vtkDataSetMapper()
mapper.SetInputConnection(reader.GetOutputPort())
mapper.SetScalarRange(scalar_range)
# Create the Actor for the mesh (actor)
actor = vtkActor()
actor.SetMapper(mapper)
#actor.GetProperty().EdgeVisibilityOn()
#actor.GetProperty().SetEdgeColor(0,0,0)

#Now build up the stuff for just the edges
edges = vtkExtractEdges()
edges.SetInputConnection(reader.GetOutputPort())
edge_mapper = vtkPolyDataMapper()
edge_mapper.SetInputConnection(edges.GetOutputPort())
edge_mapper.ScalarVisibilityOff()
edge_actor = vtkActor()
edge_actor.SetMapper(edge_mapper)
edge_actor.GetProperty().SetColor(0,0,0)


#Now try the contourFilter
cnt = vtkBandedPolyDataContourFilter()
cnt.SetInputConnection(reader.GetOutputPort())
cnt.SetScalarModeToValue()
cnt.GenerateContourEdgesOn()
cnt.GenerateValues(3,scalar_range)

mapper2=vtkPolyDataMapper()
mapper2.SetInputConnection(cnt.GetOutputPort())
actor2=vtkActor()
actor2.SetMapper(mapper2)

# Create the Renderer
renderer = vtkRenderer()

#renderer.AddActor(actor)
renderer.AddActor(edge_actor)
renderer.AddActor(actor2)

renderer.SetBackground(.9, .9, .9) # Set background to white
# Create the RendererWindow
renderer_window = vtkRenderWindow()
renderer_window.AddRenderer(renderer)

# Create the RendererWindowInteractor and display the vtk_file
interactor = vtkRenderWindowInteractor()
interactor.SetRenderWindow(renderer_window)
interactor.Initialize()
interactor.Start()


<<<<<<<<<<<<< End Code




------------------
Eric Miller
PADT, Inc.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20140512/08ac0d5f/attachment.html>


More information about the vtkusers mailing list