[vtkusers] Triangle Geometry and Vertices

Paulo Henrique Junqueira Amorim paulojamorim at gmail.com
Sun Dec 12 15:58:54 EST 2010


Thank's David and Jim.

Generate a triangle is really what I wanted.

By the same token, there is some way from a vtkPolyData, generate a mesh of
triangles more regular?

I would like to improve the mesh for use in finite elements.

Ragards,
Paulo



On 12 December 2010 14:04, David Gobbi <david.gobbi at gmail.com> wrote:

> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20101212/24dcaa9d/attachment.htm>


More information about the vtkusers mailing list