vtkImageMarchingSquares ambiguous cases

I am attempting to use the vtkImageMarchingSquares class to generate isodose lines for some dose data. This is working great, until the marching squares gets to certain slices. I am using K-slicing, which is the only direction the marching squares implementation currently supports.

(The isodose lines don’t show up in the screenshot above as the error happens pretty quickly, almost before the first render of the lines.)

After doing some debugging on my own, it appears that when the marching squares tries the ambiguous cases (case 5 and case 10), the algorithm will error out because it fails to get the edge.

(Debugging in ImageMarchingSquares.js)

(This is where the error happens, when looking into the edgeVerts variable. Could even fail earlier if mergePoints is true.)

Is this an issue with the implementation of the marching squares algorithm in vtk.js, or is it possible I am doing something wrong? It doesn’t appear that the algorithm tries to distinguish between the ambiguous cases (select the right edge?).

For reference, here is the data used in the scene (from SlicerRT Data):

If it would help, I can create a reproduction using stackblitz, or something similar, but figured I would just start with laying things out first.


Have you checked to see what happens in VTK? It might be a bug in the vtk.js implementation.

No I have not yet. Unfortunately, I don’t have much experience using VTK outside of vtk.js. I could definitely give it a try though.

Would ActiViz be a good way to test this, using a memory safe language (C#)?

Activiz should suffice, as all we are doing is evaluating if VTK’s filter exhibits the same behavior.

Any chance that fix(imagemarchingcubes): fix vtkImageMarchingCubes filter multiple re… by finetjul · Pull Request #2754 · Kitware/vtk-js · GitHub fixed your isue ?