Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some voxels out of bounds #1

Open
m-schuetz opened this issue Mar 6, 2023 · 1 comment
Open

Some voxels out of bounds #1

m-schuetz opened this issue Mar 6, 2023 · 1 comment

Comments

@m-schuetz
Copy link
Owner

  • When mapping float coordinates to quantized voxel coordinates, the coordinate should be clamped to [0, gridSize - 1]
  • Code below occasionally maps coordinates to exactly gridSize if a sample is roughly equal to the bounding box maximum.
  • Occurs in first-come and random sampling strategies

int ix = float(bitgrid_size) * (point.x - child->min.x) / childSize.x;
int iy = float(bitgrid_size) * (point.y - child->min.y) / childSize.y;
int iz = float(bitgrid_size) * (point.z - child->min.z) / childSize.z;

Should be clamped like this:

int ix = clamp(fGridSize * (point.x - node->min.x) / boxSize.x, 0.0f, fGridSize - 1.0f);
int iy = clamp(fGridSize * (point.y - node->min.y) / boxSize.y, 0.0f, fGridSize - 1.0f);
int iz = clamp(fGridSize * (point.z - node->min.z) / boxSize.z, 0.0f, fGridSize - 1.0f);

Should probably also be done in similar sections in average and weighted strategies? e.g.

float fx = fGridSize * (point.x - node->min.x) / boxSize.x;
float fy = fGridSize * (point.y - node->min.y) / boxSize.y;
float fz = fGridSize * (point.z - node->min.z) / boxSize.z;

@m-schuetz
Copy link
Owner Author

There is also a small amount of voxels in the first processed inner node that are overwritten with other data due to mistakenly overlapping buffer allocations.

At the end of the voxelization, the allocator offset should be updated to after the last allocated voxel, like first-come and random sampling already do:

This update of the allocator is missing in the average and weighted average strategies, at this place:

The problem arises because kernel3 directly afterwards allocates some memory to compute stats, but because the allocator wasn't updated, that memory ends up pointing to the voxels of the first processed node:

uint32_t& stat_num_leaves = *allocator.alloc<uint32_t*>(4);
uint32_t& stat_num_inner = *allocator.alloc<uint32_t*>(4);
uint64_t& stat_sum_leaves = *allocator.alloc<uint64_t*>(8);
uint64_t& stat_sum_inner = *allocator.alloc<uint64_t*>(8);
uint64_t& stat_max_leaves = *allocator.alloc<uint64_t*>(8);
uint64_t& stat_max_inner = *allocator.alloc<uint64_t*>(8);
uint64_t& stat_min_leaves = *allocator.alloc<uint64_t*>(8);
uint64_t& stat_min_inner = *allocator.alloc<uint64_t*>(8);
uint64_t* pointsAtLevel = allocator.alloc<uint64_t*>(50 * 8);
uint64_t* voxelsAtLevel = allocator.alloc<uint64_t*>(50 * 8);
uint64_t* innerAtLevel = allocator.alloc<uint64_t*>(50 * 8);
uint64_t* leavesAtLevel = allocator.alloc<uint64_t*>(50 * 8);

And this is what it looks like. Should be about 100-150 voxels that end up garbage due do the amount of mem that computing stats allocates.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant