# How to rotate OrthogonalSlicesDeg in slices?

**URL:** <https://discourse.slicer.org/t/how-to-rotate-orthogonalslicesdeg-in-slices/20892>\
**Category:** Development\
**Tags:** python\
**Created:** [December 2, 2021, 11:27pm UTC](https://discourse.slicer.org/t/how-to-rotate-orthogonalslicesdeg-in-slices/20892 "2021-12-02T23:27:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jumbojing](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jumbojing/32/10811_2.png) [@jumbojing](https://discourse.slicer.org/u/jumbojing)\
**Post date:** [December 2, 2021, 11:27pm UTC](https://discourse.slicer.org/t/how-to-rotate-orthogonalslicesdeg-in-slices/20892/1 "2021-12-02T23:27:22Z")

</div>

在插件中,我用Ctrl + Alt + Left-click-and-drag在不同的Slice里找到了一个合适vector, 我想移动这个vector, 想了很多方法都不理想, 其中包括:[rotateOrthogonalSlicesDeg](https://github.com/SlicerHeart/SlicerHeart/blob/5be64b4b68fcbfbdc7ed463913f52a74208b6d07/ValveView/ValveView.py#L275-L303), 可是这个方法,只能在一个Slice里面旋转,当我改变Slice后,原来那个slice的角度就归零了…谁有好的方法帮我?

> In my plug-in, I used Ctrl + Alt + Left-click-and-drag to find a suitable vector(include position and angle) from different slices. I wanted to move this vector’s position and keep its angle, I had try to some methods, but not ideal, for example: [rotateOrthogonalSlicesDeg](https://github.com/SlicerHeart/SlicerHeart/blob/5be64b4b68fcbfbdc7ed463913f52a74208b6d07/ValveView/ValveView.py#L275-L303), but this method can only be rotated in a slice, when I change the angle in another slice, the angle of the previous slice reset…Who has a good way to help me?

---

<div class="post-metadata">

**Author:** ![jumbojing](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jumbojing/32/10811_2.png) [@jumbojing](https://discourse.slicer.org/u/jumbojing)\
**Post date:** [December 2, 2021, 11:32pm UTC](https://discourse.slicer.org/t/how-to-rotate-orthogonalslicesdeg-in-slices/20892/2 "2021-12-02T23:32:07Z")

</div>

@lassoan@Juicy@jamesobutler @jcfr @pieper

我的具体思路是: 通过Ctrl + Alt + Left-click-and-drag的方法, 找到一个矢量, 返回并保存这个矢量的位置和在三个slice(RAS) 角度, 利用[rotateOrthogonalSlicesDeg](https://github.com/SlicerHeart/SlicerHeart/blob/5be64b4b68fcbfbdc7ed463913f52a74208b6d07/ValveView/ValveView.py#L275-L303) 找回这个视图,

> My specific idea is: Find a vector by Ctrl + Alt + Left-click-and-drag from slices, return and save the position of this vector and the angle of the three slices (RAS), use the [rotateOrthogonalSlicesDeg](https://github.com/SlicerHeart/SlicerHeart/blob/5be64b4b68fcbfbdc7ed463913f52a74208b6d07/ValveView/ValveView.py#L275-L303) to retrieve this vector views (sense) or move this vector’s position and succeed its angle…

---

<div class="post-metadata">

**Author:** ![jumbojing](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jumbojing/32/10811_2.png) [@jumbojing](https://discourse.slicer.org/u/jumbojing)\
**Post date:** [December 3, 2021, 11:07pm UTC](https://discourse.slicer.org/t/how-to-rotate-orthogonalslicesdeg-in-slices/20892/3 "2021-12-03T23:07:50Z")

</div>

好吧…我自己解决了这个问题…贡献我的代码:  
From:[setSlicePositionAndOrientation](https://github.com/SlicerHeart/SlicerHeart/blob/76572a78835e657e01d576af0f82d5729867b6b7/ValveAnnulusAnalysis/HeartValveLib/ValveModel.py#L967-L1021)

```auto
  def orthoReset(PIP,nor,ax):

    RNode = slicer.mrmlScene.GetNodeByID("vtkMRMLSliceNodeRed")
    YNode = slicer.mrmlScene.GetNodeByID("vtkMRMLSliceNodeYellow")
    GNode = slicer.mrmlScene.GetNodeByID("vtkMRMLSliceNodeGreen")
    # Rslice
    RNode.SetSliceToRASByNTP(-nor[0][0],-nor[0][1],-nor[0][2], 
                             -ax[0][0],-ax[0][1],-ax[0][2], 
                             PIP[0], PIP[1], PIP[2], 0)

    YNode.SetSliceToRASByNTP(-nor[2][0],-nor[2][1],-nor[2][2], 
                             -ax[2][0],-ax[2][1],-ax[2][2], 
                             PIP[0], PIP[1], PIP[2], 0)

    GNode.SetSliceToRASByNTP(-nor[1][0],-nor[1][1],-nor[1][2], 
                             -ax[1][0],-ax[1][1],-ax[1][2], 
                             PIP[0], PIP[1], PIP[2], 0)
    return True

```

其中, ax和nor通过`GetSliceToRAS`获取,其中ax为第一列, nor为第三列,比如:

```auto
    axialSliceToRas = axialNode.GetSliceToRAS()
    axR = [
        axialSliceToRas.GetElement(0, 0),
        axialSliceToRas.GetElement(1, 0),
        axialSliceToRas.GetElement(2, 0),
    ]
    norR = [
        axialSliceToRas.GetElement(0, 2),
        axialSliceToRas.GetElement(1, 2),
        axialSliceToRas.GetElement(2, 2),
    ]
    x1 = [
        axialSliceToRas.GetElement(0, 3),
        axialSliceToRas.GetElement(1, 3),
        axialSliceToRas.GetElement(2, 3),
    ]

```

From:[getPlaneIntersectionPoint](https://github.com/SlicerHeart/SlicerHeart/blob/5be64b4b68fcbfbdc7ed463913f52a74208b6d07/ValveView/ValveView.py#L213-L273)
