se
Exercise 1 !1"#!1#1"
Sid 1 $"%
Exercise 1
Reading OFF-files
In this representation, each polygon is represented by a list of vertex coordinates. P = ((x1, y1, z1), (x2, y2, z2), ... , (xn, yn, zn))
Disadvantages
Takes space. For more than one polygon space is wasted because vertices are duplicated. It is also risky to duplicate data when the data may change. Takes time since there is no explicit representation of edges and vertices, an interactive move of a vertex involves finding all polygons that share the vertex. Polygon edges are drawn twice since there is no easy way to find edges.
V2 P1 P2 V4 V3
Each vertex is stored once in a vertex list. The polygon, P, is a list of indices to a vertex list. V = (V1, V2, V3, V4) = ((x1, y1, z1), ... , (x4 , y4 , z4 )) P1 = (1, 2, 4) P2 = (4, 2, 3)
V1
Sid
$"%
Advantages
Space saved because each vertex is stored once. Coordinates of a vertex can be changed easily. Difficult to find polygons that share edges. Polygon edges are drawn twice since there is no easy way to find edges.
V2 E1 V1 E5 P1 E4 P2 E3 V4 E2 V3
Disadvantage
In this format a polygon is represented by a pointer to the edge list V = (V1, V2, V3, V4) = ((x1, y1, z1), ... , (x4 , y4 , z4 )) E1 = (V1 , V2, P1, ) E2 = (V2 , V3, P2, ) E3 = (V3 , V4, P2, ) E4 = (V4 , V2, P1, P2) E5 = (V4 , V1, P1, ) P1 = (E1 , E4, E5) P2 = (E2 , E3, E4)
Advantages
Displays edges rather than polygons. Eliminates redundant clipping, transformation and scan conversion. Filled polygons are more easily clipped. The order of vertices may be important in drawing, i.e., the vertices in all polygons should be in clock-wise or counter clock-wise order. This is tricky in this representation.
Disadvantage
In all three cases, the determining of which edges are incident to a vertex is not easy. All edges must be inspected. If this is important (optionally in Assignment 3), the mentioned Half-edge representations is probably better.
OFF #header Nvertices Nfaces Nedges X[0] Y[0] Z[0] : : : X[Nv-1] Y[Nv-1] Z[Nv-1] NV1 V[0] V[1] ... V[NV-1] COLOR : NVN V[0] V[1] ... V[NV-1] COLOR The optional color may take several forms. Line breaks are significant here: the color description begins after V[NV-1] and ends with the end of the line (or the next # comment). A color may be: nothing the default color one integer index into the colormap; three or four integers RGB[A] and possibly alpha values in the range [0,255] three or four floating-point numbers RGB[A] and possibly alpha values in the range [0, 1]
Triangulation
Drawing polygon data is much faster if all polygons have the same number of vertices. Since there can be any number of vertices in a polygon according to the OFF format we should fall back to triangles, i.e., each polygon read from the OFF file should be converted to a triangle. There are many algorithms for this, but a simple one will do. Below is a suggestion in some pseudo code (Vi is the i:th vertex in a polygon P with n vertices). for i=2 to n -1 do: store(new Polygon(V0, Vi-1, Vi))
Vertex data is usually 3D float (not double) data. 4D is also possible to use, where the 4th element is called w and usually set to 1.0 (or 0 for vectors). If you use color data, our applications only use 3D colors (RGB). Prepare for additional vector data (normals) to your polygons (Used in the Assignment 3). Also look at Exercise 2 for inspiration about data storage.