<font size=2 face="sans-serif">In case this subject is eventually interesting
to anyone else, below is basic GraphToTable function. (Thanks Jeff/Brian
for your inputs)</font>
<br>
<br><font size=2 face="sans-serif">vtkTable *createTableFromGraph(vtkGraph
*graph)</font>
<br><font size=2 face="sans-serif">{</font>
<br><font size=2 face="sans-serif"> vtkTable
*myTable = vtkTable::New();</font>
<br><font size=2 face="sans-serif"> //Create
a column named "NodeId"</font>
<br><font size=2 face="sans-serif"> vtkStringArray
*colNodeId = vtkStringArray::New();</font>
<br><font size=2 face="sans-serif"> colNodeId->SetName("NodeId");</font>
<br><font size=2 face="sans-serif"> myTable->AddColumn(colNodeId);</font>
<br><font size=2 face="sans-serif"> //Create
columns named "X", "Y" and "Z"</font>
<br><font size=2 face="sans-serif"> vtkFloatArray
*colX = vtkFloatArray::New();</font>
<br><font size=2 face="sans-serif"> colX->SetName("X");</font>
<br><font size=2 face="sans-serif"> myTable->AddColumn(colX);</font>
<br><font size=2 face="sans-serif"> vtkFloatArray
*colY = vtkFloatArray::New();</font>
<br><font size=2 face="sans-serif"> colY->SetName("Y");</font>
<br><font size=2 face="sans-serif"> myTable->AddColumn(colY);</font>
<br><font size=2 face="sans-serif"> vtkFloatArray
*colZ = vtkFloatArray::New();</font>
<br><font size=2 face="sans-serif"> colZ->SetName("Z");</font>
<br><font size=2 face="sans-serif"> myTable->AddColumn(colZ);</font>
<br>
<br><font size=2 face="sans-serif"> //Fill
the table with data from the graph vertices</font>
<br><font size=2 face="sans-serif"> vtkVertexListIterator
*vertices = vtkVertexListIterator::New();</font>
<br><font size=2 face="sans-serif"> graph->GetVertices(vertices);</font>
<br><font size=2 face="sans-serif"> double
position[3] = {0.0, 0.0, 0.0};</font>
<br><font size=2 face="sans-serif"> vtkIdType
i = 0;</font>
<br><font size=2 face="sans-serif"> while
(vertices->HasNext())</font>
<br><font size=2 face="sans-serif"> {</font>
<br><font size=2 face="sans-serif">
vertices->Next();</font>
<br><font size=2 face="sans-serif">
//Add the vertex ID to the "NodeId"
column</font>
<br><font size=2 face="sans-serif">
char vertexId[10];</font>
<br><font size=2 face="sans-serif">
sprintf(vertexId, "%d",i); //Convert
the vertex ID to a string</font>
<br><font size=2 face="sans-serif">
colNodeId->InsertNextValue( vertexId );</font>
<br><font size=2 face="sans-serif">
//Add the position values to columns "X",
"Y" and "Z"</font>
<br><font size=2 face="sans-serif">
graph->GetPoint(i, position);</font>
<br><font size=2 face="sans-serif">
colX->InsertNextValue( position[0] );</font>
<br><font size=2 face="sans-serif">
colY->InsertNextValue( position[1] );</font>
<br><font size=2 face="sans-serif">
colZ->InsertNextValue( position[2] );</font>
<br><font size=2 face="sans-serif">
++i;</font>
<br><font size=2 face="sans-serif"> }</font>
<br><font size=2 face="sans-serif"> return
myTable;</font>
<br><font size=2 face="sans-serif">}</font>
<br>
<br><font size=2 face="sans-serif">Cheers,</font>
<br>
<br><font size=2 face="sans-serif">JB</font>
<br>
<br>
<br>
<table width=100%>
<tr valign=top>
<td><font size=1 color=#5f5f5f face="sans-serif">From:</font>
<td><font size=1 face="sans-serif">Jeff Baumes <jeff.baumes@kitware.com></font>
<tr valign=top>
<td><font size=1 color=#5f5f5f face="sans-serif">To:</font>
<td><font size=1 face="sans-serif">Jason BELLONE <JBELLONE@unog.ch></font>
<tr>
<td valign=top><font size=1 color=#5f5f5f face="sans-serif">Cc:</font>
<td><font size=1 face="sans-serif">vtkusers@vtk.org</font>
<tr valign=top>
<td><font size=1 color=#5f5f5f face="sans-serif">Date:</font>
<td><font size=1 face="sans-serif">19/04/2010 16:47</font>
<tr valign=top>
<td><font size=1 color=#5f5f5f face="sans-serif">Subject:</font>
<td><font size=1 face="sans-serif">Re: [vtkusers] vtkGraphToTable</font></table>
<br>
<hr noshade>
<br>
<br>
<br><tt><font size=2>You are right that vtkDataObjectToTable will not transfer
points to<br>
the table, because points are treated as a special array outside the<br>
point (or vertex) data. It would be great to see a "TransferPoints"<br>
option to vtkDataObjectToTable to take care of this case.<br>
<br>
Jeff<br>
<br>
On Fri, Apr 16, 2010 at 1:14 PM, Jason BELLONE <JBELLONE@unog.ch>
wrote:<br>
> Thanks Brian,<br>
><br>
> I really appreciate your suggestions! Please forgive my ignorance,
but I'm a<br>
> bit unclear on parameterizing vtkDataObjectToTable. Using the<br>
> vtkRandomGraphSource->vtkGraphLayout->vtkDataObjectToTable->vtkTableWriter<br>
> pipeline, I get only a list of vertexIds (with SetFieldType(3)) -
but no<br>
> coordinates (posX, posY, posZ).<br>
><br>
> P.S. I'm using VisTrails to simulate which doesn't have<br>
> vtkDelimitedTextWriter<br>
><br>
> For some background, the reason we're following this approach is to
use vtk<br>
> to produce graph data models as vtkTables. The table is used as source
for a<br>
> 3d game engine (OGRE) where the id, x, y, z records are used to generate<br>
> null 3d points. Game assets are then attached to these points.<br>
><br>
> Thank you very much for the assistance,<br>
><br>
> JB<br>
><br>
> _______________________________________________<br>
> Powered by </font></tt><a href=www.kitware.com><tt><font size=2>www.kitware.com</font></tt></a><tt><font size=2><br>
><br>
> Visit other Kitware open-source projects at<br>
> </font></tt><a href=http://www.kitware.com/opensource/opensource.html><tt><font size=2>http://www.kitware.com/opensource/opensource.html</font></tt></a><tt><font size=2><br>
><br>
> Please keep messages on-topic and check the VTK FAQ at:<br>
> </font></tt><a href=http://www.vtk.org/Wiki/VTK_FAQ><tt><font size=2>http://www.vtk.org/Wiki/VTK_FAQ</font></tt></a><tt><font size=2><br>
><br>
> Follow this link to subscribe/unsubscribe:<br>
> </font></tt><a href=http://www.vtk.org/mailman/listinfo/vtkusers><tt><font size=2>http://www.vtk.org/mailman/listinfo/vtkusers</font></tt></a><tt><font size=2><br>
><br>
><br>
</font></tt>
<br>
<br>