How to handle voxels with root?


I have a challenging problem to solve…

I need to store a floating number (the scattering-density) for each of my 3D voxel. The number of voxels along coordinate axis are about 200 (x), 200 (y), 100 (x), for a total of 200x200x100 voxels.
Then I need to play with density for analysis (e.g. find the local maximum, the mean in 3x3 voxels, etc).

What’s the best way to store the variables?

  1. I’ve tried to fill a tree, but then it’s difficult to find adjacent voxels (they are not necessarily in consequent entries)

  2. I’ve tried an array: Float_t voxel[2550000];
    same problem I have with trees, plus for dimensions greater then 2550000 root exits without executing. Why?

  3. 3D arrays: easy to navigate in space, but I have
    the same dimension-problem:
    Float_t voxelMtx[100][100][100]; //matrix for analysis
    exit without executing.

What’s the best way to handle this data? Are there examples provided?



For 2) and 3) the limitation you hit is the limit in the stack size. This is control by your os and/or shell (see ulimit). Usually you can simply work around it by allocating on the heap:

For 3, it might be (or not :slight_smile:) more convenient to use a vector<vector<vector > >;


If you have a (very?) sparse density, you may want to consider

std::map< something, float >

where something could be a string, an integer (e.g., =200200x + 200y + 100z) or something else. It probably won’t be the fasted (although I’d be surprised if you really noticed) and should work fairly nicely.


allocating on the heap gives me the same memory-problem when I fill the array and reach the limit… other hints?

Thanks a lot


How densely populated are your bins? Did you try the map?

Thanks! the map works greatly! :smiley:


[quote]allocating on the heap gives me the same memory-problem when I fill the array and reach the limit… other hints?[/quote]I am not sure that you mean by “reach the limit”, do you still allocate after the first large allocation? What do you do when you ‘fill’ the array?