Storing Objects: Object File Format

Together with thinking up a data structure to represent the objects I wanted to explore, I needed a way to store the objects in text files. Some terminology to remember from the data structure discussion: objects come in disjoint pieces, each piece has at least one surface, each surfaces is a polytope, and is represented by the part/image structure.

Here is a compact description of the file format. After some preliminary information needed to parse the file, the object is described one piece at a time. The information about any given piece is contained in a piece section. Sections are seperated by a percent sign (%). Within sections, information about the parts in the piece is given one dimension at a time. For each dimension there is a part segment. The part segment for dimension n starts with how many faces of dimension n there are in the current piece, followed by the definitions of those parts. There is one part definition per line. It starts with a list of link values: integers that indicate which n-1 dimensional parts are the faces of a given n dimensional part. These link values are used to create the image list under the part. For vertices (parts of dimension 0), there are coordinates instead of link values. After the link values (or coordinates), there is a semicolon (;), and then the color for the part is given with four values between 0 and 1: red, green, blue, and opacity. The last part segment is for the surfaces of the piece, one surface definition per line. Like the part definitions, the surface definition has a list of link values, and a semicolon, but there is no color information. Color information describes the interior of the face, and surfaces are just collections of faces, so they do not have color of their own, since each of the faces comprising the surface has already had a color assinged to it. Instead of color information, surfaces have an integer 0 or 1, indicating that the surface is closed or open, respectively. "Closed" here means that the surface meets itself to bound a volume in space. An open surface does not bound volume, such as a triangle mesh of a hemi-sphere. After all the part segments, there is one last list of link values to collect all the surfaces into one piece, and then the interior of this piece is given a color.

So, for example, here are two triangles, one with a hole, one solid, all faces numbered:
two triangles, one with hole
And below is the object file for the above object. All vertices and edges are white, the triangle with a hole is red, and the solid triangle is semi-transparent blue.

2 # space_d = 2, position information is 2 coordinates
2 # 2 pieces in this object

%

# first piece is the triangle with hole cut out
2  # piece dimension is 2; 3 part segments follow
# (first part segment)
6  # 6 vertices follow
0.5 1; 1 1 1 1   #0 position=(0.5,1), color=white, opaque
0 0; 1 1 1 1     #1
1 0;  1 1 1 1    #2
0.5 0.6; 1 1 1 1 #3
0.3 0.2; 1 1 1 1 #4 
0.7 0.2; 1 1 1 1 #5

# (second part segment )
6  # 6 edges follow
0 2; 1 1 1 1 #0  edge 0 has vertices 0 and 2 as its endpoints
2 1; 1 1 1 1 #1  edge 1 has vertices 2 and 1 as its endpoints
1 0; 1 1 1 1 #2
3 5; 1 1 1 1 #3
5 4; 1 1 1 1 #4
4 3; 1 1 1 1 #5

# (third and final part segment)
2  # 2 surfaces follow
0 1 2; 0 # outer surface is edges 0, 1, and 2, it is closed
3 4 5; 0 # inner surface is edges 3, 4, and 5, it is closed

0 1; 1 0 0 1 # piece has two surfaces, interior is (opaque) red

%

# second piece is solid triangle
2 # piece dimension is 2; 3 part segments follow

3 # 3 vertices follow
1.75 1; 1 1 1 1 #0
1.25 0; 1 1 1 1 #1
2.25 0; 1 1 1 1 #2

3 # 3 edges follow
0 2; 1 1 1 1 #0
2 1; 1 1 1 1 #1
1 0; 1 1 1 1 #2

1 # 1 surface follows
0 1 2; 0

#piece consists of just one surface
0; 0 0 1 0.5  # solid triangle is semi-transparent blue

% # final section delimiter to indicate end of file

Object files can be constructed in either of two ways. One way uses an algorithm to traverse an object representation (which is already in memory) in order to write out the corresponding object file. For instance, the 600-cell will be pieced together by a lengthy iterative algorithm. Once this construction is complete, the 600-cell will be saved to a file so that it can readily loaded in the future.

The other way is to construct the object file by hand. To do this, one needs a diagram of the object with all faces and vertices numbered. Then the relationships of which parts are faces of which other parts can be seen and recorded in the file. Here, for instance, is the diagram that was used to create object file for the cube:
cube diagram
I also made a diagram for the hypercube, which actually wasn't as much of a pain to create and interpret as it might look like. Here is a scan of the diagram that I made on paper:
hypercube diagram
The object file for the hypercube is 45 lines long. By comparison, the object file for the 600-cell will be 2059 lines long.


(back to Contents)
(on to Code)