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;
    }
    复制代码
  • 相关阅读:
    建造者模式
    js日期转化(计算一周的日期)
    vue实现全选效果
    less入门
    使用node初始化项目
    ES5新语法forEach和map及封装原理
    es6中的promise对象
    深入理解jsonp跨域请求原理
    markdown语法与使用
    Ajax商品分类三级联动实现
  • 原文地址:https://www.cnblogs.com/tiandsp/p/7440832.html
Copyright © 2011-2022 走看看