Hi guys,
I played a bit with MeshToVolume.h to try to compute the sign/side of a portion of a closed polygonal mesh.
As example I have an intersection between a cube and a sphere and I want to calculate the sign/side only of the cube on one node.
These are the steps I'm doing at the moment
- I compute a coarse (say 2*desired_VoxelSize) SDF of the whole geometry and a UDF of the cube.
- topologyIntersection of the coarse SDF and cube UDF. Set clipped SDF grid to GRID_UNKNOWN
- resampleToMatch to desired_voxelSize.
- Use this grid as a maskGrid for a modified version of meshToVolume
Now inside MeshToVolume this is what I've modified:
- voxelization: feed the whole geometry but voxelize only around cube (use resampled SDF as mask)
- use resampled SDF mask to flip the sign of non intersecting voxels
- the original ComputeIntersectingVoxelSign can now flip sign of negative intersecting voxels correctly.
- transform values has only to scale values, sign is already correct
- return the distGrid here because the expandNarrowband would not work on this broken level-set
This approach seems to work as expected on this small case: I know which voxel is inside and which is outside and the accuracy is better than the resampleToMatch.
However I would appreciate your feedback as probably you are more aware where things can be improved or can go wrong. I'm happy to share the code if you think it might be of interest to other people.