Hi,
As I am trying to implement the quadric decimation algorithm and I found the following while manipulating meshes computed with ImageMarchingCubes: sometimes, triangles generated might be empty, this is the consequence of how the parameter t is computed:
In file Filters/General/ImageMarchingCubes/index.js
const t =
(cVal - voxelScalars[edgeVerts[0]]) /
(voxelScalars[edgeVerts[1]] - voxelScalars[edgeVerts[0]]);
If we have voxelScalars[edgeVerts[0]] === cVal, the position of the point along the axis of edgeVerts will be computed at one of the ends. If the same thing happens on the 3 axis, the generated triangle will be have its three points at same coordinates and it will be empty (which can lead to different kinds of problem).
When looking at the code in C++, the condition on cVal threshold seems slightly different:
In file Filters/General/ImageMarchingCubes/index.js
if (voxelScalars[VERT_MAP[idx]] >= cVal) {
index |= CASE_MASK[idx]; // eslint-disable-line no-bitwise
}
In file Filters/General/vtkImageMarchingCubes.cxx
if ((double)(ptr[0]) > value)
{
cubeIndex += 1;
}
Replacing “>= cVal” with “> cVal” corrects the issue as there is no more risk of dealing with empty triangles.
What I can’t understand is that the C++ implementations uses “>=” in Filters/Core/vtkMarchingCubes.cxx but “>” in Filters/General/vtkImageMarchingCubes.cxx
Also, when creating the new polydata and updating the output, I think the following line needs to be added:
In file Filters/General/ImageMarchingCubes/index.js, after
const polydata = vtkPolyData.newInstance();
polydata.getPoints().setData(new Float32Array(pBuffer), 3);
polydata.getPolys().setData(new Uint32Array(tBuffer));
polydata.getPolys().setNumberOfComponents(4);