Hi Paulo,<br><br>You can use vtkMeshQuality to compute the quality of a mesh, but I don't think there is anything in VTK for improving the quality of a mesh. Hopefully someone will tell me that I'm wrong about this...<div>
<br></div><div> David</div><div><br><br>On Sun, Dec 12, 2010 at 1:58 PM, Paulo Henrique Junqueira Amorim <<a href="mailto:paulojamorim@gmail.com">paulojamorim@gmail.com</a>> wrote:<br>> 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<br>> 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>> On 12 December 2010 14:04, David Gobbi <<a href="mailto:david.gobbi@gmail.com">david.gobbi@gmail.com</a>> wrote:<br>>><br>>> 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>>><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) # call for every cell, not for every point<br>
>><br>>> polydata = vtkPolyData()<br>>> polydata.SetPoints(points)<br>>> polydata.SetPolys(vertices) # use SetPolys for triangles<br>>> polydata.Update()<br>>><br>>> The above code will create a polydata that has one triangle.<br>
>><br>>> David<br>>><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>><br>>> 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<br>
>> >> 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<br>
>> > 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<br>>> > 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>><br>><br><br></div>