Heteroclinic.net logo

www.heteroclinic.net

In Depth 3D Computer Graphics
Chapter 1 Mesh File IX

201602

The first implementation is GTSFileReader.readAGTSFile(File readFile) method. For the "cube.gts", we got an easy pass.

In Depth 3D Computer Graphics
Chapter 1 Mesh File X

201602
But for the "bunny.gts", it fails.

And it throws a very long stack trace.

So basically what are we doing? In readAGTSFile(File readFile), we read the whole file as one string, then we try to use regex to get lines by n-occurrence. For example , try to get all lines of vertices. And it seems the number of lines can handle exceeds some limit than what we want it to handle -- 34834, 104288 or 69451? My first suspicion is the number of occurrence is limited in regex. We may try with C/C++ ( I am talking about the shell regex functions).

In Depth 3D Computer Graphics
Chapter 1 Mesh File XI

201602

Then we write a second implementation GTSFileReader.parseAGTSFile(File readFile). The idea is to avoid using regex n+ occurrence. But split whole file as a string by white space, we know the size of the header, total elements of vertices, edges and triangles. We will keep very simple loop structure. Remember in CPU architecture course, you were taught, an 'if else' can reduce your cache hit rate. Also, we also want to keep everything "in memory". We got 'cube.gts' passed.


In Depth 3D Computer Graphics
Chapter 1 Mesh File XII

201602

We also get the 'bunny.gts' passed. This is almost the biggest mesh file we want to deal with, at least, for this tutorial like project. So far so good.