/* See {salamic_planes.h}. */ /* Last edited on 2015-10-02 18:04:28 by stolfilocal */ #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include int_vec_t salamic_planes_get_uniform(float startZ, float deltaZ, float eps, int minZ, int maxZ) { demand(deltaZ >= 2*eps, "plane Z spacing is too small"); demand((minZ & 1 ) == 0, "{minZ} must be even"); demand((maxZ & 1 ) == 0, "{maxZ} must be even"); int32_t sZ = salamic_utils_round(startZ, eps, 1); /* Round to odd. */ int32_t dZ = salamic_utils_round(deltaZ, eps, 0); /* Round to even. */ assert(dZ >= 2); /* Get the quantized {Z-coordinate {bZ} of the first plane in the range: */ int32_t uZ = (sZ - minZ) % dZ; if (uZ < 0) { uZ += dZ; } int32_t bZ = minZ + uZ; assert((bZ - sZ) % dZ == 0); assert(bZ >= minZ); assert(bZ - minZ < dZ); /* Compute the number of planes: */ int32_t np = (maxZ - 1 - bZ)/dZ + 1; int_vec_t planeZ = int_vec_new(np); int32_t i; for (i = 0; i < np; i++) { planeZ.e[i] = bZ; bZ += dZ; } assert(bZ > maxZ); return planeZ; } int_vec_t salamic_planes_get_adaptive(char *ZFile, float eps, int minZ, int maxZ) { FILE *rd = fopen(ZFile, "rt"); /* Get the number of planes: */ int32_t line = 1; int32_t np_file = (int32_t)fget_int(rd); /* Number of planes in file. */ fget_eol(rd); line++; int_vec_t planeZ = int_vec_new(np_file); int32_t i; int32_t np = 0; /* Number of planes in range. */ for(i = 0; i < np; i++) { float fZ = (float)fget_double(rd); int32_t pZ = salamic_utils_round(fZ, eps, 1); if (pZ > maxZ) { break; } if (pZ >= minZ) { planeZ.e[np] = pZ; if ((np > 0) && (planeZ.e[np-1] >= pZ)) { fprintf(stderr, "%s:%d: ** error: slicing planes not increasing or too close\n", ZFile, line); exit(1); } np++; } fget_eol(rd); line++; } fclose(rd); int_vec_trim(&planeZ, np); return planeZ; }