# How to read linear transform from C++ CLI

**URL:** <https://discourse.slicer.org/t/how-to-read-linear-transform-from-c-cli/1994>\
**Category:** Development\
**Created:** [January 31, 2018, 10:03pm UTC](https://discourse.slicer.org/t/how-to-read-linear-transform-from-c-cli/1994 "2018-01-31T22:03:37Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![dzenanz](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/dzenanz/32/1992_2.png) [@dzenanz](https://discourse.slicer.org/u/dzenanz)\
**Post date:** [January 31, 2018, 10:03pm UTC](https://discourse.slicer.org/t/how-to-read-linear-transform-from-c-cli/1994/1 "2018-01-31T22:03:37Z")

</div>

Slicer used to write `.h5` or `.tfm` files when a transform needed to be passed to a CLI:

```
<transform type="linear" fileExtensions=".tfm,.h5,.hdf5,.mat,.txt">
  <longflag>transform0</longflag>
  <description>...</description>
  <label>rigid transform 0</label>
  <channel>input</channel>
</transform>

```

but now a CLI gets `--transform0 C:/Temp/Slicer/BDBAI_AAAAAAAABFECHIFA.mrml#vtkMRMLLinearTransformNode1` which **itk::TransformFileReader** cannot read. How to force Slicer to write an ITK-readable transform?

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [January 31, 2018, 10:50pm UTC](https://discourse.slicer.org/t/how-to-read-linear-transform-from-c-cli/1994/2 "2018-01-31T22:50:51Z")

</div>

Which Slicer version does this? Many CLI modules uses transforms with ITK readers - do they work correctly?

---

<div class="post-metadata">

**Author:** ![dzenanz](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/dzenanz/32/1992_2.png) [@dzenanz](https://discourse.slicer.org/u/dzenanz)\
**Post date:** [January 31, 2018, 10:52pm UTC](https://discourse.slicer.org/t/how-to-read-linear-transform-from-c-cli/1994/3 "2018-01-31T22:52:36Z")

</div>

1aa2f026195e7f8206748867cca4a6fc46197f7c from 2018-01-27

---

<div class="post-metadata">

**Author:** ![ihnorton](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/ihnorton/32/9_2.png) [@ihnorton](https://discourse.slicer.org/u/ihnorton)\
**Post date:** [February 1, 2018, 2:01am UTC](https://discourse.slicer.org/t/how-to-read-linear-transform-from-c-cli/1994/4 "2018-02-01T02:01:13Z")

</div>

> [@dzenanz](#):
>
> How to force Slicer to write an ITK-readable transform?

Are you using the “force executable” setting in Settings-\>Modules?

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [February 1, 2018, 3:56am UTC](https://discourse.slicer.org/t/how-to-read-linear-transform-from-c-cli/1994/5 "2018-02-01T03:56:23Z")

</div>

@dzenanz Many CLI modules uses transforms with ITK readers - do they work correctly?

For example, “Resample Scalar/Vector/DWI volume” module works correctly for me, writing the transform to .h5 file.

> **Full command line**
>
> Resample Scalar/Vector/DWI Volume command line:
> 
> C:/D/S4R/Slicer-build/lib/Slicer-4.9/cli-modules/Release/ResampleScalarVectorDWIVolume.exe --Reference C:/Users/msliv/AppData/Local/Temp/Slicer/CCCEE\_vtkMRMLScalarVolumeNodeB.nrrd --transformationFile C:/Users/msliv/AppData/Local/Temp/Slicer/CCCEE\_vtkMRMLLinearTransformNodeE.h5 --hfieldtype h-Field --interpolation linear --transform\_order output-to-input --image\_center input --spacing 0,0,0 --size 0,0,0 --direction\_matrix 0,0,0,0,0,0,0,0,0 --number\_of\_thread 0 --default\_pixel\_value 0 --window\_function c --spline\_order 3 --transform\_matrix 1,0,0,0,1,0,0,0,1,0,0,0 --transform a C:/Users/msliv/AppData/Local/Temp/Slicer/CCCEE\_vtkMRMLScalarVolumeNodeB.nrrd C:/Users/msliv/AppData/Local/Temp/Slicer/CCCEE\_vtkMRMLScalarVolumeNodeD.nrrd

It uses this XML:

```
<transform fileExtensions=".h5">
  <name>transformationFile</name>
  <label>Transform Node</label>
  <flag>-f</flag>
  <longflag>--transformationFile</longflag>
  <default/>
  <channel>input</channel>
</transform>

```

You can add the few missing tags to your XML file (name, default, flag) and see if it makes a difference.

---

<div class="post-metadata">

**Author:** ![dzenanz](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/dzenanz/32/1992_2.png) [@dzenanz](https://discourse.slicer.org/u/dzenanz)\
**Post date:** [February 1, 2018, 4:17pm UTC](https://discourse.slicer.org/t/how-to-read-linear-transform-from-c-cli/1994/6 "2018-02-01T16:17:17Z")

</div>

After changing the `fileExtensions=".tfm,.h5,.hdf5,.mat,.txt"` into `fileExtensions=".tfm"` and recompiling the problem went away. Then I changed back into the original, and the transforms are still being written normally (as `.tfm` files). Perhaps changes to CMake code made the difference. I explicitly added this (trying to fix an unrelated linking error with tests):

```
find_package(SlicerExecutionModel REQUIRED)
include(${SlicerExecutionModel_USE_FILE})

set(MABMIS_ITK_COMPONENTS
  ITKIOImageBase
  ITKTransform
  ITKIOTransformBase
  ITKIOXML
  )
find_package(ITK 4.6 COMPONENTS ${MABMIS_ITK_COMPONENTS} REQUIRED)
set(ITK_NO_IO_FACTORY_REGISTER_MANAGER 1) # See Libs/ITKFactoryRegistration/CMakeLists.txt
include(${ITK_USE_FILE})

find_package(Slicer)
include(${Slicer_USE_FILE})

```

But why would any of this make a difference?

@ihnorton Disabling “Prefer executable CLIs” passes the images via pointer, but does not seem to affect transforms.

---

<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:** [February 2, 2018, 1:00pm UTC](https://discourse.slicer.org/t/how-to-read-linear-transform-from-c-cli/1994/7 "2018-02-02T13:00:44Z")

</div>

Are you running CLI a executable or shared library?

---

<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:** [February 2, 2018, 1:04pm UTC](https://discourse.slicer.org/t/how-to-read-linear-transform-from-c-cli/1994/8 "2018-02-02T13:04:43Z")

</div>

Sorry for the noise, I was on the phone and didn’t see the full thread.

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [February 2, 2018, 1:57pm UTC](https://discourse.slicer.org/t/how-to-read-linear-transform-from-c-cli/1994/9 "2018-02-02T13:57:41Z")

</div>

I think you need to force recompilation after you change the module description XML. I noticed in the past that XML file changes did not take effect with a simple build.
