PDA

View Full Version : GLUtesselator, zero-area triang, & T-intersections



PJDIXIT
04-16-2012, 07:28 PM
I came across this issue when I was trying to triangulate Text entities using GLUtesselator. However, it can occur during triangulation of any polygon using GLUtesselator. The problem is that sometimes GLUtesselator generates zero-area triangles. Most of the times you can ignore them but there are cases where they canít be ignored. I am trying to find a solution so that final triangulation of a given polygon do not have any zero-area triangles or T-intersections. As far as I know, GLUtesselator is one of the most robust and stable tesselator available so I would like to stick to it and wonít mind doing some post-processing to fix the triangulation rather than writing a new tesselator myself.

I will try to demonstrate the problem with tessellation of character ĎHí. Input vertices to the GLUtesselator are:
http://www.dixittech.com/blog/wp-content/uploads/2012/04/H_input.jpg


Vertex |x |y |z |Edge flag
------------------------------------------
V1 |298 |381 |0 |True
V2 |298 |0 |0 |True
V3 |266 |0 |0 |True
V4 |266 |185 |0 |True
V5 |32 |185 |0 |True
V6 |32 |0 |0 |True
V7 |0 |0 |0 |True
V8 |0 |381 |0 |True
V9 |32 |381 |0 |True
V10 |32 |212 |0 |True
V11 |266 |212 |0 |True
V12 |266 |381 |0 |True

This is how it was triangulated using GLUtesselator. I set the winding to GLU_TESS_WINDING_ODD and GLU_TESS_TOLERANCE was set to default 0.

http://www.dixittech.com/blog/wp-content/uploads/2012/04/H_Tesselation4.jpg

After preliminary inspection of the triangulation, it seemed as if there were T-intersections at vertex 5 and 10 which raised a red flag as the geometry was further processed by half-edge data structure and T-intersections were not allowed.

http://www.dixittech.com/blog/wp-content/uploads/2012/04/H_T-Intersection2.jpg


However, generating the list of triangles showed that tessellation actually generated zero-area triangles and not T-intersections. Here is the list of generated triangles:


Triangle | Vertex indices | Edge flags |Comment
----------------------------------------------
T1 | (1, 11, 12) |(F, T, T) |
T2 | (11, 1, 4) | (F, F, F) |
T3 | (4, 1, 3) | (F, F, T) |
T4 | (3, 1, 2) | (F, T, T) |
T5 | (11, 5, 10) | (F, F, T) |
T6 | (5, 11, 4) | (F, F, T) |
T7 | (9, 7, 8) | (F, T, T) |
T8 | (7, 9, 6) | (F, F, T) |
T9 | (6, 9, 10) | (F, T, F) |Zero-area
T10 | (6, 10, 5) | (F, F, T) |Zero-area

Legend : T = True , F = False

The problem is that I canít use zero-area triangles either as I canít calculate normal or equation of plane correctly for zero-area triangles. Normals and equation of planes can be very critical for implementing smoothing and shadow generation algorithms so they need to have a valid value.

So, I am stuck here with a very bad situation: If I have zero-area triangles then I canít calculate normal and equation of plane correctly which is a must. It is trivial to remove zero-area triangles but if I remove them then I am stuck with T-intersections and I canít live with them either.

So I would like to make sure that in cases where GLUtesselator generates zero-area triangles, my application will re-triangulate a sub-portion of the polygon such that there are no zero-area triangles or T-intersections. For our example case, triangulation should look some thing like this:

http://www.dixittech.com/blog/wp-content/uploads/2012/04/H_Wanted_Tesselation1.jpg

I think its a very fundamental problem and a solution to it will benefit lot of developers working in a similar area. I am sure I am not the first one to stumble upon it. Any suggestions how it can be done? Any alternate approach is very welcome as well.

If you have trouble reading the tables clearly, you can also check this post at GLUtesselator : Issues with zero-area triangles and T-intersections (http://dixittech.com/blog)

-Prasad

sevenfold
05-08-2012, 07:37 PM
Yes, I've encountered this problem too, using GLUtesselator to create 3D text, and it almost always
creates degenerate triangles. And if you try to remove these degenerate triangles, T-junctions
are created, which are just as bad, since the mesh is no longer a closed mesh. Now, you have
a bunch of open edges, which causes a lot of headaches.

You might be tempted to go the long route try to remove T-junctions, but the act of removing
them may create even more T-junctions. So, in the end, you'll have to live with zero-area triangles
if you want a closed mesh, or need to find another tesselator.

Alternatives:
You might want to look at Delaunay triangulation. Delaunay triangulation has some nice properties
which prevent zero-area triangles from being created.

From wikipedia:


Delaunay triangulations maximize the minimum angle of all the angles of the triangles in the triangulation;
they tend to avoid skinny triangles.