# Using SimpleItk in loadable modules

**URL:** https://discourse.slicer.org/t/using-simpleitk-in-loadable-modules/908
**Category:** Development
**Created:** [August 21, 2017, 8:21am UTC](https://discourse.slicer.org/t/using-simpleitk-in-loadable-modules/908 "2017-08-21T08:21:09Z")
**Posts on this page:** 14
**Page:** 1

<div class="post-metadata">

### Author: ![sandra](https://avatars.discourse-cdn.com/v4/letter/s/4491bb/32.png) [@sandra](https://discourse.slicer.org/u/sandra)
#### Post date: [August 21, 2017, 8:21am UTC](https://discourse.slicer.org/t/using-simpleitk-in-loadable-modules/908/1 "2017-08-21T08:21:09Z")

</div>

Hi everyone,

I would like to use SimpleItk while writting a loadable module.  
My problem is about including the necessary files:  
#include \<sitkCenteredTransformInitializerFilter.h\> for example doesn’t work, I get the error “file not found”

I know that Slicer’s architecture is complex and I’m not sure how to include SimpleItk/the necessary files in a loadable module. I tried the different ways I could find in SimpleItk examples (in the official documentation, so not using Slicer) but I didn’t succeed.

(I did build Slicer with SimpleItk).

Thanks for your help,

Sandra.

---

<div class="post-metadata">

### Author: ![Fernando](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fernando/32/5640_2.png) [@Fernando](https://discourse.slicer.org/u/Fernando)
#### Post date: [August 21, 2017, 12:13pm UTC](https://discourse.slicer.org/t/using-simpleitk-in-loadable-modules/908/2 "2017-08-21T12:13:39Z")

</div>

Hi Sandra,

I think SimpleITK has wrappers for Python, C#, Java and R, but for C++ you should use ITK directly.

---

<div class="post-metadata">

### Author: ![sandra](https://avatars.discourse-cdn.com/v4/letter/s/4491bb/32.png) [@sandra](https://discourse.slicer.org/u/sandra)
#### Post date: [August 21, 2017, 12:35pm UTC](https://discourse.slicer.org/t/using-simpleitk-in-loadable-modules/908/3 "2017-08-21T12:35:58Z")

</div>

You mean that in general it isn’t possible to use simpleItk with C++ or it isn’t possible in Slicer particularly ?

---

<div class="post-metadata">

### Author: ![Fernando](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fernando/32/5640_2.png) [@Fernando](https://discourse.slicer.org/u/Fernando)
#### Post date: [August 21, 2017, 12:59pm UTC](https://discourse.slicer.org/t/using-simpleitk-in-loadable-modules/908/4 "2017-08-21T12:59:39Z")

</div>

In general:

> **[SimpleITK/SimpleITK](https://github.com/SimpleITK/SimpleITK#simpleitk)**
>
> SimpleITK: a layer built on top of the Insight Toolkit (ITK), intended to simplify and facilitate ITK's use in rapid prototyping, education and interpreted languages. - SimpleITK/SimpleITK

---

<div class="post-metadata">

### Author: ![sandra](https://avatars.discourse-cdn.com/v4/letter/s/4491bb/32.png) [@sandra](https://discourse.slicer.org/u/sandra)
#### Post date: [August 21, 2017, 1:02pm UTC](https://discourse.slicer.org/t/using-simpleitk-in-loadable-modules/908/5 "2017-08-21T13:02:39Z")

</div>

I saw this page where there are examples of simpleItk used in C++

[https://itk.org/SimpleITKDoxygen/html/examples.html](https://itk.org/SimpleITKDoxygen/html/examples.html)

---

<div class="post-metadata">

### Author: ![Fernando](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fernando/32/5640_2.png) [@Fernando](https://discourse.slicer.org/u/Fernando)
#### Post date: [August 21, 2017, 1:13pm UTC](https://discourse.slicer.org/t/using-simpleitk-in-loadable-modules/908/6 "2017-08-21T13:13:35Z")

</div>

> [@sandra](#):
>
> I saw this page where there are examples of simpleItk used in C++

I didn’t know about those, sorry.

---

<div class="post-metadata">

### Author: ![fedorov](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/fedorov/32/14_2.png) [@fedorov](https://discourse.slicer.org/u/fedorov)
#### Post date: [August 21, 2017, 8:03pm UTC](https://discourse.slicer.org/t/using-simpleitk-in-loadable-modules/908/7 "2017-08-21T20:03:49Z")

</div>

In general, it is indeed possible to use SimpleITK from C++, but I don’t know of any examples in Slicer. @blowekamp would know for sure!

---

<div class="post-metadata">

### Author: ![jcfr](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jcfr/32/17825_2.png) [@jcfr](https://discourse.slicer.org/u/jcfr)
#### Post date: [August 21, 2017, 8:27pm UTC](https://discourse.slicer.org/t/using-simpleitk-in-loadable-modules/908/8 "2017-08-21T20:27:00Z")

</div>

While possible, the build system currently do not enable this.

In a nutshell, the SimpleITK targets (available through `SimpleITKConfig.cmake`) are not exposed to extensions. Only ITK is.

To keep things simple, I suggest we stick to ITK when dealing with C++ and image processing.

---

<div class="post-metadata">

### Author: ![blowekamp](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/blowekamp/32/1386_2.png) [@blowekamp](https://discourse.slicer.org/u/blowekamp)
#### Post date: [August 22, 2017, 1:25am UTC](https://discourse.slicer.org/t/using-simpleitk-in-loadable-modules/908/9 "2017-08-22T01:25:29Z")

</div>

I have a module, which is still compiling, that uses SimpleITK in this way. The NucleusClosing module uses the c++ interface for SimpleITK. It still seems to work.

> **[blowekamp/Slicer-IASEM](https://github.com/blowekamp/Slicer-IASEM?files=1)**
>
> Slicer3D IASEM Microscopy Extension. Contribute to blowekamp/Slicer-IASEM development by creating an account on GitHub.

HTH  
Brad

---

<div class="post-metadata">

### Author: ![jcfr](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jcfr/32/17825_2.png) [@jcfr](https://discourse.slicer.org/u/jcfr)
#### Post date: [August 22, 2017, 3:59am UTC](https://discourse.slicer.org/t/using-simpleitk-in-loadable-modules/908/10 "2017-08-22T03:59:09Z")

</div>

Indeed 😄 , we are marking `SimpleITK` as `FIND_PACKAGE` … and the targets end up being exposed.

> <https://github.com/Slicer/Slicer/blob/ead66c24da4cc499981b09e05ea79c82815ce2db/SuperBuild/External_SimpleITK.cmake#L127-L130>

---

<div class="post-metadata">

### Author: ![sandra](https://avatars.discourse-cdn.com/v4/letter/s/4491bb/32.png) [@sandra](https://discourse.slicer.org/u/sandra)
#### Post date: [August 22, 2017, 8:16am UTC](https://discourse.slicer.org/t/using-simpleitk-in-loadable-modules/908/11 "2017-08-22T08:16:08Z")

</div>

So @blowekamp what did you do to have simpleItk working in your loadable module ?

@jcfr : do I have to write these 4 lines somewhere or are they already present in the slicer’s architecture ?

---

<div class="post-metadata">

### Author: ![jcfr](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jcfr/32/17825_2.png) [@jcfr](https://discourse.slicer.org/u/jcfr)
#### Post date: [August 22, 2017, 1:08pm UTC](https://discourse.slicer.org/t/using-simpleitk-in-loadable-modules/908/12 "2017-08-22T13:08:19Z")

</div>

Hi @sandra,

You only need to “link” against the `SimpleITK` targets as it is done here:

> <https://github.com/blowekamp/Slicer-IASEM/blob/f3895471dd01d0340cbed5178dfe7ac27b745090/NucleusClosing/CMakeLists.txt#L31-L33>

In the case of loadable modules, you would add `${SimpleITK_LIBRARIES}` to the `TARGET_LIBRARIES` parameter of the logic:

> <https://github.com/Slicer/Slicer/blob/ead66c24da4cc499981b09e05ea79c82815ce2db/Utilities/Templates/Modules/Loadable/Logic/CMakeLists.txt#L20-L26>

---

<div class="post-metadata">

### Author: ![blowekamp](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/blowekamp/32/1386_2.png) [@blowekamp](https://discourse.slicer.org/u/blowekamp)
#### Post date: [August 22, 2017, 1:19pm UTC](https://discourse.slicer.org/t/using-simpleitk-in-loadable-modules/908/13 "2017-08-22T13:19:06Z")

</div>

The first step is to find the SimpleITK package in CMake:

> <https://github.com/blowekamp/Slicer-IASEM/blob/f3895471dd01d0340cbed5178dfe7ac27b745090/CMakeLists.txt#L45-L52>

Then as JC said you need to link against the SimpleITK libraries.

---

<div class="post-metadata">

### Author: ![sandra](https://avatars.discourse-cdn.com/v4/letter/s/4491bb/32.png) [@sandra](https://discourse.slicer.org/u/sandra)
#### Post date: [August 22, 2017, 1:20pm UTC](https://discourse.slicer.org/t/using-simpleitk-in-loadable-modules/908/14 "2017-08-22T13:20:42Z")

</div>

Ok and those lines about find the SimpleITK package, where should I write them (for a loadable module) ? (In which CMakeLists.txt)
