zoukankan      html  css  js  c++  java
  • 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
    ", (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
    ", 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)
    ",
                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;
    }
    复制代码
  • 相关阅读:
    文件上传利器JQuery上传插件Uploadify
    记自己的第一个完整的java web项目
    win7下oracle的安装
    Linux下redis的安装
    微信公众号开发地理位置坐标的转换
    Apache Log4j配置说明
    eclipse安装svn插件
    网站引入外部js
    蛇形填数
    第一节:Scrapy开源框架初探
  • 原文地址:https://www.cnblogs.com/tiandsp/p/7440832.html
Copyright © 2011-2022 走看看