// -*-C++-*- #include #define FPARAM(name, default) float name = params->getFloat(#name, default); void GENERATE(TextureParam *params, int width, int height, int depth, int components, float *data) { const char *file = params->getString("file", ""); FILE *f = fopen(file, "r"); if (!f) { perror(file); return; } int x = (int)params->getFloat("x", 0); int y = (int)params->getFloat("y", 0); int z = (int)params->getFloat("z", 0); int c, n0, n1, n2; if (fscanf(f, "%d %d %d %d ", &n2, &n1, &n0, &c) != 4) { return; } fprintf(stderr, "Reading %dx%dx%dx%d numbers\n", n2, n1, n0, c); if (components > 4 || components < 0) return; int ind=0, i, j, k; for (k = 0; k < n2; k++) { for (j = 0; j < n1; j++) { for (i = 0; i < n0; i++) { float foo[100]; //for (int ic = 0; ic < c; ic++) { // fscanf(f, "%f", &foo[ic]); //} fread(foo, sizeof(float), c, f); if (i < x || i >= x + width || j < y || j >= y + height || k < z || k >= z + depth) continue; if (components >= 1) data[ind++] = foo[0%c]; if (components >= 2) data[ind++] = foo[1%c]; if (components >= 3) data[ind++] = foo[2%c]; if (components >= 4) data[ind++] = foo[3%c]; } } } fclose(f); } // vim: set syntax=c: