0

This question should be pretty easy to answer and I have a feeling there's probably a lot of documentation on the subject but I couldn't find anything in my searches so I presume I'm searching for the wrong thing.

Let's imagine I have a world of equal sized cubes, each with a value either 1 or 0.

What's the best method for merging cubes of a similar value into the largest possible cuboid. I considered just grabbing one at random and checking the adjacent nodes and combination them if they're all the same vague and repeating, but obviously the result would not be particularly optimised. I also considered checking every possible combination of cubes and comparing the results but that would be incredibly expensive.

Any help anyone could render would be very helpful.

Oh, to clarify, I'm looking for a method of constructing a KD tree out of orthogonal collision data to help optimise path finding.

Fascia
  • 732
  • 6
  • 17

1 Answers1

0

I'm assuming your world is a 3D "grid" of cubes. Is this correct? If so, a typical way to subdivide and organize a cubic space is using an Octree. http://en.wikipedia.org/wiki/Octree

EDIT: you may want to implement a 3D version of this: http://en.wikipedia.org/wiki/Connected_Component_Labeling

Tom
  • 18,685
  • 15
  • 71
  • 81
  • I considered an oct-tree as it would be considerably easier to construct, but wouldn't it have certain disadvantages compared to a KD tree? – Fascia Feb 03 '11 at 21:04
  • Just now noticed your edit, Fascia. Sorry, I got thrown by the previous title. ;-) So it sounds like you're attempting to "segment" the world into regions. Is this correct? Depending on the boundary conditions you wish the regions to have, there are a number of ways to accomplish this. Is the goal to get regions that all have the same value, or just "similar" values? – Tom Feb 03 '11 at 21:11
  • Also, do the regions need to be cube-shaped themselves? – Tom Feb 03 '11 at 21:13
  • Yes exactly, and no, the regions don't need to be cubes, but they do need to be cuboid. And yeah, the idea is for a cuboid to be entirely the same value. – Fascia Feb 03 '11 at 21:21
  • Sounds like this is very related to connected component labeling. http://en.wikipedia.org/wiki/Connected_Component_Labeling You might consider implementing a 3D version of this, which would be very efficient. During the labeling process, it should be fairly straightforward to get the "bounding box" of each label, which, if I'm not mistaken, is the cuboid you're talking about. – Tom Feb 03 '11 at 21:46
  • Although interesting (I've bookmarked it) that's not exactly what I'm talking about, I'm talking turning a flat array of cubes into a kd-tree by grouping the cubes into the largest possible cuboids. While what you linked calculates whether two objects are connected or not. – Fascia Feb 04 '11 at 00:28