8

I'm trying to implement a forward iterator for a quadtree. Unfortunately I don't seem to be able to find any resource about traversal in a quadtree.

Can anybody point me in the right direction?

Matt Mils
  • 81
  • 1
  • 2

3 Answers3

5

An easy way is to linearize the tree. You'll have to do it recursively, of course, but you'll make an array of pointers to the nodes you want to visit and then create a forward iterator from that.

Pochi
  • 2,026
  • 1
  • 15
  • 11
  • So simple so good! How come I didn't think of doing this. Now btw, I'm facing problems with nodes with one of the index equal to its parent. Seems I have to change the insert rules or something. Any idea? – Matt Mils Feb 04 '12 at 11:22
4

Take a gander at the following paper and see if it has what you need...

Simple and Efficient Traversal Methods for Quadtrees and Octrees

sigma
  • 2,758
  • 1
  • 14
  • 18
hatboyzero
  • 1,929
  • 1
  • 21
  • 44
3

This is my implementation in javascript: https://github.com/alexroat/quadtree-traversal

There is a visual demo that shows the behaviour of the algorithm.

alexroat
  • 1,687
  • 3
  • 23
  • 34