[vtkusers] Polygon triangulation using vtkPolugon::Triangulate

Frederic DANESI frederic.danesi at dinccs.com
Sun Feb 24 08:21:47 EST 2008


Hi,

Can you provide me with your points coordinates or your code ? ... I will
have a closer look to it ASAP. 

We have to figure out if it's your polygon that is incorrect (I will bet on
this one), or if the triangleFilter bugs (but to my experience, it's robust
enough), or if VTK (through OpenGL) is actually not able to render such a
polygon (I really don't think so!) ...

I my code, just fill in the polyDataMapper with the polydata called "pd"
(and not with the output of the triangle filter) to actually see your
polygon, and not its triangulation ... 

In the meanwhile, you can try to press "W" and "S" while visualizing you
polygon. It will switch from wireframe view to surface view ... and, by the
way, you will be able to see if your polygon has been correctly created (no
loop, not self intersecting, correctly oriented, ...).
 

Fred.



Cordialement,
F.Danesi
--
Département DINCCS (Département Ingénierie Numérique, Conception
Collaborative et Simulation) 
MICADO / DINCCS 
Pole de Haute Technologie, 7 boulevard Jean Delautre (IFTS) 
08000 Charleville-Mézières 
Tel. : 03.24.41.69.55 / 06.62.76.13.32 
Email : frederic.danesi at dinccs.com 
Web: www.afmicado.com / www.dinccs.com


> -----Message d'origine-----
> De : polys_poly at hotmail.com [mailto:polys_poly at hotmail.com]
> Envoyé : dimanche 24 février 2008 13:18
> À : Frederic DANESI
> Objet : Re: [vtkusers] Polygon triangulation using vtkPolugon::Triangulate
> 
> Fred,
> 
> Thank you so much for your reply and indeed it works. However, my problem
> remains. I know that OpenGL can't render correctly a polygon in 3D when it
> has inner corners larger than 180 degrees.
> 
> This is the polygon I am rendering:
> 
> http://img132.imageshack.us/img132/4343/polygon1kz0.png
> 
> This is what I get when I rotate the polygon:
> 
> http://img98.imageshack.us/img98/5820/polygon2by9.png
> 
> Any idea how I can deal with this? I would really appreciate it
> 
> Thanks,
> 
> Polys
> 
> --------------------------------------------------
> From: "Frederic DANESI" <frederic.danesi at dinccs.com>
> Sent: Sunday, February 24, 2008 12:24 AM
> To: <polys_poly at hotmail.com>; "'VTK users group'" <vtkusers at vtk.org>
> Subject: RE: [vtkusers] Polygon triangulation using
vtkPolugon::Triangulate
> 
> > Hi Polys,
> >
> > You are working directly on a vtkCell. Actually, you may have to
consider
> > working on PolyData, which enclosed all your geometric information
> > (points,
> > cells, .)
> > For your example, you can try this (it works ;-))
> >
> > vtkPoints *polygonPoints  = vtkPoints::New();
> > vtkPolygon *polygon = vtkPolygon::New();
> >
> > polygonPoints ->SetNumberOfPoints(4); //do not allocate 8 points if you
> > only
> > fill 4 in .
> > polygonPoints->InsertPoint(0, 0, 0, 0);
> > polygonPoints->InsertPoint(1, 1, 0, 0);
> > polygonPoints->InsertPoint(2, 1, 1, 0);
> > polygonPoints->InsertPoint(3, 0, 1, 0);
> >
> > polygon->GetPointIds()->SetNumberOfIds(4);
> > polygon->GetPointIds()->SetId(0, 0);
> > polygon->GetPointIds()->SetId(1, 1);
> > polygon->GetPointIds()->SetId(2, 2);
> > polygon->GetPointIds()->SetId(3, 3);
> >
> > vtkPolyData *pd = vtkPolyData::New();
> > pd->Allocate();
> > pd->InsertNextCell(polygon->GetCellType(),polygon->GetPointIds());
> > pd->SetPoints(polygonPoints);
> >
> > vtkTriangleFilter *tri= vtkTriangleFilter::New();
> > tri->SetInput(pd); //The output of the triangle filter will be a
> > triangulation of the inputPolyData .
> > vtkPolyDataMapper *map = vtkPolyDataMapper::New();
> > map->SetInput(tri->GetOutput());
> > vtkActor *act = vtkActor::New();
> > act->SetMapper(map);
> >
> > You may have to consider buying the VTK books or to have a look to the
> > examples of the book, such as ClipCow, which will show you how to
> > reconstruct a polygon from lines and then triangulate it .
> >
> > Fred.
> >
> >
> >
> > Cordialement,
> > F.Danesi
> > --
> > Département DINCCS (Département Ingénierie Numérique, Conception
> > Collaborative et Simulation)
> > MICADO / DINCCS
> > Pole de Haute Technologie, 7 boulevard Jean Delautre (IFTS)
> > 08000 Charleville-Mézières
> > Tel. : 03.24.41.69.55 / 06.62.76.13.32
> > Email : frederic.danesi at dinccs.com
> > Web: www.afmicado.com / www.dinccs.com
> >
> >
> >
> > De : vtkusers-bounces+frederic.danesi=dinccs.com at vtk.org
> > [mailto:vtkusers-bounces+frederic.danesi=dinccs.com at vtk.org] De la part
de
> > polys_poly at hotmail.com
> > Envoyé : samedi 23 février 2008 14:26
> > À : VTK users group
> > Objet : [vtkusers] Polygon triangulation using vtkPolugon::Triangulate
> >
> > I am trying to triangulate a polygon.
> >
> > My code is this:
> >
> > polygonPoints = vtkPoints::New();
> > polygon = vtkPolygon::New();
> >
> > polygonPoints ->SetNumberOfPoints(8);
> > polygon->GetPointIds()->SetNumberOfIds(8);
> >
> > polygonPoints->InsertPoint(0, 0, 0, 0);
> > polygonPoints->InsertPoint(1, 1, 0, 0);
> > polygonPoints->InsertPoint(2, 1, 1, 0);
> > polygonPoints->InsertPoint(3, 0, 1, 0);
> >
> > polygon->GetPointIds()->SetId(0, 0);
> > polygon->GetPointIds()->SetId(1, 1);
> > polygon->GetPointIds()->SetId(2, 2);
> > polygon->GetPointIds()->SetId(3, 3);
> >
> > I found out that vtkPolygon has a function named Triangulate
> >
> > int vtkPolygon::Triangulate (int index,vtkIdList* ptIds, vtkPoints* pts)
> >
> > I tried this:
> >
> > polygon->Triangulate(1, polygon->PointIds, polygonPoints);
> >
> > and get exception error.
> >
> > What do i do wrong?
> >
> > Thanks in advance,
> > Polys
> >
> >
> >





More information about the vtkusers mailing list