We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › aggregating cubes
Page Index Toggle Pages: 1
aggregating cubes (Read 709 times)
aggregating cubes
Jul 18th, 2007, 7:23pm
 
I'm looking for some algorithmic advice.  I don't expect code, but if anyone can suggest a link or search words to help narrow it down that'd be great!  Smiley

Given a 3D grid of cells (int [][][]), where 0==unoccupied and 1==occupied, convert it into rectangular polygonal solids ("boxes") such that the maximum number of adjacent occupied cells convert into the largest possible boxes.  Essentially aggregating the implied cubes into larger polygon-representation boxes.

Another way of saying it: given a voxel space, determine the minimal set of maximal axis-aligned bounding boxes that fully contain only the occupied voxels.  (which suggests an octree as potential intermediate representation, but total brain-fart on how I'd actually use it once built)

For example, take a 2D case:  on a 5x5 grid, the entire top row is occupied, but only the first 4 rows of the first column are occupied (8 occupied cells total).  Ideally, that would produce a 5x1 unit box along the top, and a 1x3 unit box along the left.  Then consider the broader cases, like if the first two rows were entirely filled (14 total, solution:  5x2, 1x2). Then extend to 3D...

Even obtaining a "pretty good" solution would probably suffice.  (I suspect the optimal solution is hard for arbitrary data)  I have an ugly hack that sort of works, via brute force nested loop manual span scanning, but it's time to look for a better way!  Thanks for any ideas.
Re: aggregating cubes
Reply #1 - Jul 18th, 2007, 7:35pm
 
From a quick think.. I'm afraid that problem coudl be one that's considered "hard" in computer science circles. And hard tends to be an understatement Smiley

I think it might be more efficient to find the "surface" voxels, and draw them all as single boxes if it's a dynamic system. (i.e. for each element, see if there's a 0 along one of the orthogonal axes, if so, draw it, if not, move along)

Re: aggregating cubes
Reply #2 - Jul 18th, 2007, 8:32pm
 
Right, could be "hard" as in "NP-Hard".  That's why I'd settle for "pretty good".

This is a mashup, feeding the voxel-type sketch's data into a polygon-type sketch. The polygon sketch will only be interesting with the larger aggregated volumes, but the voxel sketch needs all intended cells filled.

I'll give your "surface" suggestion some thought, it might help, but will be tricky.  There's two approaches, right?: have the voxel-sketch "track" the larger boxes, or have the polygon-sketch "discover" the larger boxes.  Voxel-sketch jumps all around, with no notion of "travelling to adjacent neighbor", so that makes that tricky.

Might be able to concurrently maintain two voxels, one for internal use, one for export with surfaces only.  Or could post-process with some sort of "hollowing-out" edge detector, hmm..

Anyway, much thanks for the suggestion, and sparking further ideas.  Smiley
Re: aggregating cubes
Reply #3 - Jul 18th, 2007, 9:28pm
 
If you're going for polygons of only larger areas, you could extend the surface idea a bit...

For example, when you find a "on the outside" voxel, check to see if the adjacent voxels have the same "outside" direction, and if enough in the same plane have the same "outside" face, export a quad of the surface. You may have to not stop with a single mising voxel, or covered one, if there's plenty of co-planar surface ones.

What I mean is, imagine a 5x5 plane of voxels with one side being unfilled and the other filles, and the middle one is covered unlike all the others. Don't stop for one, since then you'd end up with 4 2x2 quads, and 4 2x1/1x2 quads, whereas you could have a single 5x5 one and an extra box on the outside.
Page Index Toggle Pages: 1