[vtkusers] Polygon triangulation using vtkPolugon::Triangulate
Frederic DANESI
frederic.danesi at dinccs.com
Sat Feb 23 17:24:14 EST 2008
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