Thank&#39;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">&lt;<a href="mailto:david.gobbi@gmail.com">david.gobbi@gmail.com</a>&gt;</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&#39;m going to throw in a little addition.  You say &quot;triangle verts&quot; so<br>
I&#39;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 &lt;<a href="mailto:david.gobbi@gmail.com">david.gobbi@gmail.com</a>&gt; wrote:<br>
&gt;<br>
&gt; On Sun, Dec 12, 2010 at 6:39 AM, Jim Peterson &lt;<a href="mailto:jimcp@cox.net">jimcp@cox.net</a>&gt; wrote:<br>
&gt;&gt;<br>
&gt;&gt; Paulo,<br>
&gt;&gt; I am no Python expert, but if I understand the sequence of events, you should create the polydata object before writing the file.<br>
&gt;&gt;<br>
&gt;&gt; Hope that helps,<br>
&gt;&gt; Jim<br>
&gt;<br>
&gt; What Jim said.  Also, the id list is never filled in.  The following code is wrong:<br>
&gt;<br>
&gt; ids = vtkIdList()<br>
&gt; ids.SetNumberOfIds(3)<br>
&gt;<br>
&gt; for i in xrange(3):<br>
&gt;     ids.SetId(i, i)<br>
&gt;     points.InsertNextPoint(X[i],Y[i],Z[i])<br>
&gt;     vertices.InsertNextCell(ids)<br>
&gt;<br>
&gt; To fix it, you have two choices.  You can have all three verts in the same cell:<br>
&gt;<br>
&gt; ids = vtkIdList()<br>
&gt; ids.SetNumberOfIds(3)<br>
&gt;<br>
&gt; for i in xrange(3):<br>
&gt;     ids.SetId(i, i)<br>
&gt;     points.InsertNextPoint(X[i],Y[i],Z[i])<br>
&gt;<br>
&gt; vertices.InsertNextCell(ids)<br>
&gt; Or you can have each vert in its own cell:<br>
&gt;<br>
&gt; ids = vtkIdList()<br>
&gt; ids.SetNumberOfIds(1)<br>
&gt;<br>
&gt; for i in xrange(3):<br>
&gt;     ids.SetId(0, i)<br>
&gt;     points.InsertNextPoint(X[i],Y[i],Z[i])<br>
&gt;     vertices.InsertNextCell(ids)<br>
&gt;<br>
&gt; In the &quot;for&quot; loop, you were calling vertices.InsertNextCell(ids)<br>
&gt; when &quot;ids&quot; still had some unititialized values, since the three<br>
&gt; ids values were not filled in until the third loop iteration.<br>
&gt;<br>
&gt;   - David<br>
</div></div></blockquote></div><br>