<div class="gmail_extra">Vertex (and edge) &quot;handles&quot; in VTK are simply indices that range from 0 to #verts - 1. To access properties, you must go to the vertex (and edge) data, which is simply a collection of arrays that should be the same length. The developer generally creates and fills these arrays manually, so some extra care is usually needed to make sure things match up correctly.</div>
<div class="gmail_extra"><br></div><div class="gmail_extra">When removing vertices or edges, the removed indices make &quot;holes&quot; in the vertex or edge data, which are filled by moving the highest-index vertices or edges to those indices. This means that vertex/edge &quot;handles&quot; may become invalid after each removal.</div>
<div class="gmail_extra"><br></div><div class="gmail_extra">Here is a python session that might clarify things some.<br><br>First, create a graph with three vertices (note AddVertex returns the created vertex index):</div>
<div class="gmail_extra"><br><div class="gmail_extra">&gt;&gt;&gt; import vtk</div><div class="gmail_extra">&gt;&gt;&gt; g = vtk.vtkMutableDirectedGraph()</div><div class="gmail_extra">&gt;&gt;&gt; g.AddVertex()</div><div class="gmail_extra">
0L</div><div class="gmail_extra">&gt;&gt;&gt; g.AddVertex()</div><div class="gmail_extra">1L</div><div class="gmail_extra">&gt;&gt;&gt; g.AddVertex()</div><div class="gmail_extra">2L</div><div class="gmail_extra"><br></div>
<div class="gmail_extra">Create a name property and fill it with three values to match the three vertices:</div><div class="gmail_extra"><br></div><div class="gmail_extra">&gt;&gt;&gt; name = vtk.vtkStringArray()</div><div class="gmail_extra">
&gt;&gt;&gt; name.InsertNextValue(&quot;a&quot;)</div><div class="gmail_extra">0L</div><div class="gmail_extra">&gt;&gt;&gt; name.InsertNextValue(&quot;b&quot;)</div><div class="gmail_extra">1L</div><div class="gmail_extra">
&gt;&gt;&gt; name.InsertNextValue(&quot;c&quot;)</div><div class="gmail_extra">2L</div><div class="gmail_extra"><br></div><div class="gmail_extra">Give the property a name and add to vertex data:</div><div class="gmail_extra">
&gt;&gt;&gt; name.SetName(&quot;name&quot;)</div><div class="gmail_extra">&gt;&gt;&gt; g.GetVertexData().AddArray(name)</div><div class="gmail_extra"><br></div><div class="gmail_extra">Test that removing vertex 0 (named &quot;a&quot;) decreases the length of our property array and moves vertex 2 (named &quot;c&quot;) to position 0:</div>
<div class="gmail_extra">&gt;&gt;&gt; name.GetNumberOfTuples()</div><div class="gmail_extra">3L</div><div class="gmail_extra">&gt;&gt;&gt; g.RemoveVertex(0)</div><div class="gmail_extra">&gt;&gt;&gt; name.GetNumberOfTuples()</div>
<div class="gmail_extra">2L</div><div class="gmail_extra">&gt;&gt;&gt; name.GetValue(0)</div><div class="gmail_extra">&#39;c&#39;</div><div class="gmail_extra">&gt;&gt;&gt; name.GetValue(1)</div><div class="gmail_extra">&#39;b&#39;</div>
<div><br></div><div class="gmail_quote">On Mon, Apr 23, 2012 at 7:56 PM, planar3d <span dir="ltr">&lt;<a href="mailto:planar3d@gmail.com" target="_blank">planar3d@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I can&#39;t figure out how to do this. I have a vtkgraph and I need to be able to<br>
get a vertex by its unique identifier (aka vtkIdType) and add<br>
properties/fields like an int or a string to it. I need to be able to modify<br>
these fields as I pass through the graph and perform various transformations<br>
on it like adding and deleting nodes.<br>
<br>
As far as I can tell, you can sort of define fields by declaring these<br>
property arrays as seen in the example here:<br>
<a href="http://www.vtk.org/Wiki/VTK/Examples/Cxx/Graphs/LabelVerticesAndEdges" target="_blank">http://www.vtk.org/Wiki/VTK/Examples/Cxx/Graphs/LabelVerticesAndEdges</a><br>
<br>
The problem with this is I see no correlation/synchronization between the<br>
nodes/vertexID and these property arrays. The arrays have to be created up<br>
front and then added to the vtkgraph. So I declare an array of NumVertices,<br>
call it &quot;weights&quot; or &quot;color&quot; and then add it to the graph but what happens<br>
when I call vtkgraph.removeVertex(ID)? A vertex is deleted but that array is<br>
still NumVertices in size. Does the removeVertex function also delete the<br>
corresponding vertex entry in array? I see no enforcement of this in<br>
documentation? Do I have to manually update the property arrays whenever I<br>
remove a vertex?<br>
<br>
Also, I see no vtkgraph.getVertex(vtkIdType id) function and I see no way to<br>
modify the properties/attributes of that vertex even if I had a handle to<br>
said vertex. The GetVertexData function returns a vtkDataSetAttributes<br>
array. I don&#39;t need a giant attributes array for all the vertices. I just<br>
want the properties/attributes for one vertex so I can change/update some of<br>
the values of those attributes.<br>
<br>
--<br>
View this message in context: <a href="http://vtk.1045678.n5.nabble.com/vtkgraph-and-adding-properties-fields-to-a-vertex-node-tp5660744p5660744.html" target="_blank">http://vtk.1045678.n5.nabble.com/vtkgraph-and-adding-properties-fields-to-a-vertex-node-tp5660744p5660744.html</a><br>

Sent from the VTK - Users mailing list archive at Nabble.com.<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><br></div>