首页 > 代码库 > kdtree备份
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){ long i, vcount = 5000; void *kd, *set; unsigned int msec, start; if (argc > 1 && isdigit(argv[1][0])) { vcount = atoi(argv[1]); } printf("inserting %d random vectors... ", vcount); fflush(stdout); kd = kd_create(3); start = clock(); for (i = 0; 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, 0) == 0); } msec = clock() - start; printf("%.3f sec\n", (float)msec); start = clock(); //set = kd_nearest_range3((kdtree*)kd, 100, 100, 100, 30); set=kd_nearest3((kdtree*)kd, 100,100,100); msec = clock() - start; printf("range query returned %d items in %.5f sec\n", kd_res_size((kdres*)set), (float)msec); double pos[3]; 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[0], pos[1], pos[2]); /* go to the next entry */ kd_res_next((kdres*)set); } kd_res_free((kdres*)set); kd_free((kdtree*)kd); getchar(); return 0;}
kdtree备份
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。