vtkVoxelContoursToSurfaceFilter is generating meshes with holes in them
This issue was created automatically from an original Mantis Issue. Further discussion may take place here.
I am generating a mesh out of a series of parallel contours through the use of the vtkVoxelContoursToSurfaceFilter filter, but the resulting surface has holes in it sometimes. The attached image demonstrates the problem, it is a hollow box with an open top, but you can see the surface is missing from the top edges of the box, despite the fact that the contours are there.
The holes occur only where the surface is parallel to the xz or yz plane. It occurs only at the maximum extent of the surface.
I've done some investigating and I believe I know the exact problem and how to solve it... But I am not a VTK developer.
At the beginning of vtkVoxelContoursToSurfaceFilter::RequestData(), gridOrigin and gridSize are calculated. In the calculations for gridSize[0] and gridSize[1], it seems the intent is for there to be one buffer pixel before the actual data origin, and one buffer pixel after the actual data extent. This is not always the case though:
If the decimal part of (contourBounds[1] - contourBounds[0]) is greater than 0.5, then gridSize[0] will not be large enough because the integer cast floors the result.
Suppose contourBounds[0] = 0 and contourBounds[1] = 40.8, then we will have gridOrigin[0] = -0.5 and gridSize[0] = (int)(40.8 - 0 + 2) = (int)(42.8) = 42. Now, if there are 42 pixels along the x axis, and the first one is the origin, -0.5, then the last one will be -0.5 + 41 = 40.5, which is less than 40.8, the true maximum.
The solution here, I believe, would be to change
gridSize[0] = (int) (contourBounds[1] - contourBounds[0] + 2); gridSize[1] = (int) (contourBounds[3] - contourBounds[2] + 2);
to
gridSize[0] = (int) (contourBounds[1] - contourBounds[0] + 2.5); gridSize[1] = (int) (contourBounds[3] - contourBounds[2] + 2.5);
This is my first bug report, let me know if I can be of more assistance.