Difference between vtkContourFilter, vtkMarchingSquares and vtkMarchingContourFilter

Hi;

What is the difference between the three filters: vtkContourFilter, vtkMarchingSquares and vtkMarchingContourFilter. In the documentation, the definition is very similar but what is the difference in terms of precision. In fact I want to extract contour from a 2D binary image? what is the best filter to employ in this case.

Thank’s in advance

Typically vtkContourFilter will delegate to another contouring class for the actual algorithm. If you look at the source code, you will see that vtkContourFilter delegates to vtkSynchronizedTemplates2D for 2D images.

Since VTK is an evolving toolkit, as new algorithms are developed, new implementations periodically appear. For example, you mentioned two: vtkMarchingSquares and vtkImageMarchingSquares. These differ in performance mostly, vtkMarchingSquares uses a higher-level (i.e., slow API), while vtkImageMarchingSquares uses templated pointer access to the data.

vtkSynchronizedTemplates2D came along later and is faster than these two algorithms because it reduces the number of intersection calculations, as well as the frequency that data is reloaded.

Finally, vtkFlyingEdges2D should also be mentioned. It is probably the fastest algorithm in most cases: it uses more efficient data access, plus it is threaded (if built correctly with TBB etc).

In 2D, most of these algorithms will probably work reasonably well unless you have a ginormous 2D image. In 3D, vtkFlyingEdges3D is by far and away the fastest, single-pass contouring algorithm.

2 Likes