Example #1
0
 /** A function to read a pixel */
 double& pixel(size_t i, size_t j) { return data[vertid(i,j)]; }
Example #2
0
 double pixel(size_t i, size_t j) const { return data[vertid(i,j)]; }
/**
 * triangulate the cube directly, without decomposition
 */
static void docube(PROCESS *process, CUBE *cube)
{
	INTLISTS *polys;
	CORNER *c1, *c2;
	int i, index = 0, count, indexar[8];

	/* Determine which case cube falls into. */
	for (i = 0; i < 8; i++) {
		if (cube->corners[i]->value > 0.0f) {
			index += (1 << i);
		}
	}

	/* Using faces[] table, adds neighbouring cube if surface intersects face in this direction. */
	if (MB_BIT(faces[index], 0)) add_cube(process, cube->i - 1, cube->j, cube->k);
	if (MB_BIT(faces[index], 1)) add_cube(process, cube->i + 1, cube->j, cube->k);
	if (MB_BIT(faces[index], 2)) add_cube(process, cube->i, cube->j - 1, cube->k);
	if (MB_BIT(faces[index], 3)) add_cube(process, cube->i, cube->j + 1, cube->k);
	if (MB_BIT(faces[index], 4)) add_cube(process, cube->i, cube->j, cube->k - 1);
	if (MB_BIT(faces[index], 5)) add_cube(process, cube->i, cube->j, cube->k + 1);

	/* Using cubetable[], determines polygons for output. */
	for (polys = cubetable[index]; polys; polys = polys->next) {
		INTLIST *edges;

		count = 0;
		/* Sets needed vertex id's lying on the edges. */
		for (edges = polys->list; edges; edges = edges->next) {
			c1 = cube->corners[corner1[edges->i]];
			c2 = cube->corners[corner2[edges->i]];

			indexar[count] = vertid(process, c1, c2);
			count++;
		}

		/* Adds faces to output. */
		if (count > 2) {
			switch (count) {
				case 3:
					make_face(process, indexar[2], indexar[1], indexar[0], 0);
					break;
				case 4:
					if (indexar[0] == 0) make_face(process, indexar[0], indexar[3], indexar[2], indexar[1]);
					else make_face(process, indexar[3], indexar[2], indexar[1], indexar[0]);
					break;
				case 5:
					if (indexar[0] == 0) make_face(process, indexar[0], indexar[3], indexar[2], indexar[1]);
					else make_face(process, indexar[3], indexar[2], indexar[1], indexar[0]);

					make_face(process, indexar[4], indexar[3], indexar[0], 0);
					break;
				case 6:
					if (indexar[0] == 0) {
						make_face(process, indexar[0], indexar[3], indexar[2], indexar[1]);
						make_face(process, indexar[0], indexar[5], indexar[4], indexar[3]);
					}
					else {
						make_face(process, indexar[3], indexar[2], indexar[1], indexar[0]);
						make_face(process, indexar[5], indexar[4], indexar[3], indexar[0]);
					}
					break;
				case 7:
					if (indexar[0] == 0) {
						make_face(process, indexar[0], indexar[3], indexar[2], indexar[1]);
						make_face(process, indexar[0], indexar[5], indexar[4], indexar[3]);
					}
					else {
						make_face(process, indexar[3], indexar[2], indexar[1], indexar[0]);
						make_face(process, indexar[5], indexar[4], indexar[3], indexar[0]);
					}

					make_face(process, indexar[6], indexar[5], indexar[0], 0);

					break;
			}
		}
	}
}