GithubHelp home page GithubHelp logo

rvalavi / kd-tree Goto Github PK

View Code? Open in Web Editor NEW

This project forked from gishi523/kd-tree

0.0 0.0 0.0 14 KB

An implementation of k-d tree for searching

License: MIT License

C++ 97.43% CMake 2.57%

kd-tree's Introduction

kd-tree

A c++ implementation of k-d tree

Description

  • A C++ implementation of k-d tree
  • Header-only library
  • Provides following Nearest neighbor search functions
    • Nearest neighbor search
    • K-nearest neighbor search
    • Radius search
  • Supports both L1 and L2 distances (new feature)

How to use KDTree class

  • KDTree class takes a user-defined Point type as its template parameter
  • A user-defined Point type needs to satisfy following specifications
    • Implementation of operator[] <= accessor to its coordinates
    • Static member variable DIM <= dimension of the Point
  • Passing point cloud to KDTree constructor starts to build k-d tree
  • After building k-d tree, you can use Nearest neighbor search functions
#include "kdtree.h"

// user-defined Point type (inherits std::array in order to use operator[])
class MyPoint : public std::array<double, 2>
{
public:

	// dimension of the Point
	static const int DIM = 2;

	// As you want
	// ...
};

int main()
{
	// generate point cloud
	std::vector<MyPoint> points = ...;

	// build k-d tree
	kdt::KDTree<MyPoint> kdtree(points);

	// K-nearest neighbor search (gets indices to neighbors)
	int k = 10;
	MyPoint query = ...;
	std::vector<int> indices = kdtree.knnSearch(query, k);

	return 0;
}

Requirement

  • OpenCV (only for running sample code)

Sample code

How to build

$ git clone https://github.com/gishi523/kd-tree.git
$ cd kd-tree
$ mkdir build
$ cd build
$ cmake ../
$ make

How to run

./kdtree [seed]
  • seed
    • Seed of rand() in generating random point cloud

Author

gishi523

kd-tree's People

Contributors

gishi523 avatar robert-lu avatar rvalavi avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.