<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1250">
</head>
<body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; color: rgb(0, 0, 0); font-size: 14px; font-family: Georgia, sans-serif; ">
<div>Thanks Jeff – that worked, I appreciate it.</div>
<div><br>
</div>
<div>If anyone was interested, this works with vtkpython (VTK 6.0):</div>
<div><br>
</div>
<div>
<div>import vtk</div>
<div><br>
</div>
<div>g = vtk.vtkMutableDirectedGraph()</div>
<div><br>
</div>
<div>verts = [g.AddVertex() for i in range(3)]</div>
<div><br>
</div>
<div>g.AddGraphEdge(verts[0], verts[1])</div>
<div>g.AddGraphEdge(verts[1], verts[2])</div>
<div>g.AddGraphEdge(verts[2], verts[0])</div>
<div><br>
</div>
<div>g_layout = vtk.vtkGraphLayout()</div>
<div>g_layout.SetInputData(g)</div>
<div>g_layout.SetLayoutStrategy(vtk.vtkSimple2DLayoutStrategy())</div>
<div><br>
</div>
<div># Do layout manually before handing graph to the view. This allows us to know</div>
<div># the positions of the edge arrows.</div>
<div>g_layout_v = vtk.vtkGraphLayoutView()</div>
<div><br>
</div>
<div># Tell the view to use the vertex layout we provide.</div>
<div>g_layout_v.SetLayoutStrategyToPassThrough()</div>
<div><br>
</div>
<div># The arrows will be positioned on a straight line between the two vertices so</div>
<div># tell the view not to draw arcs for the parallel edges.</div>
<div>g_layout_v.SetEdgeLayoutStrategyToPassThrough()</div>
<div><br>
</div>
<div># Add the graph to the view. This will render vertices and edges, but not the</div>
<div># edge arrows.</div>
<div>g_layout_v.AddRepresentationFromInputConnection(g_layout.GetOutputPort())</div>
<div><br>
</div>
<div># Manually create an actor containing the glyphed arrows.</div>
<div>g2pd = vtk.vtkGraphToPolyData()</div>
<div>g2pd.SetInputConnection(g_layout.GetOutputPort())</div>
<div>g2pd.EdgeGlyphOutputOn()</div>
<div><br>
</div>
<div># Set the position (0: edge start, 1: edge end) where the edge arrows should</div>
<div># go.</div>
<div>g2pd.SetEdgeGlyphPosition(0.98)</div>
<div><br>
</div>
<div># Make a simple edge arrow for glyphing.</div>
<div>arrow = vtk.vtkGlyphSource2D()</div>
<div>arrow.SetGlyphTypeToEdgeArrow()</div>
<div>arrow.SetScale(0.1)</div>
<div>arrow.Update() # necessary?</div>
<div><br>
</div>
<div># Use a vtkGlyph3D to repeat the glyph on all edges.</div>
<div>glyph = vtk.vtkGlyph3D()</div>
<div>glyph.SetInputConnection(0, g2pd.GetOutputPort(1)) # what?</div>
<div>glyph.SetInputConnection(1, arrow.GetOutputPort())</div>
<div><br>
</div>
<div>mapper = vtk.vtkPolyDataMapper()</div>
<div>mapper.SetInputConnection(glyph.GetOutputPort())</div>
<div><br>
</div>
<div>actor = vtk.vtkActor()</div>
<div>actor.SetMapper(mapper)</div>
<div><br>
</div>
<div>g_layout_v.GetRenderer().AddActor(actor)</div>
<div>g_layout_v.ResetCamera()</div>
<div>g_layout_v.Render()</div>
<div>g_layout_v.GetInteractor().Start()</div>
</div>
<div><br>
</div>
<span id="OLK_SRC_BODY_SECTION">
<div style="font-family:Calibri; font-size:11pt; text-align:left; color:black; BORDER-BOTTOM: medium none; BORDER-LEFT: medium none; PADDING-BOTTOM: 0in; PADDING-LEFT: 0in; PADDING-RIGHT: 0in; BORDER-TOP: #b5c4df 1pt solid; BORDER-RIGHT: medium none; PADDING-TOP: 3pt">
<span style="font-weight:bold">From: </span>Jeff Baumes <<a href="mailto:jeff.baumes@kitware.com">jeff.baumes@kitware.com</a>><br>
<span style="font-weight:bold">Date: </span>Thursday, November 7, 2013 3:53 PM<br>
<span style="font-weight:bold">To: </span>Tim Meehan <<a href="mailto:meehanbt@nv.doe.gov">meehanbt@nv.doe.gov</a>><br>
<span style="font-weight:bold">Cc: </span>"<a href="mailto:vtkusers@vtk.org">vtkusers@vtk.org</a>" <<a href="mailto:vtkusers@vtk.org">vtkusers@vtk.org</a>><br>
<span style="font-weight:bold">Subject: </span>Re: [vtkusers] vtkMutableDirectedGraph and Python<br>
</div>
<div><br>
</div>
<div>
<div>In recent VTK, SetInput has been superceeded by SetInputData. Try using that method name and it should work for you.
<div><br>
</div>
<div>Jeff<span></span><br>
<br>
On Thursday, November 7, 2013, Meehan, Bernard wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I was trying to convert some of the C++ examples into python, mostly so<br>
that I could learn about how all of the classes work together, and can't<br>
seem to get a vtkMutableDirectedGraph hooked up with a vtkGraphLayout in a<br>
pipeline Š the original code was here<br>
(<a href="http://www.vtk.org/Wiki/VTK/Examples/Cxx/Graphs/VisualizeDirectedGraph" target="_blank">http://www.vtk.org/Wiki/VTK/Examples/Cxx/Graphs/VisualizeDirectedGraph</a>).<br>
<br>
Here is what I had done in Python:<br>
import vtk<br>
<br>
g = vtk.vtkMutableDirectedGraph()<br>
<br>
verts = [g.AddVertex() for i in range(4)]<br>
<br>
g.AddGraphEdge(verts[0], verts[1])<br>
g.AddGraphEdge(verts[1], verts[2])<br>
g.AddGraphEdge(verts[2], verts[0])<br>
<br>
g_layout = vtk.vtkGraphLayout()<br>
# If I uncomment this line and run, I get the following error:<br>
# TypeError: SetInputConnection argument 1: method requires a<br>
vtkAlgorithmOutput, a vtkMutableDirectedGraph was provided.<br>
# g_layout.SetInputConnection(g)<br>
<br>
# If I uncomment this line and run, I get the following error:<br>
# AttributeError: SetInput<br>
# g_layout.SetInput(g)<br>
<br>
# ?? any ideas on how to hook these up ??<br>
<br>
g_layout.SetLayoutStrategy(vtk.vtkSimple2DLayoutStrategy())<br>
<br>
# Do layout manually before handing graph to the view. This allows us to<br>
know<br>
# the positions of the edge arrows.<br>
g_layout_v = vtk.vtkGraphLayoutView()<br>
<br>
# Tell the view to use the vertex layout we provide.<br>
g_layout_v.SetStrategyToPassThrough()<br>
<br>
# The arrows will be positioned on a straight line between the two<br>
vertices so<br>
# tell the view not to draw arcs for the parallel edges.<br>
g_layout_v.SetEdgeLayoutStrategyToPassThrough()<br>
<br>
# Add the graph to the view. This will render vertices and edges, but not<br>
the<br>
# edge arrows.<br>
g_layout_v.AddRepresentationFromInputConnection(g_layout.GetOutputPort())<br>
<br>
# Manually create an actor containing the glyphed arrows.<br>
g2pd = vtk.vtkGraphToPolyData()<br>
g2pd.SetInputConnection(g_layout.GetOutputPort())<br>
g2pd.EdgeGlyphOutputOn()<br>
<br>
# Set the position (0: edge start, 1: edge end) where the edge arrows<br>
should<br>
# go.<br>
g2pd.SetEdgeGlyphPosition(0.98)<br>
<br>
# Make a simple edge arrow for glyphing.<br>
arrow = vtk.vtkArrowSource()<br>
arrow.SetGlyphTypeToEdgeArrow()<br>
arrow.SetScale(0.1)<br>
arrow.Update() # necessary?<br>
<br>
# Use a vtkGlyph3D to repeat the glyph on all edges.<br>
glyph = vtk.vtkGlyph3D()<br>
glyph.SetInputConnection(0, g2pd.GetOutputPort(1)) # what?<br>
glyph.SetInputConnection(1, arrow.GetOutputPort())<br>
<br>
mapper = vtk.vtkPolyDataMapper()<br>
mapper.SetInputConnection(glyph.GetOutputPort())<br>
<br>
actor = vtk.vtkActor()<br>
actor.SetMapper(mapper)<br>
<br>
g_layout_v.ResetCamera()<br>
g_layout_v.Render()<br>
g_layout_v.GetInteractor().Start()<br>
<br>
<br>
<br>
_______________________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">
http://www.kitware.com/opensource/opensource.html</a><br>
<br>
Please keep messages on-topic and check the VTK FAQ at: <a href="http://www.vtk.org/Wiki/VTK_FAQ" target="_blank">
http://www.vtk.org/Wiki/VTK_FAQ</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.vtk.org/mailman/listinfo/vtkusers" target="_blank">http://www.vtk.org/mailman/listinfo/vtkusers</a><br>
</blockquote>
</div>
</div>
</div>
</span>
</body>
</html>