Esempio n. 1
0
File: prop.c Progetto: j0sh/thesis
static unsigned match_enrich(kd_tree *t, int *coeffs, int x, int y,
    int *prev)
{
    int k = t->k, *start = t->start;
    kd_node *n  = kdt_query(t, coeffs);

    // set results of query
    int64_t res = match_score(coeffs, n, k);
    int best[] = {INT_MAX, UNPACK_SCORE(res)};
    int pos[] = {INT_MAX, n->value[UNPACK_IDX(res)] - start};

    pos[0] = pos[1]; // hack for (x,y) == (0,0)

    // now check 2 best matches for the left
    if (x) {
        check_guide(t, coeffs, prev[-1], best, pos);
        check_guide(t, coeffs, prev[-2], best, pos);
    }

    // check 2 best matches for top
    if (y) {
        check_guide(t, coeffs, prev[0], best, pos);
        check_guide(t, coeffs, prev[1], best, pos);
    }

    // set prev to best matches
    prev[0] = pos[0];
    prev[1] = pos[1];
    return pos[1];
}
Esempio n. 2
0
int main (int argc, char * argv[])
{
  if (argc != 2) {
    fprintf (stderr, "Usage: %s basename\n", argv[0]);
    return -1;
  }

  Kdt * kdt = kdt_new ();
  if (kdt_open (kdt, argv[1])) {
    fprintf (stderr, "%s: could not open `%s'\n", argv[0], argv[1]);
    return -1;
  }

  KdtRect query;
  int count = 0;
  //  GTimer * t = g_timer_new ();
  while (scanf ("%f %f %f %f", 
		&query[0].l, &query[1].l, 
		&query[0].h, &query[1].h) == 4) {
#if 1
    fprintf (stderr, "%ld\n", kdt_query (kdt, query));
#else
    KdtSum s;
    kdt_sum_init (&s);
    //    g_timer_start (t);
    long n = kdt_query_sum (kdt, (KdtCheck) kdt_includes, (KdtCheck) kdt_intersects, 
			    query, query, &s);
    //    g_timer_stop (t);
    //    fprintf (stderr, "%d %g %g %g %g\n", n, s.H0, s.Hmax, s.Hmin, g_timer_elapsed (t, NULL));
    printf ("%ld %g %g %g\n", n, s.H0, s.H1, s.H2);
#endif
    if (count > 0 && count % 1000 == 0)
      fprintf (stderr, "\r%d", count);
    count++;
  }
  if (count >= 1000)
    fputc ('\n', stderr);

  kdt_destroy (kdt);
  return 0;
}