[vtkusers] Triangle Geometry and Vertices
David Gobbi
david.gobbi at gmail.com
Sun Dec 12 11:04:58 EST 2010
I'm going to throw in a little addition. You say "triangle verts" so
I'm guessing
you want your cells to be triangles, not verts. If that is the case,
the code you
really need is as follows:
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) # call for every cell, not for every point
polydata = vtkPolyData()
polydata.SetPoints(points)
polydata.SetPolys(vertices) # use SetPolys for triangles
polydata.Update()
The above code will create a polydata that has one triangle.
David
On Sun, Dec 12, 2010 at 8:43 AM, David Gobbi <david.gobbi at gmail.com> wrote:
>
> 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
More information about the vtkusers
mailing list