[vtkusers] No Contours for BandedPolyDataContourFilter()
Eric Miller
eric.miller at padtinc.com
Tue May 13 07:51:54 EDT 2014
Tried again at 3:30 in the morning and figured it out. I needed to convert my unstructured data into polydata with vtkGeomtryFilter
Then it all works. Here is the section of code that does it, creating a band for values between 5 and 20.
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
#make the geometry filter using my unstructured grid (reader) as the input
gf = vtkGeometryFilter()
gf.SetInputData(reader.GetOutput())
gf.Update();
#grab the polydata from the filter with GetOutput()
pd = vtkPolyData()
pd = gf.GetOutput()
#now apply the BandedPolyContourFilter to the polydata
cnt = vtkBandedPolyDataContourFilter()
cnt.SetInputData(pd)
#I just need polygons between two values, so I turn clipping on
cnt.ClippingOn()
cnt.GenerateValues(2,5.0, 20.0)
#map it (turn off the scalar, I just want to see the polys that are made)
mapper2=vtkPolyDataMapper()
mapper2.SetInputConnection(cnt.GetOutputPort())
mapper2.ScalarVisibilityOff()
#put that in an actor, setting the band I made to red
actor2=vtkActor()
actor2.SetMapper(mapper2)
actor2.GetProperty().SetColor(1,0,0)
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
As usual, trying to explain the problem helped me solve the problem.
Eric
PADT, Inc.
From: vtkusers [mailto:vtkusers-bounces at vtk.org] On Behalf Of Eric Miller
Sent: Monday, May 12, 2014 8:41 PM
To: vtkusers at vtk.org
Subject: [vtkusers] No Contours for BandedPolyDataContourFilter()
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/20140513/f7c6a67c/attachment-0001.html>
More information about the vtkusers
mailing list