static void compare_pairs_inner() { struct timeval start_time, last_update; gettimeofday(&start_time, NULL); gettimeofday(&last_update, NULL); float counter = 0; float total = ((float)num_data * num_data) / 2; for (int x = 0; x < num_data; x++) { if (available[x]) { int start = x + 1; int next_4 = min(((start - 1) / 4 + 1) * 4, num_data); int last_4 = max(num_data & (~3), start); if (0) printf ("for %d begin=[%d-%d) end=[%d-%d) fast=[%d-%d)\n", x, start, next_4, last_4, num_data, next_4, last_4); for (int y = start; y < next_4; y++) { INNER(x, y); } for (int y = last_4; y < num_data; y++) { INNER(x, y); } for (int y = next_4; y < last_4; y += 4) { INNER(x, y + 0); INNER(x, y + 1); INNER(x, y + 2); INNER(x, y + 3); } } if (!quiet) { counter += num_data - x; struct timeval tm2; gettimeofday(&tm2, NULL); unsigned long long time_since_last_update = 1000 * (tm2.tv_sec - last_update.tv_sec) + (tm2.tv_usec - last_update.tv_usec) / 1000; if (time_since_last_update > 200) { last_update = tm2; unsigned long long time_so_far_in_ms = 1000 * (tm2.tv_sec - start_time.tv_sec) + (tm2.tv_usec - start_time.tv_usec) / 1000; float percent_done = counter / total; float time_so_far_in_sec = time_so_far_in_ms / 1000.0; float total_time = time_so_far_in_sec / percent_done; float remaining_time = total_time * (1.0 - percent_done); fprintf(stderr, "Calculating hamming distances: %.0f/%.0f = %.2f%% [%llu secs used] [%d secs remaining]\r", counter / 100000000.0, total / 100000000.0, 100.0 * percent_done, time_so_far_in_ms / 1000, (int)remaining_time); } } } if (!quiet) { struct timeval tm2; gettimeofday(&tm2, NULL); unsigned long long time_so_far_in_ms = 1000 * (tm2.tv_sec - start_time.tv_sec) + (tm2.tv_usec - start_time.tv_usec) / 1000; fprintf(stderr, "Finished calculating histogram distances in %llu secs \n", time_so_far_in_ms / 1000); } }
void rayTrace(const mxArray *N, const mxArray *d, const mxArray *T, const mxArray *O, const mxArray *D, mxArray **polygon, mxArray **intersection, mxArray **tvalue ) { /* * plane representation : Np + d = 0 * ray representation : r(t) = O + Dt * => intersection point: t = - (d + NO) / ND */ int m = mxGetM(N); int nrPolygons = mxGetN(N); double *normal = mxGetPr(N); double *planeD = mxGetPr(d); double *T34 = mxGetPr(T); double *origin = mxGetPr(O); double *direction = mxGetPr(D); int i; double *best_t, *P, *R; *polygon = mxCreateDoubleMatrix(1, 1, mxREAL); *intersection = mxCreateDoubleMatrix(3, 1, mxREAL); *tvalue = mxCreateDoubleMatrix(1, 1, mxREAL); P = mxGetPr(*polygon); R = mxGetPr(*intersection); best_t = mxGetPr(*tvalue); *best_t = -1; for(i=0;i<nrPolygons;i++,normal+=3,planeD++,T34+=12) { double NO = INNER(normal,origin); double ND = INNER(normal,direction); if (ND!=0) /* if polygon not parallel to ray */ { double t = -(*planeD+NO)/ND; if (t>0 && (*best_t<0 || t<*best_t)) /* if intersection on positive side of ray and smaller than best so far */ { /* the actual intersection point */ double rx = origin[0] + t*direction[0]; double ry = origin[1] + t*direction[1]; double rz = origin[2] + t*direction[2]; /* calculate 2D coordinate within polygon frame */ double a = T34[0]*rx+T34[3]*ry+T34[6]*rz+T34[ 9]; double b = T34[1]*rx+T34[4]*ry+T34[7]*rz+T34[10]; /* if inside polygon, we have a winner */ if (a>=0 && b>=0 && (a+b)<=1) { *best_t = t; *P = i+1; R[0]=rx;R[1]=ry;R[2]=rz; } } } } }
int main() { foo( OUTER( INNER(17) ) ); _PASS }