kdtree备份

库在这里

这个很好用。

例子:

/*! gcc -Wall -g -o test test.c libkdtree.a */
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <assert.h>
#include <time.h>
#include "kdtree.h"

int main(int argc, char **argv)
{
    ;
    void *kd, *set;
    unsigned int msec, start;

     && isdigit(argv[][])) {
        vcount = atoi(argv[]);
    }
    printf("inserting %d random vectors... ", vcount);
    fflush(stdout);

    kd = kd_create();

    start = clock();
    ; i<vcount; i++) {
        float x, y, z;
        x = ((float)rand() / RAND_MAX) * 200.0 - 100.0;
        y = ((float)rand() / RAND_MAX) * 200.0 - 100.0;
        z = ((float)rand() / RAND_MAX) * 200.0 - 100.0;

        assert(kd_insert3((kdtree*)kd, x, y, z, ) == );
    }

    msec = clock() - start;
    printf("%.3f sec\n", (float)msec);

    start = clock();
    //set = kd_nearest_range3((kdtree*)kd, 100, 100, 100, 30);
    ,,);
    msec = clock() - start;
    printf("range query returned %d items in %.5f sec\n", kd_res_size((kdres*)set), (float)msec);

    ];
    while (!kd_res_end((kdres*)set)) {
        /* get the data and position of the current result item */
        kd_res_item((kdres*)set, pos);

        /* print out the retrieved data */
        printf("node at (%.3f, %.3f, %.3f)\n",
            pos[], pos[], pos[]);

        /* go to the next entry */
        kd_res_next((kdres*)set);
    }

    kd_res_free((kdres*)set);

    kd_free((kdtree*)kd);
    getchar();
    ;
}
上一篇:linux wenjian


下一篇:JS和jQuery中ul li遍历获取对应的下角标