Esempio n. 1
0
void FillArrayWithIsosurface(void)
{
	int n, total = 0;
	// Make room for 12 triangles
	triangle *triangles = malloc(12 * sizeof(triangle));
	if(triangles == NULL){
		perror("Triangles array NULL");
		return;
	}
	
	for(int k = 0; k < nz - 1; k++) {
		for(int j = 0; j < ny - 1; j++) {
			for(int i = 0; i < nx - 1; i++) {
				// For each cell generate the triangles
				n = generate_cell_triangles(triangles, get_cell(i, j, k), isovalue);
				
				for(int c = 0; c < n; c++){
					// Add alle the vertices from the triangle
					AddVertexToArray(triangles[c].p[0], triangles[c].n[0]);
					AddVertexToArray(triangles[c].p[1], triangles[c].n[1]);
					AddVertexToArray(triangles[c].p[2], triangles[c].n[2]);
				}
				
				total += n;
			}
		}
	}
	
	printf("Num triangles generated for isosurface: %d\n", total);
	
	free(triangles);
}
Esempio n. 2
0
void FillArrayWithPoints(void)
{
    int i, j, k;
    int idx;

    idx = 0;

    for (k = 0; k < nz; k++)
    {
        for (j = 0; j < ny; j++)
        {
            for (i = 0; i < nx; i++)
            {
                if (abs(volume[idx]-isovalue) <= epsilon)
                {
                    AddVertexToArray(
                        v3_create((i+0.5)*sizex, (j+0.5)*sizey, (k+0.5)*sizez),
                        v3_create(0, 0, 0)
                    );
                }

                idx++;
            }
        }
    }
}
Esempio n. 3
0
void FillArrayWithIsosurface(void)
{
  cell c;
  vec3 v, n;
  triangle triangles[12];
  int amt, amt_total = 0;

  for (int k = 0; k < nx; k++) {
    for (int j = 0; j < ny; j++) {
      for (int i = 0; i < nz; i++) {
        c = get_cell(i, j, k);
        amt = generate_cell_triangles(triangles, c, isovalue);
        amt_total += amt;
        for (int a = 0; a < amt; a++) {
          for (int b = 0; b < 3; b++) {
            v = triangles[a].p[b];
            n = triangles[a].n[b];
            AddVertexToArray(v, n);
          }
        }
      }
    }
  }
  printf("\nTRIANGLE COUNT = %d\n", amt_total);
}
Esempio n. 4
0
void FillArrayWithCubes(void)
{
    int i, j, k;
    int idx;
    float   minx, miny, minz;
    float   maxx, maxy, maxz;

    idx = 0;

    for (k = 0; k < nz; k++)
    {
        for (j = 0; j < ny; j++)
        {
            for (i = 0; i < nx; i++)
            {
                if (abs(volume[idx]-isovalue) <= epsilon)
                {
                    minx = i*sizex;
                    miny = j*sizey;
                    minz = k*sizez;

                    maxx = (i+1)*sizex;
                    maxy = (j+1)*sizey;
                    maxz = (k+1)*sizez;

                    AddVertexToArray(v3_create(minx, miny, minz), v3_create(0, 0, -1));
                    AddVertexToArray(v3_create(maxx, miny, minz), v3_create(0, 0, -1));
                    AddVertexToArray(v3_create(maxx, maxy, minz), v3_create(0, 0, -1));
                    AddVertexToArray(v3_create(minx, maxy, minz), v3_create(0, 0, -1));

                    AddVertexToArray(v3_create(minx, miny, maxz), v3_create(0, 0, 1));
                    AddVertexToArray(v3_create(maxx, miny, maxz), v3_create(0, 0, 1));
                    AddVertexToArray(v3_create(maxx, maxy, maxz), v3_create(0, 0, 1));
                    AddVertexToArray(v3_create(minx, maxy, maxz), v3_create(0, 0, 1));


                    AddVertexToArray(v3_create(minx, miny, minz), v3_create(0, -1, 0));
                    AddVertexToArray(v3_create(maxx, miny, minz), v3_create(0, -1, 0));
                    AddVertexToArray(v3_create(maxx, miny, maxz), v3_create(0, -1, 0));
                    AddVertexToArray(v3_create(minx, miny, maxz), v3_create(0, -1, 0));

                    AddVertexToArray(v3_create(minx, maxy, minz), v3_create(0, 1, 0));
                    AddVertexToArray(v3_create(maxx, maxy, minz), v3_create(0, 1, 0));
                    AddVertexToArray(v3_create(maxx, maxy, maxz), v3_create(0, 1, 0));
                    AddVertexToArray(v3_create(minx, maxy, maxz), v3_create(0, 1, 0));


                    AddVertexToArray(v3_create(minx, miny, minz), v3_create(-1, 0, 0));
                    AddVertexToArray(v3_create(minx, maxy, minz), v3_create(-1, 0, 0));
                    AddVertexToArray(v3_create(minx, maxy, maxz), v3_create(-1, 0, 0));
                    AddVertexToArray(v3_create(minx, miny, maxz), v3_create(-1, 0, 0));

                    AddVertexToArray(v3_create(maxx, miny, minz), v3_create(1, 0, 0));
                    AddVertexToArray(v3_create(maxx, maxy, minz), v3_create(1, 0, 0));
                    AddVertexToArray(v3_create(maxx, maxy, maxz), v3_create(1, 0, 0));
                    AddVertexToArray(v3_create(maxx, miny, maxz), v3_create(1, 0, 0));
                }

                idx++;
            }
        }
    }
}