Thank's David and Jim.<br><br>Generate a triangle is really what I wanted.<br><br>By the same token, there is some way from a vtkPolyData, generate a mesh of triangles more regular?<br><br>I would like to improve the mesh for use in finite elements.<br>
<br>Ragards,<br>Paulo<br><br><br><br><div class="gmail_quote">On 12 December 2010 14:04, David Gobbi <span dir="ltr"><<a href="mailto:david.gobbi@gmail.com">david.gobbi@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
I'm going to throw in a little addition. You say "triangle verts" so<br>
I'm guessing<br>
you want your cells to be triangles, not verts. If that is the case,<br>
the code you<br>
really need is as follows:<br>
<div class="im"><br>
ids = vtkIdList()<br>
ids.SetNumberOfIds(3)<br>
<br>
for i in xrange(3):<br>
ids.SetId(i, i)<br>
points.InsertNextPoint(X[i],Y[i],Z[i])<br>
<br>
</div> vertices.InsertNextCell(ids) # call for every cell, not for every point<br>
<div class="im"><br>
polydata = vtkPolyData()<br>
polydata.SetPoints(points)<br>
</div> polydata.SetPolys(vertices) # use SetPolys for triangles<br>
polydata.Update()<br>
<br>
The above code will create a polydata that has one triangle.<br>
<font color="#888888"><br>
David<br>
</font><div><div></div><div class="h5"><br>
<br>
On Sun, Dec 12, 2010 at 8:43 AM, David Gobbi <<a href="mailto:david.gobbi@gmail.com">david.gobbi@gmail.com</a>> wrote:<br>
><br>
> On Sun, Dec 12, 2010 at 6:39 AM, Jim Peterson <<a href="mailto:jimcp@cox.net">jimcp@cox.net</a>> wrote:<br>
>><br>
>> Paulo,<br>
>> I am no Python expert, but if I understand the sequence of events, you should create the polydata object before writing the file.<br>
>><br>
>> Hope that helps,<br>
>> Jim<br>
><br>
> What Jim said. Also, the id list is never filled in. The following code is wrong:<br>
><br>
> ids = vtkIdList()<br>
> ids.SetNumberOfIds(3)<br>
><br>
> for i in xrange(3):<br>
> ids.SetId(i, i)<br>
> points.InsertNextPoint(X[i],Y[i],Z[i])<br>
> vertices.InsertNextCell(ids)<br>
><br>
> To fix it, you have two choices. You can have all three verts in the same cell:<br>
><br>
> ids = vtkIdList()<br>
> ids.SetNumberOfIds(3)<br>
><br>
> for i in xrange(3):<br>
> ids.SetId(i, i)<br>
> points.InsertNextPoint(X[i],Y[i],Z[i])<br>
><br>
> vertices.InsertNextCell(ids)<br>
> Or you can have each vert in its own cell:<br>
><br>
> ids = vtkIdList()<br>
> ids.SetNumberOfIds(1)<br>
><br>
> for i in xrange(3):<br>
> ids.SetId(0, i)<br>
> points.InsertNextPoint(X[i],Y[i],Z[i])<br>
> vertices.InsertNextCell(ids)<br>
><br>
> In the "for" loop, you were calling vertices.InsertNextCell(ids)<br>
> when "ids" still had some unititialized values, since the three<br>
> ids values were not filled in until the third loop iteration.<br>
><br>
> - David<br>
</div></div></blockquote></div><br>