Bug in vtkPolygon::Triangulate

Horst Wagner wagner at iap.tuwien.ac.at
Tue Aug 3 10:01:38 EDT 1999


I already posted a similar message last week, but I think it did not
reach the mailing list. Anyway, in the meantime I dug a bit deeper into
the vtk code.

My problem is that I observe that for some really simple polygons
triangulation completely fails. The triangulation routine returns
success, yet the list of triangles is empty.

First of all, I think, that the statement in
vtkPolygon::RecursiveTriangulate (vtkPolygon.c):

   return 1;

should be replaced with

   return this->SuccessfulTriangulation;

Otherwise in many cases the routine incorrectky returns 1 although the
flag SuccessfulTriangulation is set to zero (i.e. triangulation failed).

Unfortunately, this does not solve my problem, but at least gives me the
correct return value (i.e no success). After some debugging, I think the
real problem is somewhere in vtkPolygon::CanSplitLoop(). It seems to
have problems when several vertices are on a straight line.

Attached to the end of this message is a simple TCL example
demonstrating the problem. The example is based on the triangulate.tcl
code of examplesTCL in the vtk distribution using a simple 8 point
No polygon will be rendered, yet if you increase the y coordinates of
points 5 & 6 in the code by one, then triangulation suddenly work
I tested this for vtk2.2 and vtk2.3 on Intel NT and on Alpha Tru64-Unix.
Unfortunately, the nightly distributions are to large for me to download
by modem.
Does anyone know a workaround to this problem ?

vtkPolygon.cxx says:
// Triangulate polygon. Tries to use the fast triangulation technique
// first, and if that doesn't work, uses more complex routine that is
//  guaranteed to work
However, I cannot find this more complex and reliable routine.



catch {load vtktcl}
## Example tests the triangulation method in vtkPolygon
# get the interactor ui
source ../../examplesTcl/vtkInt.tcl

vtkPoints points
 points InsertPoint 0 0 2 0
 points InsertPoint 1 0 1 0
 points InsertPoint 2 1 1 0
 points InsertPoint 3 1 0 0
 points InsertPoint 4 4 0 0
 points InsertPoint 5 4 4 0
 points InsertPoint 6 1 4 0
 points InsertPoint 7 1 2 0

# if you change y from 4 to 5 in points 5 and 6,
#   then polygon is triangulated correctly

vtkCellArray polys
    polys InsertNextCell 8;#number of points
    polys InsertCellPoint 0
    polys InsertCellPoint 1
    polys InsertCellPoint 2
    polys InsertCellPoint 3
    polys InsertCellPoint 4
    polys InsertCellPoint 5
    polys InsertCellPoint 6
    polys InsertCellPoint 7

vtkPolyData polyData
    polyData SetPoints points
    polyData SetPolys polys

# triangulate the polygons
vtkTriangleFilter tf
    tf SetInput polyData

vtkPolyDataMapper map
    map SetInput [tf GetOutput]

vtkActor tri
    tri SetMapper map

# Create the RenderWindow, Renderer and both Actors
vtkRenderer ren1
vtkRenderWindow renWin
    renWin AddRenderer ren1
vtkRenderWindowInteractor iren
    iren SetRenderWindow renWin

# Add the actors to the renderer, set the background and size
ren1 AddActor tri
ren1 SetBackground 0 0 0
[ren1 GetActiveCamera] Dolly 1.4

renWin SetSize 500 500
iren Initialize

# render the image
iren SetUserMethod {wm deiconify .vtkInteract}

# prevent the tk window from showing up then start the event loop
wm withdraw .

This is the private VTK discussion list.  Please keep messages on-topic.
Check the FAQ at: <http://www.automatrix.com/cgi-bin/vtkfaq>
To UNSUBSCRIBE, send message body containing "unsubscribe vtkusers" to
<majordomo at gsao.med.ge.com>.  For help, send message body containing
"info vtkusers" to the same address.     Live long and prosper.

More information about the vtkusers mailing list