Heteroclinic.net logo

www.heteroclinic.net

Generating Triangle Strip Episode One
I. the thiking, we have an example

20150529

Recently, I have been studying the gts library. It has the functionality and an exmaple about how to generate a triangle strip. Gts is an amazing library. During my computer science study at university time, I borrowed a lot of ideas from it for my own projects. However, this library was written I think the style is of the time programmers are moving from C to C++. Today, I am so familar with IDE and debugging tools that the gts library leaves me in a maze of structs with darting pointers and typedefs. It was said C++ is C plus macro. But I don't have a full semester to re-forge my C skills. What leads here is that I tried to write the OpenGL Gears with GL4, which quite necessarily requires building triangle strips with general mesh. I am not stuborn with how to express my thought, in addition to my difficulty to apprentice the crocheting of gts, I decided to make a move. So I stared at the following sample mesh file for some minutes. There is something caught my eyes. So I would haste to write down some thoughts then let them shun into the corners behind the murals painted with mundane impulses.

Generating Triangle Strip Episode One
II. the thiking, how to read the sample

20150529

I once tried to find some formal explanation about the format of a gts model file. Maybe it is I did not stick to the source or it is just not easy to do such sourcing. Finally, I understood it by just trying. Not difficult just need pencil and paper, and patience.
The first line of this model states, for this model there are eight vertices, eighteen edges and twelve triangles.
From line two to line nine, each line has the three-dimensional coordinate (x,y,z) of a vertex. The first vertex was assigned a index 1 and so on so forth, though computer programming usually start the first as an index 0.
From line ten to line twenty-seven, each line of model file has the connection information of two vertices. For example "3 1" states vertex 3 is connected to vertex 1, namely there is an edge for some triangle(s). Starting from 1, each edge is also given an index incremented by 1 from the previous line.
From line twenty-eight to line thirty-nine, each line of model file indicates a triangle. Each triangle has three edges. For example "9 13 1" states edge with index nine, thirteen and one form the triangle with index one.
At earlier times, I had drawn this model by hand many times, to find out what it is, to find out how the triangle is oriented counter-clock-wise or the vice. We know the vertices show the geometry, the edges show the topology of the model. The triangles will take about the completeness of the mesh. Three edges connected three vertices, but the area bounded maybe a hole. Normally, I just drew the orthogonal draft like traditional geometry or mechanics, machine design text book, an axonometric(al) drawing --baike.baidu.com. The above model is the mathematical record of a cube. Typically, I don't write down the the veritices, lines, and triangles on the paper. For convenience to read anywhere, this time I did. My handwriting tends to put single number is a very similar pattern, they look quite different from being looked at in a text editor. So I was amazed that, at the triangles part, there are many numbers appear exactly twice, and no number appear more than three times.

Generating Triangle Strip Episode One
III. the thiking, we call them some corollaries

20150529
Corollary 1.1 One edge is shared by two and exactly two triangles if it is shared.
The proof will be trivia. It can be formalized by differential geometry and basic graph theories.
Corollary 1.2 For one triangle strip, not a single triangle, either there is four edges left to grow the strip or there is zero left. There is no other case. The case for zero left is that the strip form a loop, a mobius strip eg.
The proof will be trivia. It can be formalized by differential geometry and basic graph theories.


Generating Triangle Strip Episode One
IV. the thiking, an algorithm by text description

20150529

Let's only look at the triangles part. We cut it into three pieces, we call each bucket. For example:



For each bucket, the first pass, we count and select the edges that appear exactly twice, put them to a sorted table etc (we have a structure that can get trianges from an edge, edges for a triangle), sorted by edge index. From the edges, we will be able connect the triangles.
After the first pass, a lot of edges will be filtered. A loop will be a complete strip not possible for future growing. Any strip (having more than two triangles) will provide only four edges to connect more triangles. A single triangle provides three edges to border (a more accurate term than connect) more triangles. The number of edges left in a bucket will be greatly reduced. Then we merge two adjacent buckets. Go back to the previous step. Loop until all buckets are merged.
For a large mesh, large scale merge sort like strip generation can be run in parallel.