Heteroclinic.net logo

www.heteroclinic.net

Jgts Demo 1.0 Smooth Shading of GTS models
9

201607

Now we are going to demonstrate how we prepare a model file for OpenGL rendering pipeline.


The initFromFile(String fn) is pretty long. It was literally transalted from the C program I wrote some years ago. Due to no IDE or the IDE is so poor for programming in C, keeping everything in one file eases keyword/string search.


Jgts Demo 1.0 Smooth Shading of GTS models
10

201607

The functions compose of three main parts, add a vertex, add an edge and add a triangle to our customized data structure. These steps are consistent with the structure of a GTS model file. In addition, we also compute the bounding box of the model, namely the xmin, ymin, zmin and xmax, ymax, zmax. If we try to translate and scale a model to fit into a given camera setting, the geometry information of the bounding box is very necessary.

The Java implementation of addAVertexToVlist eases us

Comparing the C implementation, where we wrote a heap by ourselves, the Java array is easy to read. C array is also feasible, but as far as I remember it has limit differs at different OSs or C implementations. Sometime it is so complicated to remember why you have done that and asking too many whys are difficult to answer until you took great pains to keep notes at every line you wrote, then another question may be raised why you keep so many notes. Query is good and looks endeavoring but research and literature take pains.

The customized pointerish heap implementation also bizzarely crashed the program at random due to the limited knowlege/expertise of handling such situation. This does not say Java implementation resovles the above mentioned situation. In fact, when operating any machine, we have to tune it ourselves or get somebody else to do that so we won't put the machine to a stall. JVM's graphical interface makes such practice possible.

Jgts Demo 1.0 Smooth Shading of GTS models
11

201607

Then the data structure and implementation for edges can be referring to that of vertices. In model processing, we know that the edges keep the information of the topological structure namely the connectivity. We also need each vertex knows which and how many edges connects to it, so we can reach to other vertices. Each edge has two vertices. Two vertices share a same edge.

Jgts Demo 1.0 Smooth Shading of GTS models
12

201607

If we want to talk about the completeness of a 2-manifold, I think here we can count the triangles it has or neighboring vertices that don't share one same triangle, so we can tell if this particular manifold has a hole. It is worth noting that GTS records a triangle by the three edges it has. An edge connects two vertices. So if we want to know the vertex-triangle relationship, we need extra effort. The edges' sequence of a triangle is important because it decides the orientation of the triangle, CCW or CW, which denoted as counter-clock-wise or clock-wise.