Smoothing vtkMarchingSquare output

Greetings to all.
I have search around the net and the forum to find a way to smooth the output of vtkMarchingSquares but I am in dead end I think. I have implemented a Dicom Viewer with RTStruct and RTDose support. At the moment I am trying to calculate and display the IsoDose contours. I have used vtkMarchingSquares and I am pretty close to achieve what I was aiming to.

In the above image though it can be seen that the result is kind of a zig zag contour line which was expected to be truth. Though I am not sure how I can smooth the result. I have tried using vtkWindowedSincPolyDataFilter or vtkSmoothPolyDataFilter but doesn’t seem to do the trick. Then I thought to find a way to export the vtkCell points from the resulting contours and do the smoothing using custom made code but again was stuck on the process of extracting the points. Have tried to use vtkStripper and GetLines for that.
I am sure that this is something discussed on the past and that the solution could be simple but I am really sorry cause I am quite new to VTK and not sure if I am having a completely wrong approach to my problem.

Thank you in advance.
Kind regards


1 Like

There might be a bug in the RTSTRUCT importer, as contours should never look like this. You can confirm this by comparing results with what you get with 3D Slicer and SlicerRT extension. Also note that SlicerRT is a VTK-based library that provides all the features that you have already developed (and probably also those features that you plan to develop in the next few years). Instead of redeveloping everything from scratch, I would strongly recommend to make use of SlicerRT. It is free, comes with a completely restriction-free license, it can be used without restrictions for any purpose (e.g., it is used in this commercial treatment planning system), and it is more fun and efficient to collaborate then pursue independent competing efforts - especially if they are both based on VTK.

Thanks Andras,

The displayed contour lines that you see are the result of vtkMarchingSquares on a 2D array that has dose values. So in essence it is kind of IsoDose lines from low Gy values towards the center with maximum Gy. It is not RTStructure contours. Thanks for your suggestion on using slicer but it is essential to implement a standalone windows app that uses VTK. So my problem is that i need to smooth the resulting lines from vtkMarchignSquares
As you can see on the zoomed screenshot above I have illuminated voxels (using vtkPoints and vtkVertexGlyphFilter) and it is visible how marching squares calculates the lines for each voxel. So I need to apply some smoothing on the results to be more eye appealing.

Thanks for your time

I see. These isodose lines still look very odd (I don’t remember ever seeing such noisy isodose surfaces), but it might be due to some unusual dose computation method. Anyway, cross-check with SlicerRT to confirm that it is not a bug in your implementation.

You may also have a look at the isodose surface in 3D to see if that looks reasonable.

I’m not sure if you are supposed to smooth an isodose contour, but if you really want to do it, then vtkWindowedSincPolyDataFilter on the isodose surface should work well. If it does not work then it is most likely some error in how you use the filter (e.g., you try to smooth a 2D contour or smoothing parameters are not set optimally).

That’s great, because 3D Slicer is exactly that - a standalone Windows app that uses VTK. Maybe it is not that widely known, but you can build custom application from Slicer. This is the approach that all the Slicer-based commercial products use. You have full control over all the components that are bundled by default, so you can remove all modules that you don’t need and add any modules/extensions that you need. You can also provide your own branding (icons, style, custom skin, etc.), main window content, etc., so most often users do not even realize that the application is built on 3D Slicer platform.

See a Kitware blog post about Slicer custom applications here:

You can find a few examples of custom applications here:

Hi Andras,

Thanks for all the answers and suggestions. I will have to recheck dose upscaling to be sure that I am doing it right. Then I will recheck vtkWindowedSincPolyDataFilter since I have tried it but couldn’t make it work properly.

Thanks again

Dear Andras,

After our brainstorming I returned and checked the interpolation algorithm and I have fixed the upscaling so now everything is looking great.

What you see above are the IsoDose contours as there are calculated using the vtkMarchingSquares.
The output of vtkMarchingSquares is fed directly to a mapper->actor->renderer sequence.

What is the correct way to get from the vtkMarchingSquares output the vtkPoints that consist an IsoDose contourline?

I have found this old forum thread were it seems to be very similar to what I am trying to do but I didn’t have any success with that pipeline. Do you have any suggestions on what path I should follow?

Kind regards

vtkStripper is not reliable for getting continuous contours. vtkContourTriangulator is great, it is much more robust (not perfect, but for reasonable complex contours it works well), but it is considerably slower.

It is really painful to see that you are spending time with rediscovering and struggling with problems that we have all experienced and (mostly) solved years ago. It would be very useful to know what we would need to do differently to persuade excellent developers like you to join forces to improve and extend existing implementation instead of redoing everything from scratch. All small and simple tools are expected to be web apps nowadays, so desktop software can only survive if it is very powerful, high-quality, scalable, well maintained and supported - which is very hard to achieve if each developer works alone on his own small project.

Dear Andras,

Thanks for your help. You are absolutely right on your last paragraph. I wish things were different for me so I could focus on newer technologies and implementations. Unfortunately that is not possible at the moment. I really wish at the near future to be able to cross to vtk.js and the web world. I don’t believe that you have to do anything differently on how you are operating VTK ,3D Slicer platform and the community. You and your team are doing an excellent work.

My sincere regards and respect.

1 Like

Hi CDevel,
I also encountered this problem. Could tell me how you to sovle? Did you upscale the dose slice , and then extracted the isolines , use some interpolation algorithm to smooth the isolines finally?

Thanks for your time

Hi czjsai,

If I recall correctly I solved the issue by applying a smoothing algorithm on the upscaled Dose grid. vtkMarchingSquares works pretty sweet as long as you feed it with the correct data. So my issue was on the data that I was feeding. By smoothing my upscaled dose grid I managed to get the above result.