2

I'm currently creating a "neighbourhood graph" by doing roughly this:

for every voxel
  look at every other unseen voxel 
    check if neighbours

which runs roughly in n squared (minus n). It is acceptable for a certain number of voxels, but obviously it takes much more time with bigger lists.

Another naive solution is simply to put everything into either a big 3d array, or in a hashmap, which would run in O(n) but at the expense of much more memory.

Is there a faster way? I can't seem to enter the right search terms in google...

templatetypedef
  • 362,284
  • 104
  • 897
  • 1,065
Manux
  • 3,643
  • 4
  • 30
  • 42
  • 1
    The hash approach requires relatively little memory. It depends of your implementation language, but roughly the equivalent to 5 or 6 pointers/integers per point. – salva Jun 22 '12 at 12:41
  • If you have a 3d-array of evenly spaced voxels, then finding neighbors is trivial (+/- 1 in each index). If you are currently storing some information of each voxel in a large 1-d array, reshaping to a 3-d array does not change the size of your data. – Ruan Caiman Jun 22 '12 at 15:24

1 Answers1

4

You might want to look at space partitioning trees like the octree or k-d tree structures. These structures usually can be built very efficiently (O(n) or O(n log n), IIRC), and then provide extremely fast lookups for finding either nearest neighbors or points within a given bounding box. Using one of these structures should give you a huge performance boost without the huge memory cost of making a giant 3D array.

Hope this helps!

templatetypedef
  • 362,284
  • 104
  • 897
  • 1,065
  • "for finding either nearest neighbors or points within a given bounding box." How is this bounding box defined? – seralouk Nov 25 '20 at 09:57
  • These data structures let you do queries of the form “here’s a 2D or 3D box - what are all the points inside this box?” – templatetypedef Nov 25 '20 at 17:34