static void get_brick_vertices( Brick *br, VRState *state, Coord cpt[8], VRVolumeData *vd, Matrix RTTMat ) { int i; Matrix BTRMat; /* Locate brick cube at the proper location and rotate it */ matrix_copy(IdentityMatrix, 4, BTRMat); matrix_translate(1.0, 1.0, 1.0, BTRMat); matrix_scale(0.5, 0.5, 0.5, BTRMat); matrix_translate(br->xOff, br->yOff, br->zOff, BTRMat); matrix_scale(1.0 / (float) vd->nxBricks, 1.0 / (float) vd->nyBricks, 1.0 / (float) vd->nzBricks, BTRMat); matrix_scale(2.0, 2.0, 2.0, BTRMat); matrix_translate(-1.0, -1.0, -1.0, BTRMat); matrix_mult_safe(BTRMat, vd->VTRMat, BTRMat); /* Transform unit cube */ for (i = 0; i < 8; i++) { coord_transform(PlusMinusCube[i], BTRMat, cpt[i]); } /* Store invers transformation so texture coords are in range [0.0 1.0] */ matrix_invert(BTRMat, RTTMat); matrix_translate(1.0, 1.0, 1.0, RTTMat); matrix_scale(0.5, 0.5, 0.5, RTTMat); matrix_translate(br->txOff, br->tyOff, br->tzOff, RTTMat); matrix_scale(br->txScl, br->tyScl, br->tzScl, RTTMat); }
int main (int argc, const char *argv[]) { int c; int ok; char *infile, *morphfile, *outfile, *format, *input_layer, *output_layer; char *attrs, *spatial_filter, *attr_filter; int raster, back_transform; extern int optind; extern int optopt; extern char * optarg; if (argc < 2) { printUsage(); return(0); } // Provide default values. infile = morphfile = outfile = input_layer = NULL; attrs = spatial_filter = attr_filter = NULL; format = NULL; raster = 0; output_layer = "transformed_layer"; back_transform = 0; // Process command line while (1) { static struct option long_options[] = { {"help", no_argument, 0, 'h'}, {"input", required_argument, 0, 'i'}, {"morphfile", required_argument, 0, 'm'}, {"output", required_argument, 0, 'o'}, {"format", required_argument, 0, 'f'}, {"raster", no_argument, 0, 'r'}, {"input_layer", required_argument, 0, '1'}, {"spatial_filter", required_argument, 0, 's'}, {"attr_filter", required_argument, 0, 'w'}, {"output_layer", required_argument, 0, '2'}, {"attrs", required_argument, 0, 'a'}, {"back", no_argument, 0, 'b'}, {0, 0, 0, 0} }; c = getopt_long(argc, (char**)argv, "hi:m:o:f:r1:s:w:a:2:b", long_options, NULL); if (c == -1) { break; } switch (c) { case 'h': printUsage(); return 0; case 'i': infile = optarg; break; case 'o': outfile = optarg; break; case 'm': morphfile = optarg; break; case 'f': format = optarg; break; case '1': input_layer = optarg; break; case 's': spatial_filter = optarg; break; case 'a': attrs = optarg; break; case 'w': attr_filter = optarg; break; case '2': output_layer = optarg; break; case 'r': raster = 1; break; case 'b': back_transform = 1; break; case '?': return 1; default: printUsage(); abort(); } } // Input value checking. if (morphfile == NULL) { fprintf(stderr, "Error. You must supply a morph file.\n"); exit(1); } if ((infile == NULL && outfile != NULL) || (infile != NULL && outfile == NULL)) { fprintf(stderr, "Error. Specify an input and an output file.\n"); exit(1); } // Call the appropriate function for transforming the input layer. // If input and output files are not given, read the coordinates from standard input and // write the transformed values to the standard output. if (infile == NULL && outfile == NULL) { ok = coord_transform(morphfile, back_transform); return ok; } printf("r.morph.transform starting\n"); // We have input and output files. Choose between raster and vector. if (raster) { ok = raster_transform(infile, morphfile, outfile, format, back_transform); } else { ok = vector_transform(infile, input_layer, spatial_filter, attr_filter, morphfile, outfile, attrs, format, output_layer, back_transform); } printf("r.morph.transform done\n"); return ok; }
struct fbook * fbook_init(char *filename, struct board *b) { if (fbcache && fbcache->bsize == board_size(b) && fbcache->handicap == b->handicap) return fbcache; FILE *f = fopen(filename, "r"); if (!f) { perror(filename); return NULL; } struct fbook *fbook = calloc(1, sizeof(*fbook)); fbook->bsize = board_size(b); fbook->handicap = b->handicap; /* We do not set handicap=1 in case of too low komi on purpose; * we want to go with the no-handicap fbook for now. */ for (int i = 0; i < 1<<fbook_hash_bits; i++) fbook->moves[i] = pass; if (DEBUGL(1)) fprintf(stderr, "Loading opening fbook %s...\n", filename); /* Scratch board where we lay out the sequence; * one for each transposition. */ struct board *bs[8]; for (int i = 0; i < 8; i++) { bs[i] = board_init(NULL); board_resize(bs[i], fbook->bsize - 2); } char linebuf[1024]; while (fgets(linebuf, sizeof(linebuf), f)) { char *line = linebuf; linebuf[strlen(linebuf) - 1] = 0; // chop /* Format of line is: * BSIZE COORD COORD COORD... | COORD * BSIZE/HANDI COORD COORD COORD... | COORD * We descend up to |, then add the new node * with value minimax(1000), forcing UCT to * always pick that node immediately. */ int bsize = strtol(line, &line, 10); if (bsize != fbook->bsize - 2) continue; int handi = 0; if (*line == '/') { line++; handi = strtol(line, &line, 10); } if (handi != fbook->handicap) continue; while (isspace(*line)) line++; for (int i = 0; i < 8; i++) { board_clear(bs[i]); bs[i]->last_move.color = S_WHITE; } while (*line != '|') { coord_t *c = str2coord(line, fbook->bsize); for (int i = 0; i < 8; i++) { coord_t coord = coord_transform(b, *c, i); struct move m = { .coord = coord, .color = stone_other(bs[i]->last_move.color) }; int ret = board_play(bs[i], &m); assert(ret >= 0); } coord_done(c); while (!isspace(*line)) line++; while (isspace(*line)) line++; } line++; while (isspace(*line)) line++; /* In case of multiple candidates, pick one with * exponentially decreasing likelihood. */ while (strchr(line, ' ') && fast_random(2)) { line = strchr(line, ' '); while (isspace(*line)) line++; // fprintf(stderr, "<%s> skip to %s\n", linebuf, line); } coord_t *c = str2coord(line, fbook->bsize); for (int i = 0; i < 8; i++) { coord_t coord = coord_transform(b, *c, i); #if 0 char conflict = is_pass(fbook->moves[bs[i]->hash & fbook_hash_mask]) ? '+' : 'C'; if (conflict == 'C') for (int j = 0; j < i; j++) if (bs[i]->hash == bs[j]->hash) conflict = '+'; if (conflict == 'C') { hash_t hi = bs[i]->hash; while (!is_pass(fbook->moves[hi & fbook_hash_mask]) && fbook->hashes[hi & fbook_hash_mask] != bs[i]->hash) hi++; if (fbook->hashes[hi & fbook_hash_mask] == bs[i]->hash) hi = 'c'; } fprintf(stderr, "%c %"PRIhash":%"PRIhash" (<%d> %s)\n", conflict, bs[i]->hash & fbook_hash_mask, bs[i]->hash, i, linebuf); #endif hash_t hi = bs[i]->hash; while (!is_pass(fbook->moves[hi & fbook_hash_mask]) && fbook->hashes[hi & fbook_hash_mask] != bs[i]->hash) hi++; fbook->moves[hi & fbook_hash_mask] = coord; fbook->hashes[hi & fbook_hash_mask] = bs[i]->hash; fbook->movecnt++; } coord_done(c); } for (int i = 0; i < 8; i++) { board_done(bs[i]); } fclose(f); if (!fbook->movecnt) { /* Empty book is not worth the hassle. */ fbook_done(fbook); return NULL; } struct fbook *fbold = fbcache; fbcache = fbook; if (fbold) fbook_done(fbold); return fbook; } void fbook_done(struct fbook *fbook) { if (fbook != fbcache) free(fbook); }
void vr_define_clip_planes( VRState *state, float ucp[][4] ) { int i, j; Coord p1, p2, p3, n; float w1, w2, w3, d; GLdouble cp[MAX_CLIP_PLANES][4]; for (i = 0; i < state->planeData->nPlanes; i++) { n[0] = state->planeData->plane[i].a; n[1] = state->planeData->plane[i].b; n[2] = state->planeData->plane[i].c; /* Transform the plane normal by the world rotation */ coord_transform(n, state->view->invRotMat, n); d = state->planeData->plane[i].d; /* Define the clip plane */ cp[i][0] = n[0]; cp[i][1] = n[1]; cp[i][2] = n[2]; cp[i][3] = d; glClipPlane(GL_CLIP_PLANE0 + i, cp[i]); /* Find three independent points on the plane */ n[0] = state->planeData->plane[i].a; n[1] = state->planeData->plane[i].b; n[2] = state->planeData->plane[i].c; find_points_on_plane(n, d, p1, p2, p3); /* Transform the points and do the homogenous divide */ coord_transw(p1, state->view->WTSMat, w1); coord_transw(p2, state->view->WTSMat, w2); coord_transw(p3, state->view->WTSMat, w3); coord_transform(p1, state->view->WTSMat, p1); coord_transform(p2, state->view->WTSMat, p2); coord_transform(p3, state->view->WTSMat, p3); coord_div(p1, w1, p1); coord_div(p2, w2, p2); coord_div(p3, w3, p3); /* Create two vectors from the three points */ coord_sub(p2, p1, p2); coord_sub(p3, p1, p3); /* The important vector is the cross product of two transfrmd vectors */ coord_cross_product(p2, p3, p1); /* Determine direction */ if (p1[2] < 0) { state->planeData->plane[i].facing = PLANE_FACING_AWAY; } else { state->planeData->plane[i].facing = PLANE_FACING_TOWARDS; } } if (ucp != NULL) { for (i = 0; i < state->planeData->nPlanes; i++) { for (j = 0; j < 4; j++) { ucp[i][j] = (float) cp[i][j]; } } } }