[vtkusers] vtkGraphToTable
Jason BELLONE
JBELLONE at unog.ch
Mon Apr 19 10:57:28 EDT 2010
In case this subject is eventually interesting to anyone else, below is
basic GraphToTable function. (Thanks Jeff/Brian for your inputs)
vtkTable *createTableFromGraph(vtkGraph *graph)
{
vtkTable *myTable = vtkTable::New();
//Create a column named "NodeId"
vtkStringArray *colNodeId = vtkStringArray::New();
colNodeId->SetName("NodeId");
myTable->AddColumn(colNodeId);
//Create columns named "X", "Y" and "Z"
vtkFloatArray *colX = vtkFloatArray::New();
colX->SetName("X");
myTable->AddColumn(colX);
vtkFloatArray *colY = vtkFloatArray::New();
colY->SetName("Y");
myTable->AddColumn(colY);
vtkFloatArray *colZ = vtkFloatArray::New();
colZ->SetName("Z");
myTable->AddColumn(colZ);
//Fill the table with data from the graph vertices
vtkVertexListIterator *vertices = vtkVertexListIterator::New();
graph->GetVertices(vertices);
double position[3] = {0.0, 0.0, 0.0};
vtkIdType i = 0;
while (vertices->HasNext())
{
vertices->Next();
//Add the vertex ID to the "NodeId" column
char vertexId[10];
sprintf(vertexId, "%d",i); //Convert the vertex ID to a
string
colNodeId->InsertNextValue( vertexId );
//Add the position values to columns "X", "Y" and "Z"
graph->GetPoint(i, position);
colX->InsertNextValue( position[0] );
colY->InsertNextValue( position[1] );
colZ->InsertNextValue( position[2] );
++i;
}
return myTable;
}
Cheers,
JB
From:
Jeff Baumes <jeff.baumes at kitware.com>
To:
Jason BELLONE <JBELLONE at unog.ch>
Cc:
vtkusers at vtk.org
Date:
19/04/2010 16:47
Subject:
Re: [vtkusers] vtkGraphToTable
You are right that vtkDataObjectToTable will not transfer points to
the table, because points are treated as a special array outside the
point (or vertex) data. It would be great to see a "TransferPoints"
option to vtkDataObjectToTable to take care of this case.
Jeff
On Fri, Apr 16, 2010 at 1:14 PM, Jason BELLONE <JBELLONE at unog.ch> wrote:
> Thanks Brian,
>
> I really appreciate your suggestions! Please forgive my ignorance, but
I'm a
> bit unclear on parameterizing vtkDataObjectToTable. Using the
>
vtkRandomGraphSource->vtkGraphLayout->vtkDataObjectToTable->vtkTableWriter
> pipeline, I get only a list of vertexIds (with SetFieldType(3)) - but no
> coordinates (posX, posY, posZ).
>
> P.S. I'm using VisTrails to simulate which doesn't have
> vtkDelimitedTextWriter
>
> For some background, the reason we're following this approach is to use
vtk
> to produce graph data models as vtkTables. The table is used as source
for a
> 3d game engine (OGRE) where the id, x, y, z records are used to generate
> null 3d points. Game assets are then attached to these points.
>
> Thank you very much for the assistance,
>
> JB
>
> _______________________________________________
> 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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100419/8ffece4e/attachment.htm>
More information about the vtkusers
mailing list