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

**URL:** https://discourse.itk.org/t/csharp-c-wrappings-for-itk-and-plastimatch/5472
**Category:** Uncategorized
**Created:** [November 8, 2022, 10:38pm UTC](https://discourse.itk.org/t/csharp-c-wrappings-for-itk-and-plastimatch/5472 "2022-11-08T22:38:22Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![G\_Tom](https://discourse.itk.org/user_avatar/discourse.itk.org/g_tom/32/3019_2.png) [@G\_Tom](https://discourse.itk.org/u/G_Tom)
#### Post date: [November 8, 2022, 10:38pm UTC](https://discourse.itk.org/t/csharp-c-wrappings-for-itk-and-plastimatch/5472/1 "2022-11-08T22:38:22Z")

</div>

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](http://plastimatch.org/contents.html)

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

> [//PLMGamma.h](https://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

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [November 9, 2022, 1:41pm UTC](https://discourse.itk.org/t/csharp-c-wrappings-for-itk-and-plastimatch/5472/2 "2022-11-09T13:41:57Z")

</div>

`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](https://www.swig.org/tutorial.html).

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.

---

<div class="post-metadata">

### Author: ![G\_Tom](https://discourse.itk.org/user_avatar/discourse.itk.org/g_tom/32/3019_2.png) [@G\_Tom](https://discourse.itk.org/u/G_Tom)
#### Post date: [December 20, 2022, 10:14pm UTC](https://discourse.itk.org/t/csharp-c-wrappings-for-itk-and-plastimatch/5472/3 "2022-12-20T22:14:01Z")

</div>

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

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [December 20, 2022, 10:47pm UTC](https://discourse.itk.org/t/csharp-c-wrappings-for-itk-and-plastimatch/5472/4 "2022-12-20T22:47:20Z")

</div>

@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).

---

<div class="post-metadata">

### Author: ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)
#### Post date: [July 5, 2023, 8:08pm UTC](https://discourse.itk.org/t/csharp-c-wrappings-for-itk-and-plastimatch/5472/5 "2023-07-05T20:08:24Z")

</div>

@G_Tom a viable approach to C# wrappings for plastimatch may be [itk-wasm](https://wasm.itk.org). Like the binding generation for JavaScript, Python, and Java, C# wrapping binding generation could be added as outlined [in this issue](https://github.com/InsightSoftwareConsortium/itk-wasm/issues/867).

CC @gcsharp

---

<div class="post-metadata">

### Author: ![gcsharp](https://discourse.itk.org/letter_avatar_proxy/v4/letter/g/7bcc69/32.png) [@gcsharp](https://discourse.itk.org/u/gcsharp)
#### Post date: [July 5, 2023, 8:51pm UTC](https://discourse.itk.org/t/csharp-c-wrappings-for-itk-and-plastimatch/5472/6 "2023-07-05T20:51:08Z")

</div>

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.
