[vtkusers] Vertex Labels with vtkGraphLayoutView

Don Pellegrino donpellegrino at live.com
Tue Mar 27 21:15:53 EDT 2012


Am I using the right commands to label vertices in a graph?
 
I created a vtkStringArray and assigned it to a vtkMutableUndirectedGraph's VertexData. I then called the vtkGraphLayoutView.VertexLabelVisibilityOn() method. Yet, when the graph is rendered I can only see the squares for the nodes and the lines for the edges. No labels are visible. Setting vtkGraphLayoutView.SetVertexLabelFontSize() to various values does not have any effect. Did I miss something in the following code that prevents the vertex labels from appearing?
 
No warnings or errors are reported during run-time.
 
ActiViz.NET 5.8.0 in a Visual Studio 2010 C# Console Application.
---

using System;
using Kitware.VTK;

namespace TitanToolkitTest
{
    class Program
    {
        static void Main(string[] args)
        {
            // Graph
            vtkMutableUndirectedGraph g = vtkMutableUndirectedGraph.New();
            int v1 = g.AddVertex();
            int v2 = g.AddVertex();
            int v3 = g.AddVertex(); 
            g.AddGraphEdge(v1, v2);
            g.AddGraphEdge(v2, v3);
            g.AddGraphEdge(v3, v1);

            // Vertex Labels
            vtkStringArray label = vtkStringArray.New();
            label.SetName("label");
            label.InsertNextValue("A"); // v1
            label.InsertNextValue("B"); // v2
            label.InsertNextValue("C"); // v3
            g.GetVertexData().AddArray(label); 

            // View
            vtkGraphLayoutView view = vtkGraphLayoutView.New();
            view.AddRepresentationFromInput(g);
            view.VertexLabelVisibilityOn();
            view.SetVertexLabelArrayName("label"); 
            view.Update();

            // Render
            vtkRenderWindow renWin = vtkRenderWindow.New(); 
            renWin.AddRenderer(view.GetRenderer());
            renWin.Render();
            
            // Interact
            vtkRenderWindowInteractor iren = vtkRenderWindowInteractor.New();
            iren.SetRenderWindow(renWin);
            iren.Initialize();
            iren.Start();
        }
    }
}
  		 	   		  


More information about the vtkusers mailing list