[vtkusers] creating simple multi-triangle polydata
Liam Kurmos
quantum.leaf at googlemail.com
Fri Mar 12 07:08:34 EST 2010
Hi,
I have some triangle data i need to visualise to make sure it's correct.
I looked at http://www.vtk.org/Wiki/VTK/Examples/GeometricObjects/Display/Triangle
which adds a single vtkSmartPointer<vtkTriangle> triangle
to vtkSmartPointer<vtkCellArray> triangles.
I thought it would be straight forward to extend this to adding
multiple cells. I added all my points and then did:
for (int i=0;i<rsphere->n_faces;i++){
vtkSmartPointer<vtkTriangle> triangle = vtkSmartPointer<vtkTriangle>::New();
triangle->GetPointIds()->SetId ( i, rsphere->faces[i]);
triangle->GetPointIds()->SetId ( i+1, rsphere->faces[i+1] );
triangle->GetPointIds()->SetId ( i+2, rsphere->faces[i+2]);
triangles->InsertNextCell ( triangle );
}
however this segfaults on the second itteration. (a triangle is
produced if i only loop once).
Is this the correct approach? if so it must be my data that is causing
the segfault.
i think my point/index array data is correct. I changed the index from
rsphere->faces[...] to constants 0,1,2 but it still segfaults on the
second itteration.
please let me know if i am missing something. I couldn't find an
example for multiple triangles, but i can write want if desired.
I have the books at home so if this is covered there please let me
know and i'll look it up.
regards,
Liam
ps: small point but
http://www.vtk.org/Wiki/VTK/Examples/Triangle_GeometryPolygon
and
http://www.vtk.org/Wiki/VTK/Examples/GeometricObjects/TriangleOnData
seem to be almost identical to each other, the former has better
comments and the latter has defines an unused vtktriangle t.
More information about the vtkusers
mailing list