[vtkusers] Directed Graph Edges

Jeff Baumes jeff.baumes at kitware.com
Tue Feb 23 09:30:12 EST 2010


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

On Mon, Feb 22, 2010 at 2:54 PM, David Doria
<daviddoria+vtk at gmail.com<daviddoria%2Bvtk at gmail.com>
> wrote:

> On Fri, Feb 19, 2010 at 8:39 AM, JO BLOGGS <glogboj at yahoo.co.uk> wrote:
>
>>   I am using vtkGraphLayoutView to visualize a vtkDirectedGraph. How do I
>> get the view to show me the directions of edges (i.e. arrowheads or colour
>> change)?
>>
>> Many thanks for your advice,
>> Colin
>>
>>
>>
> It seems reasonable to indicate the direction of the edges with arrows. I
> also don't see any option for this. Anyone know if this is possible?
>
> Thanks,
>
> David
>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at:
> http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>
>


-- 
Jeff Baumes, Ph.D.
R&D Engineer, Kitware Inc.
(518) 881-4932
jeff.baumes at kitware.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100223/20c4990e/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: EdgeArrows.png
Type: image/png
Size: 5881 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100223/20c4990e/attachment.png>


More information about the vtkusers mailing list