# 2D views and 3D model transformation

**URL:** <https://discourse.slicer.org/t/2d-views-and-3d-model-transformation/2920>\
**Category:** Support\
**Created:** [May 24, 2018, 5:04pm UTC](https://discourse.slicer.org/t/2d-views-and-3d-model-transformation/2920 "2018-05-24T17:04:53Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dedy\_Ariansyah](https://avatars.discourse-cdn.com/v4/letter/d/ac8455/32.png) [@Dedy\_Ariansyah](https://discourse.slicer.org/u/Dedy_Ariansyah)\
**Post date:** [May 24, 2018, 5:04pm UTC](https://discourse.slicer.org/t/2d-views-and-3d-model-transformation/2920/1 "2018-05-24T17:04:53Z")

</div>

Hello,

In Slicer, it is possible to display a 3D model aligned with 2D slices view in sagittal, coronal, and axial view.

 ![Untitled](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/3/c/3cebade031b2e93259caa21765117267e7fb242b.png)

I am trying to achieve the same visualization in the external software by exporting the model and 2d views generated by Slicer.

Is it possible to obtain the original pose of 3D model w.r.t sagital, coronal, and axial plane?

Many thanks

---

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [May 24, 2018, 5:40pm UTC](https://discourse.slicer.org/t/2d-views-and-3d-model-transformation/2920/2 "2018-05-24T17:40:00Z")

</div>

Yes, you can select the view using the popup controller. Also you can switch to parallel projection mode if needed:

[https://www.slicer.org/wiki/Documentation/4.8/SlicerApplication/MainApplicationGUI#3D\_Viewer](https://www.slicer.org/wiki/Documentation/4.8/SlicerApplication/MainApplicationGUI#3D_Viewer)

---

<div class="post-metadata">

**Author:** ![Dedy\_Ariansyah](https://avatars.discourse-cdn.com/v4/letter/d/ac8455/32.png) [@Dedy\_Ariansyah](https://discourse.slicer.org/u/Dedy_Ariansyah)\
**Post date:** [May 25, 2018, 8:05am UTC](https://discourse.slicer.org/t/2d-views-and-3d-model-transformation/2920/3 "2018-05-25T08:05:36Z")

</div>

Thanks Pieper for the reference. I have taken a look on it. But, i did not manage to find any function that allow me to access the information of relative transformation between planes (Axial, Sagittal, Coronal) and 3D model.

I wonder if you could give more hint on how to access numerical value of the transformation matrix (either manually or programmatically)?

Many 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, 12:42pm UTC](https://discourse.slicer.org/t/2d-views-and-3d-model-transformation/2920/4 "2018-05-25T12:42:15Z")

</div>

Transformation matrix can be accessed using GetSliceToRAS method of the slice node.

```
sliceViewName = slicer.app.layoutManager().sliceViewNames()[0]
sliceToRAS = slicer.app.layoutManager().sliceWidget(sliceViewName).sliceLogic().GetSliceNode().GetSliceToRAS()
print(sliceToRAS)

```

You can also [change the default slice orientations](https://www.slicer.org/wiki/Documentation/Nightly/ScriptRepository#Change_default_slice_view_orientation).

---

<div class="post-metadata">

**Author:** ![Dedy\_Ariansyah](https://avatars.discourse-cdn.com/v4/letter/d/ac8455/32.png) [@Dedy\_Ariansyah](https://discourse.slicer.org/u/Dedy_Ariansyah)\
**Post date:** [May 25, 2018, 3:35pm UTC](https://discourse.slicer.org/t/2d-views-and-3d-model-transformation/2920/5 "2018-05-25T15:35:51Z")

</div>

Thanks again Andras.

I’ve been trying to understand the API to access the transformation matrix of the 3D model w.r.t to RAS but with no luck.

could you give me any clue?

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, 7:26pm UTC](https://discourse.slicer.org/t/2d-views-and-3d-model-transformation/2920/6 "2018-05-25T19:26:06Z")

</div>

SliceToRAS returns a VTKMatrix4x4 that defines the slice plane’s position (4th column of the matrix) and slice vertical and horizontal axis directions (1st and 2nd column).

---

<div class="post-metadata">

**Author:** ![Dedy\_Ariansyah](https://avatars.discourse-cdn.com/v4/letter/d/ac8455/32.png) [@Dedy\_Ariansyah](https://discourse.slicer.org/u/Dedy_Ariansyah)\
**Post date:** [May 28, 2018, 12:36pm UTC](https://discourse.slicer.org/t/2d-views-and-3d-model-transformation/2920/7 "2018-05-28T12:36:04Z")

</div>

Hi Andras,

Yes, from the snippet code that you have provided, I am able to get the transformation matrix of the planes (axial, sagittal, and coronal). This time, I am trying to understand that given the 3D model is generated in the 3D view, I want to obtain the transformation matrix of the 3D model with respect to RAS coordinate system.

Many thanks

---

<div class="post-metadata">

**Author:** ![priya.vada4](https://avatars.discourse-cdn.com/v4/letter/p/d26b3c/32.png) [@priya.vada4](https://discourse.slicer.org/u/priya.vada4)\
**Post date:** [May 28, 2018, 1:14pm UTC](https://discourse.slicer.org/t/2d-views-and-3d-model-transformation/2920/8 "2018-05-28T13:14:06Z")

</div>

Hi Dedy

For obtaining the transformation matrix of the 3D view, you will have to access the vtkMRMLCameraNode of the 3D view and then get the position and orientation of the vtk camera.

Hope that helps.

Priya

---

<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, 1:15pm UTC](https://discourse.slicer.org/t/2d-views-and-3d-model-transformation/2920/9 "2018-05-28T13:15:22Z")

</div>

By default, the model is not transformed. If you have a transform applied to the node then you can get the transform using [modelNode.GetParentTransformNode()](http://apidocs.slicer.org/master/classvtkMRMLTransformableNode.html#a66aa332e08f772323d055fe3ff74a527). If you applied linear transform(s) then you can then get the combined transformation matrix using [transformNode.GetMatrixTransformToWorld(matrix)](http://apidocs.slicer.org/master/classvtkMRMLTransformNode.html#a5d2d93382aa7da7ec3d9a27987305bce). If the transformation chain contains non-linear transforms as well then you can get it using [transformNode.GetTransformToWorld(transform)](http://apidocs.slicer.org/master/classvtkMRMLTransformNode.html#a8f740f5e6e6e9b785c365826e4fada0c).
