# Using Reformat module from Python

**URL:** <https://discourse.slicer.org/t/using-reformat-module-from-python/2933>\
**Category:** Development\
**Tags:** reformat\
**Created:** [May 25, 2018, 9:07pm UTC](https://discourse.slicer.org/t/using-reformat-module-from-python/2933 "2018-05-25T21:07:47Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![mschumaker](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mschumaker/32/1395_2.png) [@mschumaker](https://discourse.slicer.org/u/mschumaker)\
**Post date:** [May 25, 2018, 9:07pm UTC](https://discourse.slicer.org/t/using-reformat-module-from-python/2933/1 "2018-05-25T21:07:48Z")

</div>

I’m trying to use the Reformat module from a Python scripted module. I’m having trouble using the setSliceNormal and setWorldPosition methods. Looking at qSlicerReformatModuleWidget, both setSliceNormal and setWorldPosition have slots that take double\*, and setSliceNormal has a public method that takes three arguments: setSliceNormal (double x, double y, double z). I tried to use it both ways, but I keep getting ValueError. Sample code:

```
reformatWidget = slicer.modules.reformat.widgetRepresentation()
slice = slicer.app.layoutManager().sliceWidget('Red')
sliceNode = slice.mrmlSliceNode()
reformatWidget.setEditedNode(sliceNode,"","")
reformatWidget.setSliceNormal(1.0,0,0)

```

The result is: “ValueError: Called setSliceNormal(double normal) -\> void with wrong number of arguments: (1.0, 0.0, 0.0)”.  
I also tried a list, tuple, and a ctypes double array.  
Is there a way I can accomplish this with the Reformat module? Is there Python compatibility code that’s missing from this module?

Thanks

---

<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:** [May 25, 2018, 9:27pm UTC](https://discourse.slicer.org/t/using-reformat-module-from-python/2933/2 "2018-05-25T21:27:05Z")

</div>

Is there a reason why you not simply modify the slice node?

---

<div class="post-metadata">

**Author:** ![mschumaker](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mschumaker/32/1395_2.png) [@mschumaker](https://discourse.slicer.org/u/mschumaker)\
**Post date:** [May 25, 2018, 9:51pm UTC](https://discourse.slicer.org/t/using-reformat-module-from-python/2933/3 "2018-05-25T21:51:08Z")

</div>

I used (1,0,0) in the example, but I would like to be able to set a normal vector that’s off of the principal axes. Also a centre point of the rotation that’s not the centre of the image. I didn’t see a straightforward way to do that from vtkMRMLSliceNode.

---

<div class="post-metadata">

**Author:** ![mschumaker](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mschumaker/32/1395_2.png) [@mschumaker](https://discourse.slicer.org/u/mschumaker)\
**Post date:** [May 25, 2018, 10:09pm UTC](https://discourse.slicer.org/t/using-reformat-module-from-python/2933/4 "2018-05-25T22:09:57Z")

</div>

In Github, I received a suggestion from @jcfr for how to improve the Python compatibility of the Reformat module by adding:

```
Q_PROPERTY(QVector3D worldPosition READ worldPosition WRITE setWorldPosition)

[...]

QVector3D worldPosition() const;
void setWorldPosition(const QVector3D& position); 

```

I’m not sure how the Q\_PROPERTY macro works, but I’m willing to give this a try.

---

<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:** [May 25, 2018, 10:42pm UTC](https://discourse.slicer.org/t/using-reformat-module-from-python/2933/5 "2018-05-25T22:42:12Z")

</div>

Slice position and orientation are specified by SliceToRAS matrix. You can get it using GetSliceToRAS method and update it. You can also use SetSliceToRASByNTP to set slice orientation by slice normal and X axis and position.

---

<div class="post-metadata">

**Author:** ![mschumaker](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mschumaker/32/1395_2.png) [@mschumaker](https://discourse.slicer.org/u/mschumaker)\
**Post date:** [May 28, 2018, 2:26pm UTC](https://discourse.slicer.org/t/using-reformat-module-from-python/2933/6 "2018-05-28T14:26:35Z")

</div>

Thank you, that’s exactly the method I was hoping to find. I missed it when I was looking at the API docs. Looking at the documentation for it, and at the code, I’m still unclear what the final parameter, “Orientation”, should be set to. In the switch statement in the code, it refers to the cases 0,1,2 as para-Axial, para-Sagittal, and para-Coronal, respectively. Does that mean that if the view I want is close to axial, I should set Orientation to 0?

---

<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:** [May 28, 2018, 2:51pm UTC](https://discourse.slicer.org/t/using-reformat-module-from-python/2933/7 "2018-05-28T14:51:01Z")

</div>

SetSliceToRASByNTP’s orientation parameter can be used to generate orthogonal views corresponding to an axial view. It just saves you from figuring out how to change the normal vector for orthogonal views.

---

<div class="post-metadata">

**Author:** ![mschumaker](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mschumaker/32/1395_2.png) [@mschumaker](https://discourse.slicer.org/u/mschumaker)\
**Post date:** [May 28, 2018, 2:59pm UTC](https://discourse.slicer.org/t/using-reformat-module-from-python/2933/8 "2018-05-28T14:59:20Z")

</div>

Ok. My concern is that I don’t see a way that it will set the elements of the SliceToRAS matrix if I don’t supply an Orientation value of 0, 1, or 2. I couldn’t tell if that meant I was limited to the standard orthogonal views.

---

<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:** [May 28, 2018, 3:00pm UTC](https://discourse.slicer.org/t/using-reformat-module-from-python/2933/9 "2018-05-28T15:00:39Z")

</div>

N specifies the slice normal direction if you set orientation to Axial.

---

<div class="post-metadata">

**Author:** ![mschumaker](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/mschumaker/32/1395_2.png) [@mschumaker](https://discourse.slicer.org/u/mschumaker)\
**Post date:** [May 28, 2018, 4:19pm UTC](https://discourse.slicer.org/t/using-reformat-module-from-python/2933/10 "2018-05-28T16:19:08Z")

</div>

Ok, thanks. I wanted to make sure I was interpreting it correctly.
