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!
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.