[vtkusers] creating simple multi-triangle polydata

David Doria daviddoria+vtk at gmail.com
Fri Mar 12 10:00:55 EST 2010


On Fri, Mar 12, 2010 at 7:08 AM, Liam Kurmos <quantum.leaf at googlemail.com>wrote:

> 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.
>
>
Shoudn't you have to use i+=3 instead of i++ to increment the loop counter?

Now you are getting

0, 1, 2
1, 2, 3

where you want

0, 1, 2
3, 4, 5

right?


Good point with the two examples. I removed the unused vtkTriangle t. I also
created this page:

http://www.vtk.org/Wiki/VTK/Tutorials/GeometryTopology

that is linked to from the Tutorials page. This way there are not links to
two similar examples from the Examples page. I also renamed those pages to
be in the Tutorials "directory".

Thanks,

David
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100312/c9c6f3d7/attachment.htm>


More information about the vtkusers mailing list