Commit 1febb304 authored by Taddeüs Kroes's avatar Taddeüs Kroes

Graphics assignment 9.

Source code cleanup.
parent eefbd269
......@@ -44,18 +44,17 @@ interpolate_points(unsigned char isovalue, vec3 p1, vec3 p2,
2 triangles.
*/
// Some abbreviating definitions that are used in the function below
/* Some abbreviating definitions that are used in the function below */
#define ADD_VEC(i,a,b) (triangles[tri_count].p[(i)] = \
interpolate_points(isovalue, c.p[(a)], c.p[(b)], v[(a)], v[(b)]))
#define ADD_TRI(a,b,c,d,e,f) \
ADD_VEC(0,(a),(b)); ADD_VEC(1,(c),(d)); ADD_VEC(2,(e),(f)); tri_count++
static int
generate_tetrahedron_triangles(triangle *triangles, unsigned char isovalue,
cell c, int v0, int v1, int v2, int v3)
{
unsigned char *v = c.value;
//vec3 *p = triangles[0].p;
int tri_count = 0;
// Use a 4-bit bitmask to determine the order of "black/white" points of
......@@ -63,72 +62,29 @@ generate_tetrahedron_triangles(triangle *triangles, unsigned char isovalue,
switch( (v[v0] <= isovalue ? 1 : 0) | (v[v1] <= isovalue ? 1<<1 : 0)
| (v[v2] <= isovalue ? 1<<2 : 0) | (v[v3] <= isovalue ? 1<<3 : 0) )
{
case 0x1: case 0xE: // 0001 or 1110
ADD_TRI(v0, v1, v0, v2, v0, v3);
break;
//p[0] = interpolate_points(isovalue, c.p[v0], c.p[v1], v[v0], v[v1]);
//p[1] = interpolate_points(isovalue, c.p[v0], c.p[v2], v[v0], v[v2]);
//p[2] = interpolate_points(isovalue, c.p[v0], c.p[v3], v[v0], v[v3]);
//return 1;
case 0x2: case 0xD: // 0010 or 1101
ADD_TRI(v1, v0, v1, v3, v1, v2);
break;
//p[0] = interpolate_points(isovalue, c.p[v1], c.p[v0], v[v1], v[v0]);
//p[1] = interpolate_points(isovalue, c.p[v1], c.p[v3], v[v1], v[v3]);
//p[2] = interpolate_points(isovalue, c.p[v1], c.p[v2], v[v1], v[v2]);
//return 1;
case 0x4: case 0xB: // 0100 or 1011
ADD_TRI(v2, v0, v2, v1, v2, v3);
break;
//p[0] = interpolate_points(isovalue, c.p[v2], c.p[v0], v[v2], v[v0]);
//p[1] = interpolate_points(isovalue, c.p[v2], c.p[v1], v[v2], v[v1]);
//p[2] = interpolate_points(isovalue, c.p[v2], c.p[v3], v[v2], v[v3]);
//return 1;
case 0x8: case 0x7: // 1000 or 0111
ADD_TRI(v3, v0, v3, v2, v3, v1);
break;
//p[0] = interpolate_points(isovalue, c.p[v3], c.p[v0], v[v3], v[v0]);
//p[1] = interpolate_points(isovalue, c.p[v3], c.p[v2], v[v3], v[v2]);
//p[2] = interpolate_points(isovalue, c.p[v3], c.p[v1], v[v3], v[v1]);
//return 1;
case 0x3: case 0xC: // 0011 or 1100
ADD_TRI(v0, v3, v0, v2, v1, v3);
ADD_TRI(v1, v3, v0, v2, v1, v2);
break;
//p[0] = interpolate_points(isovalue, c.p[v0], c.p[v3], v[v0], v[v3]);
//p[1] = interpolate_points(isovalue, c.p[v0], c.p[v2], v[v0], v[v2]);
//p[2] = interpolate_points(isovalue, c.p[v1], c.p[v3], v[v1], v[v3]);
//p = triangles[1].p;
//p[0] = interpolate_points(isovalue, c.p[v1], c.p[v3], v[v1], v[v3]);
//p[2] = interpolate_points(isovalue, c.p[v1], c.p[v2], v[v1], v[v2]);
//p[1] = interpolate_points(isovalue, c.p[v0], c.p[v2], v[v0], v[v2]);
//return 2;
case 0x5: case 0xA: // 0101 or 1010
ADD_TRI(v0, v1, v2, v3, v0, v3);
ADD_TRI(v0, v1, v1, v2, v2, v3);
break;
//p[0] = interpolate_points(isovalue, c.p[v0], c.p[v1], v[v0], v[v1]);
//p[1] = interpolate_points(isovalue, c.p[v2], c.p[v3], v[v2], v[v3]);
//p[2] = interpolate_points(isovalue, c.p[v0], c.p[v3], v[v0], v[v3]);
//p = triangles[1].p;
//p[0] = interpolate_points(isovalue, c.p[v0], c.p[v1], v[v0], v[v1]);
//p[1] = interpolate_points(isovalue, c.p[v1], c.p[v2], v[v1], v[v2]);
//p[2] = interpolate_points(isovalue, c.p[v2], c.p[v3], v[v2], v[v3]);
//return 2;
case 0x6: case 0x9: // 0110 or 1001
ADD_TRI(v0, v1, v2, v3, v1, v3);
ADD_TRI(v0, v1, v0, v2, v2, v3);
break;
//p[0] = interpolate_points(isovalue, c.p[v0], c.p[v1], v[v0], v[v1]);
//p[2] = interpolate_points(isovalue, c.p[v1], c.p[v3], v[v1], v[v3]);
//p[1] = interpolate_points(isovalue, c.p[v2], c.p[v3], v[v2], v[v3]);
//p = triangles[1].p;
//p[0] = interpolate_points(isovalue, c.p[v0], c.p[v1], v[v0], v[v1]);
//p[1] = interpolate_points(isovalue, c.p[v0], c.p[v2], v[v0], v[v2]);
//p[2] = interpolate_points(isovalue, c.p[v2], c.p[v3], v[v2], v[v3]);
//return 2;
default: // 0000 or 1111
break;
case 0x1: case 0xE: // 0001 or 1110
ADD_TRI(v0, v1, v0, v2, v0, v3);
break;
case 0x2: case 0xD: // 0010 or 1101
ADD_TRI(v1, v0, v1, v3, v1, v2);
break;
case 0x4: case 0xB: // 0100 or 1011
ADD_TRI(v2, v0, v2, v1, v2, v3);
break;
case 0x8: case 0x7: // 1000 or 0111
ADD_TRI(v3, v0, v3, v2, v3, v1);
break;
case 0x3: case 0xC: // 0011 or 1100
ADD_TRI(v0, v3, v0, v2, v1, v3);
ADD_TRI(v1, v3, v0, v2, v1, v2);
break;
case 0x5: case 0xA: // 0101 or 1010
ADD_TRI(v0, v1, v2, v3, v0, v3);
ADD_TRI(v0, v1, v1, v2, v2, v3);
break;
case 0x6: case 0x9: // 0110 or 1001
ADD_TRI(v0, v1, v2, v3, v1, v3);
ADD_TRI(v0, v1, v0, v2, v2, v3);
}
return tri_count;
......
......@@ -35,7 +35,7 @@ voxel2idx(int i, int j, int k)
cell corresponds to voxel (i, j, k), datapoint 1 to voxel (i+1, j, k),
etc. See Figure 3 in the assignment. */
// Abbreviation definition, used in the function below
/* Abbreviation definition, used in the function below */
#define ADD_DATA_POINT(index,i,j,k) \
c.p[(index)] = v3_create((i), (j), (k)); \
c.value[(index)] = volume[voxel2idx((i), (j), (k))]
......@@ -43,8 +43,8 @@ voxel2idx(int i, int j, int k)
cell
get_cell(int i, int j, int k)
{
cell c;
cell c;
ADD_DATA_POINT(0, i , j , k);
ADD_DATA_POINT(1, i+1, j , k);
ADD_DATA_POINT(2, i , j+1, k);
......@@ -54,7 +54,7 @@ get_cell(int i, int j, int k)
ADD_DATA_POINT(6, i , j+1, k+1);
ADD_DATA_POINT(7, i+1, j+1, k+1);
return c;
return c;
}
/* Utility function to read a volume dataset from a VTK file.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment