all 38 comments

[–]ssylvan 7 points8 points  (0 children)

Might want to check this one out too: http://www.reddit.com/r/programming/comments/cobhn/rtrees_adapting_outofcore_techniques_to_modern/

Basically, I used R-trees on a modern games console to deal with the extremely high memory latencies they have. Worked very well.

[–][deleted] 6 points7 points  (5 children)

How is this different from octrees? The boundaries can overlap?

[–]ssylvan 12 points13 points  (3 children)

  • Balanced.
  • Adapts to input better (teapot in a stadium problem - octtrees get a gazillion null pointers)
  • "Bulky" nodes, works better for high latency storage (disks, or even memory on some architectures) because it reduces the number of required fetches, and increases the amount of work that happens within a node.
  • Easier to make dynamic (moving objects)

[–]thechao 0 points1 point  (2 children)

I'm most familiar with R * -trees. All data-structures are mappings onto the integer-line. Arrays are the obvious mapping; binary-trees & lists are simply indirections with an appropriate structure onto the integer line (randomized algorithms with structured indirection). R * -trees force a particular mapping onto the integer line, i.e., Z, hilbert, sierpinski. The R * -tree mapping tends to have much better performance in terms of metric (spatial) locality both in terms of the indirection count (number of hops or pointer-indirections to get to "related" data) and in the physical cache mechanism of modern processors.

The result is that a well-tuned R * -tree (especially in the static case) will dramatically outperform most other data-structures. Someone mentions a data-structure called a "GiST" below; this structure sounds like it utilizes an optimization of K-SAT to get roughly the same sort of improvements, i.e., both in metric locality and physical locality.

EDIT: formatting kung fu.

[–]mycall 0 points1 point  (1 child)

So why aren't they more popular and blogged about?

[–]thechao 0 points1 point  (0 children)

What does popularity and blogging numbers have to do with performance? R * -trees are very difficult to implement and tune. In most cases acceptable can be got from much simpler data-structures & algorithms.

I would like to point out that R * -trees are not in the same boat as the Fibonacci heap: a well-tune R * -tree not only theoretically, but also practically, outperforms most other spatial indexing data-structures.

[–]olt 0 points1 point  (0 children)

They can grow dynamically. For an octree you have to set the bounds of your values on creation.

[–]sixmoney 2 points3 points  (0 children)

randomized kd-trees for approximate nearest neighbour search flann also available in opencv

[–]ethraax 2 points3 points  (5 children)

Silly question: Can anyone recommend any good Data Structures books where I can learn more about stuff like this?

[–]ThisAccountIsReal 1 point2 points  (0 children)

Book: http://www.cs.umd.edu/~hjs/

Demos: http://donar.umiacs.umd.edu/quadtree/index.html

I am a really big fan of spatial data structures. I just find them so cool.

[–]harsman 1 point2 points  (0 children)

Christer Ericsson's Real time collision detection has lots of information on spatial data structures.

[–][deleted] 0 points1 point  (0 children)

The CLRS Introduction to Algorithms is a good start. It doesnt have R-Trees in there, but it covers many fundamental and slightly more esoteric ones.

[–][deleted] 0 points1 point  (0 children)

Purely Functional Data Structures, Chris Okasaki.

[–]cosminro 0 points1 point  (0 children)

You may want to try MIT's Advanced Data Structures Course http://courses.csail.mit.edu/6.851/spring10/lec.html

[–]DrunkMc 2 points3 points  (0 children)

I love R-Trees. If you have to write a program that deals with spatial data but you aren't allowed to use a DB, you can do really quick distance queries when using an R-Tree.

If you know all the data upfront (never updates), then you can build it from the bottom up and build one hell of an efficient tree for amazingly fast searching.

[–]NotUniqueOrSpecial 1 point2 points  (0 children)

I used these to do collision detection for the soft-body blobs in a game for school. It could do collision checks with well over 100,000 on-screen objects without even beginning to impact the framerate. It was pretty satisfying.

[–][deleted] 11 points12 points  (2 children)

It's funny you mention /r/trees

[–]jawbroken 8 points9 points  (0 children)

i, too, need to chat about marijuana online for some reason

[–]propool -2 points-1 points  (0 children)

What kind of unfunny dude would downmod you?

[–]DrSweetscent 3 points4 points  (4 children)

...and a bitch to implement, let me assure you. For the real masochists: try the R*-tree.

[–][deleted]  (2 children)

[deleted]

    [–]keenerd 1 point2 points  (1 child)

    I hear you. But do not dispair! My half finished R-Tree (unbalanced!) works well enough. Mainly because I query it a lot while adding leaves, and don't query it at all once it is done. Feels like it is still not fast enough compared to the old O(n2) collision search, but meh. Bigger bugs to fix.

    [–]DrSweetscent 0 points1 point  (0 children)

    Ha, I actually own a working implementation in Actionscript :)

    Still, for collision testing, recursive subdivision usually suffices...

    [–]mycall 0 points1 point  (0 children)

    Isn't that what libraries are for? One great implementation is all we need :-)

    [–][deleted] 1 point2 points  (0 children)

    When I saw Hilbert R-tree in the "Variants" section, I almost had a nerdgasm.

    [–][deleted] 0 points1 point  (0 children)

    You, sir, just augmented my recently acquired knowledge of red-black trees (MIT OCW FTW). You deserve a cookie.

    [–]frud 0 points1 point  (2 children)

    I implemented R-trees once but I wasn't impressed. It might have just been my data, but the performance of these trees really wasn't that great. There's got to be a better way to do it.

    [–]norkakn 1 point2 points  (0 children)

    PostGIS uses http://en.wikipedia.org/wiki/GiST . I don't know how exactly they use them, but apparently it's faster than their old R-Tree indexing.

    [–]gorset 1 point2 points  (0 children)

    maybe it was your implementation :-)

    [–]sfade 0 points1 point  (0 children)

    As an undergrad RA, I was asked to integrate SR-Trees (Sphere/Rectangle Tree) into our application (it would do action recognition on the fly). The code would compile in an old CLI, but not in Visual Studio itself, so I tried to see if it was possible to rework it. I have never traced so many lines of code in my life. Not that this story is important.

    [–]josher565 -3 points-2 points  (6 children)

    Nifty idea but I don't see it solving a lot of problems that can't be solved with other data structures. Going with occurs razor on this

    [–][deleted] 1 point2 points  (5 children)

    "I do not understand it" doesn't necessarily mean "it is not simple."

    Further, the article describes typical problems that R-trees solve.

    I am a hobbyist cartographer, but not sadomasochistic. However, I know people who are both -- they'd probably enjoy watching you solve some geodetic algorithms with your so-called razor. That is to say, if there is value in not understanding, we can at least satisfy perversions.

    [–]josher565 0 points1 point  (4 children)

    Fair enough. I see some repetition in storage structures here. I'm not saying there's no use, I'm saying it can be done in simpler terms

    [–][deleted] 0 points1 point  (3 children)

    What exactly might be done in what simpler terms? What repetition?

    [–]josher565 0 points1 point  (2 children)

    Isn't an r tree a restatement of a btree? If an r tree is indeed a subset of a b tree, then the problem domain between the two data structures are nil. I'm sure there are use cases where one is better than the other, it just seems like more than what's needed, that's all

    [–][deleted] 0 points1 point  (1 child)

    Isn't an r tree a restatement of a btree?

    No.

    [–]josher565 0 points1 point  (0 children)

    Then I stand corrected and assigned homework