<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii"><meta name=Generator content="Microsoft Word 15 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:11.0pt;
font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:#0563C1;
text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
{mso-style-priority:99;
color:#954F72;
text-decoration:underline;}
span.EmailStyle17
{mso-style-type:personal-compose;
font-family:"Calibri","sans-serif";
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri","sans-serif";}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-US link="#0563C1" vlink="#954F72"><div class=WordSection1><p class=MsoNormal>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.<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>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. <o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>I need the polygons that make up the bands for another application, that is why I’m using it.<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>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:<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>>>>>>>>>>>>>>>>>>><o:p> </o:p></p><p class=MsoNormal>#!/usr/bin/env python<o:p></o:p></p><p class=MsoNormal>import vtk<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>from vtk import *<o:p></o:p></p><p class=MsoNormal> <o:p></o:p></p><p class=MsoNormal># The source file<o:p></o:p></p><p class=MsoNormal>file_name = "tt1.vtk"<o:p></o:p></p><p class=MsoNormal> <o:p></o:p></p><p class=MsoNormal># Read the source file.<o:p></o:p></p><p class=MsoNormal>reader = vtkUnstructuredGridReader()<o:p></o:p></p><p class=MsoNormal>reader.SetFileName(file_name)<o:p></o:p></p><p class=MsoNormal>reader.Update() # Needed because of GetScalarRange<o:p></o:p></p><p class=MsoNormal>output = reader.GetOutput()<o:p></o:p></p><p class=MsoNormal>scalar_range = output.GetScalarRange()<o:p></o:p></p><p class=MsoNormal> <o:p></o:p></p><p class=MsoNormal># Create the mapper that corresponds the objects of the vtk file<o:p></o:p></p><p class=MsoNormal># into graphics elements<o:p></o:p></p><p class=MsoNormal>mapper = vtkDataSetMapper()<o:p></o:p></p><p class=MsoNormal>mapper.SetInputConnection(reader.GetOutputPort())<o:p></o:p></p><p class=MsoNormal>mapper.SetScalarRange(scalar_range)<o:p></o:p></p><p class=MsoNormal> <o:p></o:p></p><p class=MsoNormal># Create the Actor for the mesh (actor)<o:p></o:p></p><p class=MsoNormal>actor = vtkActor()<o:p></o:p></p><p class=MsoNormal>actor.SetMapper(mapper)<o:p></o:p></p><p class=MsoNormal>#actor.GetProperty().EdgeVisibilityOn()<o:p></o:p></p><p class=MsoNormal>#actor.GetProperty().SetEdgeColor(0,0,0)<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>#Now build up the stuff for just the edges<o:p></o:p></p><p class=MsoNormal>edges = vtkExtractEdges()<o:p></o:p></p><p class=MsoNormal>edges.SetInputConnection(reader.GetOutputPort())<o:p></o:p></p><p class=MsoNormal>edge_mapper = vtkPolyDataMapper()<o:p></o:p></p><p class=MsoNormal>edge_mapper.SetInputConnection(edges.GetOutputPort())<o:p></o:p></p><p class=MsoNormal>edge_mapper.ScalarVisibilityOff()<o:p></o:p></p><p class=MsoNormal>edge_actor = vtkActor()<o:p></o:p></p><p class=MsoNormal>edge_actor.SetMapper(edge_mapper)<o:p></o:p></p><p class=MsoNormal>edge_actor.GetProperty().SetColor(0,0,0)<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>#Now try the contourFilter<o:p></o:p></p><p class=MsoNormal>cnt = vtkBandedPolyDataContourFilter() <o:p></o:p></p><p class=MsoNormal>cnt.SetInputConnection(reader.GetOutputPort())<o:p></o:p></p><p class=MsoNormal>cnt.SetScalarModeToValue()<o:p></o:p></p><p class=MsoNormal>cnt.GenerateContourEdgesOn()<o:p></o:p></p><p class=MsoNormal>cnt.GenerateValues(3,scalar_range)<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>mapper2=vtkPolyDataMapper()<o:p></o:p></p><p class=MsoNormal>mapper2.SetInputConnection(cnt.GetOutputPort())<o:p></o:p></p><p class=MsoNormal>actor2=vtkActor()<o:p></o:p></p><p class=MsoNormal>actor2.SetMapper(mapper2)<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal># Create the Renderer<o:p></o:p></p><p class=MsoNormal>renderer = vtkRenderer()<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>#renderer.AddActor(actor)<o:p></o:p></p><p class=MsoNormal>renderer.AddActor(edge_actor)<o:p></o:p></p><p class=MsoNormal>renderer.AddActor(actor2)<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>renderer.SetBackground(.9, .9, .9) # Set background to white<o:p></o:p></p><p class=MsoNormal> <o:p></o:p></p><p class=MsoNormal># Create the RendererWindow<o:p></o:p></p><p class=MsoNormal>renderer_window = vtkRenderWindow()<o:p></o:p></p><p class=MsoNormal>renderer_window.AddRenderer(renderer)<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal> <o:p></o:p></p><p class=MsoNormal># Create the RendererWindowInteractor and display the vtk_file<o:p></o:p></p><p class=MsoNormal>interactor = vtkRenderWindowInteractor()<o:p></o:p></p><p class=MsoNormal>interactor.SetRenderWindow(renderer_window)<o:p></o:p></p><p class=MsoNormal>interactor.Initialize()<o:p></o:p></p><p class=MsoNormal>interactor.Start()<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><<<<<<<<<<<<< End Code<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>------------------<o:p></o:p></p><p class=MsoNormal>Eric Miller<o:p></o:p></p><p class=MsoNormal>PADT, Inc.<o:p></o:p></p></div></body></html>