[vtkusers] Directed Graph Edges

Colin Myers glogboj at yahoo.co.uk
Sat Feb 27 21:17:33 EST 2010


>
> On Tue, Feb 23, 2010 at 9:30 AM, Jeff Baumes <jeff.baumes at kitware.com>wrote:
>
>
>>> Arrowheads are possible. Currently the functionality is not exposed in
>>> vtkGraphLayoutView, but it is possible to create your own actor. Here is the
>>> python code for doing it:
>>>
>>> from vtk import *
>>>
>>> # Make a small random graph and graph view.
>>> source = vtkRandomGraphSource()
>>> view = vtkGraphLayoutView()
>>>
>>> # Do layout manually before handing graph to the view.
>>> # This allows us to know the positions of edge arrows.
>>> layout = vtkGraphLayout()
>>> strategy = vtkSimple2DLayoutStrategy()
>>> layout.SetInputConnection(source.GetOutputPort())
>>> layout.SetLayoutStrategy(strategy);
>>> view.SetLayoutStrategyToPassThrough()
>>>
>>> # Add the graph to the view. This will render vertices and edges,
>>> # but not edge arrows.
>>> view.AddRepresentationFromInputConnection(layout.GetOutputPort())
>>>
>>> # Manually create an actor containing the glyphed arrows.
>>> graphToPoly = vtkGraphToPolyData()
>>> graphToPoly.SetInputConnection(layout.GetOutputPort())
>>> graphToPoly.EdgeGlyphOutputOn()
>>>
>>> # Set the position (0: edge start, 1: edge end) where
>>> # the edge arrows should go.
>>> graphToPoly.SetEdgeGlyphPosition(0.8)
>>>
>>> # Make a simple edge arrow for glyphing.
>>> arrowSource = vtkGlyphSource2D()
>>> arrowSource.SetGlyphTypeToEdgeArrow()
>>> arrowSource.SetScale(0.3)
>>>
>>> # Use Glyph3D to repeat the glyph on all edges.
>>> arrowGlyph = vtkGlyph3D()
>>> arrowGlyph.SetInputConnection(0, graphToPoly.GetOutputPort(1))
>>> arrowGlyph.SetInputConnection(1, arrowSource.GetOutputPort())
>>>
>>> # Add the edge arrow actor to the view.
>>> arrowMapper = vtkPolyDataMapper()
>>> arrowMapper.SetInputConnection(arrowGlyph.GetOutputPort())
>>> arrowActor = vtkActor()
>>> arrowActor.SetMapper(arrowMapper)
>>> view.GetRenderer().AddActor(arrowActor)
>>>
>>> # Start interaction.
>>> view.ResetCamera()
>>> view.GetInteractor().Start()
>>>
>>> Jeff
>>>
>>>
>>   
> I tried to port this to c++:
> http://www.vtk.org/Wiki/VTK/Examples/Graphs/VisualizeDirectedGraph
>
> but something didn't translate.
>
> Thoughts?
>
> David
>

Thanks very much for your help on this.

I tweaked your example (attached) by reducing the scaling of the glyph and adding an extra vertex. With just two vertices the vtkGraphLayoutView turns parallel edges into arcs by default. Setting the EdgeLayoutStrategy to PassThrough (rather than ArcParallel) works fine but we lose the nice curves.

Regards,
Colin


      
-------------- next part --------------
A non-text attachment was scrubbed...
Name: VisualizeDirectedGraph.cxx
Type: text/x-c
Size: 3095 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100228/79706bf2/attachment.bin>


More information about the vtkusers mailing list