How to quickly count the number of neighboring voxels?

I have a 3D mesh (voxels) where some voxels are filled and some are not. A three-dimensional grid is rarely filled, so I got a set filledVoxelswith the coordinates (x, y, z) of the filled voxels. What I'm trying to do is find out, for each filled voxel, how many neighboring voxels are filled too.

Here is an example:

  • Filled Voxels contain voxels (1, 1, 1), (1, 2, 1) and (1, 3, 1).
  • Therefore, the calculations of the neighbors:
    • (1,1,1) has 1 adjacent
    • (1,2,1) has 2 neighborhoods
    • (1,3,1) has 1 neighbor.

I now have this algorithm:

voxelCount = new Map<Voxel, Integer>();

for (voxel v in filledVoxels)
  count = checkAllNeighbors(v, filledVoxels);
  voxelCount[v] = count;
end

checkAllNeighbors () scans all 26 surrounding voxels. Thus, in general, I execute 26 * filled Voxels.size () requests, which is pretty slow.

? , , voxels , .

, 3D- ( ). , 5 6 .

+3
8

voxel octree, node , , .

node , .

+5

, (O ()), (O (log (size))).

26, . , - 26 → 10 -, , , , - .

+2

, 26 . , . , O (N ^ 2), . , , :

voxelCount = new Map<Voxel, Integer>();
visitedVoxels = new EfficientSpatialDataType();

for (voxel v in filledVoxels)
  for (voxel n in neighbors(v))
    if (visitedVoxels.contains(n))
      voxelCount[v]++;
      voxelCount[n]++;
    end
  next
  visitedVoxels.add(v);
next

, kd-tree, , . , .

+2

, , , , , IsFullVoxel(), . , , , , IsFullVoxel(), .

OTOH , , IsFullVoxel() LUT. , . , , , , . , , 5-6 , , 7 22 .

, IsFullVoxel(), true, voxel .

+1

, 25%, , , .

+1

Z-order curve . ( ) , , , , .

+1

, . , . , ( - , kd-tree, O(log n)).

(.. ), 3d- bools. 26 ( ).

, , , longs (64 ). 64- 64 (4 4 4) . , 64- ( ).

0

?

, , 1 . , , , .

, , , .

Pseudo C :

#define MAXX 100
#define MAXY 100
#define MAXZ 100

int x, y, z
char countArray[MAXX][MAXY][MAXZ];

initializeCountArray(MAXX, MAXY, MAXZ);  // Set all array elements to 0

for(x=0; x<MAXX; x++)
   for(y=0;y<MAXY;y++)
      for(z=0;z<MAXZ;z++)
         if(VoxelExists(x,y,z))
            incrementNeighbors(x,y,z);

initializeCountArray, 0.

, incrementNeighbors, . , incrementNeighbrs, , .

1 26 . , () . , - 26 , , .

(.. ​​ ?) . , 2,3,5 , countArray [2] [3] [5].

1 . , , , .

, . , , , , . - , , , , , , .

0
source

Source: https://habr.com/ru/post/1710407/


All Articles