Csharp [c#] wrappings for ITK (and Plastimatch)

Hi , I want to use itk from C# application. So far, I know simple itk works with c# but I am interested in using the plastimatch library which is simply heavily built on ITK.
Plastimatch documentation — Plastimatch 1.9.4 documentation

So far, I have made a c++ DLL (PLMGamma) linked to both ITK and plastimatch.

//PLMGamma.h
#pragma once
#include <itkImage.h>
#include “gamma_dose_comparison.h”

#ifdef PLMGAMMADLL_EXPORTS
#define PLMGAMMA_API __declspec(dllexport)
#else
#define PLMGAMMA_API __declspec(dllimport)
#endif
class PLMGAMMA_API PLMGamma
{
public:
void Compare(FloatImageType::Pointer float_image1, FloatImageType::Pointer float_image2);

};

Where FloatImageType defined in \include\plastimatch\itk_image_type.h as:

typedef itk::Image < float, 3 > FloatImageType;

My Question, is how do I wrap this PLMGamma class for use in c# ? I am ok to dabble with Swig or manually writing c++ wrapper functions but I need some help please.

Thanks

GT

FloatImageType::Pointer is an alias for itk::SmartPointer<FloatImageType>. Smart pointers are problematic for wrapping, that’s why we avoid them in public interfaces in ITK. Passing images via plain pointers (FloatImageType *) should be quite easy to wrap with SWIG.

Do note that ITK currently only properly wraps for Python. C# wrappings were broken for years, before being removed recently (this year or the last). So you would need to wrap all the things you want exposed in C#, including any ITK class found in your public interface.

Hi Dzenan,

thanks for your reply. I was wondering if you can show how to wrap (FloatImageType *) as you suggest. The only public interface requirement I have is that itk::Image < float, 3 > FloatImageType be available in the dot net side.
i.e, I want to be able to create a new FloatImageType object in c# .

Thank you .

GT

@matt.mccormick and @blowekamp might be able to help with that.

I don’t know whether there would be anything more to it than following SWIG documentation for wrapping a custom class. You would probably also have to wrap its parent classes (ImageBase, LightObject etc).

@G_Tom a viable approach to C# wrappings for plastimatch may be itk-wasm. Like the binding generation for JavaScript, Python, and Java, C# wrapping binding generation could be added as outlined in this issue.

CC @gcsharp

Wow, that’s pretty wild. I’ll look into it.

I did have success getting a basic C# wrapper working with SWIG, but the work is pretty time consuming and I never finished.

1 Like