[vtkusers] Triangle Geometry and Vertices

David Gobbi david.gobbi at gmail.com
Sun Dec 12 10:43:36 EST 2010


On Sun, Dec 12, 2010 at 6:39 AM, Jim Peterson <jimcp at cox.net> wrote:

> Paulo,
> I am no Python expert, but if I understand the sequence of events, you
> should create the polydata object before writing the file.
>
> Hope that helps,
> Jim


What Jim said.  Also, the id list is never filled in.  The following code is
wrong:

ids = vtkIdList()
ids.SetNumberOfIds(3)

for i in xrange(3):
    ids.SetId(i, i)
    points.InsertNextPoint(X[i],Y[i],Z[i])
    vertices.InsertNextCell(ids)

To fix it, you have two choices.  You can have all three verts in the same
cell:

ids = vtkIdList()
ids.SetNumberOfIds(3)

for i in xrange(3):
    ids.SetId(i, i)
    points.InsertNextPoint(X[i],Y[i],Z[i])

vertices.InsertNextCell(ids)

Or you can have each vert in its own cell:

ids = vtkIdList()
ids.SetNumberOfIds(1)

for i in xrange(3):
    ids.SetId(0, i)
    points.InsertNextPoint(X[i],Y[i],Z[i])
    vertices.InsertNextCell(ids)

In the "for" loop, you were calling vertices.InsertNextCell(ids)
when "ids" still had some unititialized values, since the three
ids values were not filled in until the third loop iteration.

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


More information about the vtkusers mailing list