← Back

ofxSpatialHash

github.com/skell999/ofxSpatialHash · @skell999
OF 0.11 Algorithms 2D

Fast nearest neighbour lookup for 2d particle systems

0 0 Last commit 4y ago Created 4y ago

README

ofxSpatialHash

Fast nearest neighbour lookup for 2d particle systems

Tests

Debug Build

World size 1000 x 1000. Grid size 10. Search radius 150.
Adding ofVec2f as pointers ofxSpatialHash::addPoint()
PointsMilliseconds
1000.054
1,0000.302
10,0001.245
50,0005.035
100,0009.392
500,00047.302
1,000,00095.738
10,000,000995.733
Nearest neighbour search. Milliseconds.
PointsHash glmHash ofVec2fNaive glmNaive ofVec2f
1000.0040.0040.0120.008
1,0000.0180.0151.2040.573
10,0000.1360.105104.70351.006
50,0000.6830.5482609.961305.25
100,0001.4631.08710890.35574.67
500,0007.7695.615330835168685
1,000,00019.10712.219n/an/a
10,000,000207.801129.039n/an/a

Release Build

Adding ofVec2f as pointers ofxSpatialHash::addPoint()
PointsMilliseconds
1000.01
1,0000.07
10,0000.241
50,0000.968
100,0001.582
500,00012.341
1,000,00014.337
10,000,000268.345
Nearest neighbour search. Milliseconds.
PointsHash glmHash ofVec2fNaive glmNaive ofVec2f
100000.001
1,000000.140.251
10,0000.0050.00519.36925.852
50,0000.0430.057326.108295.424
100,0000.1540.1431103.81029.82
500,0000.8280.57228465.330356.9
1,000,0001.7071.711n/an/a
10,000,00023.67823.955n/an/a

License

MIT License

Installation

Git clone or copy into openFrameworks/addons/ folder.

Usage

First use

First initialise the hash with the correct dimensions ofxSpatialHash::init()
Points can be added to the hash with ofxSpatialHash::addPoint(float x, float y, T value)
Search for points getNearestPoints(float x, float y, float radius) and test for distance if necessary


Update points

Clear hash ofxSpatialHash::clear()
Add points ofxSpatialHash::addPoint(float x, float y, T value)


Example

All points contained in the green squares will be returned from a call to ofxSpatialHash::getNearestPoints(float x, float y, float radius)
Users need to test the returned points to see if they are inside the radius with a call to ofVec2f::distance or glm::distaance

Example

Known issues



Get this addon

HTTPS
SSH