# How to load new volume while keeping the view parameters, such as 3D orientation, 2D slice number?

**URL:** <https://discourse.slicer.org/t/how-to-load-new-volume-while-keeping-the-view-parameters-such-as-3d-orientation-2d-slice-number/5597>\
**Category:** Development\
**Tags:** segmentation\
**Created:** [January 31, 2019, 10:50am UTC](https://discourse.slicer.org/t/how-to-load-new-volume-while-keeping-the-view-parameters-such-as-3d-orientation-2d-slice-number/5597 "2019-01-31T10:50:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jeff\_CAO](https://avatars.discourse-cdn.com/v4/letter/j/b19c9b/32.png) [@Jeff\_CAO](https://discourse.slicer.org/u/Jeff_CAO)\
**Post date:** [January 31, 2019, 10:50am UTC](https://discourse.slicer.org/t/how-to-load-new-volume-while-keeping-the-view-parameters-such-as-3d-orientation-2d-slice-number/5597/1 "2019-01-31T10:50:03Z")

</div>

Hi, everyone. I am a slicer beginner. I am going to write a application based on slicer in python. A problem makes me struggled. **I need to reload a volume both in 2D viewers and render this volume. More importantly, I need to keep the orientations in 3D and 2D layer slice number (or everything except the volume data)**. I tried to extract the _scene_ node first, and reserve scene properties. But whenever I use the reload button to change the volume data, then it returns none _scene_. Your suggestions would be really appreciated. Thanks.

---

<div class="post-metadata">

**Author:** ![timeanddoctor](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/timeanddoctor/32/5839_2.png) [@timeanddoctor](https://discourse.slicer.org/u/timeanddoctor)\
**Post date:** [January 31, 2019, 10:54am UTC](https://discourse.slicer.org/t/how-to-load-new-volume-while-keeping-the-view-parameters-such-as-3d-orientation-2d-slice-number/5597/2 "2019-01-31T10:54:47Z")

</div>

Maybe you can take a transform (“General registration (BRAINS)” and “General registration (Elastix)” modules) between them to align…after load Dicom with different RAS

---

<div class="post-metadata">

**Author:** ![stephan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/stephan/32/2444_2.png) [@stephan](https://discourse.slicer.org/u/stephan)\
**Post date:** [January 31, 2019, 7:04pm UTC](https://discourse.slicer.org/t/how-to-load-new-volume-while-keeping-the-view-parameters-such-as-3d-orientation-2d-slice-number/5597/3 "2019-01-31T19:04:03Z")

</div>

You can use vtkMRMLSliceNode::GetSliceToRAS() to retrieve the current slice view position.

Example for the Red slice view:

```
viewMatrixRed = vtk.vtkMatrix4x4()
viewMatrixRed.DeepCopy(slicer.app.layoutManager().sliceWidget("Red").mrmlSliceNode().GetSliceToRAS())

```

then, after loading your new volume, set the Red slice view to the settings saved in viewMatrixRed:

```
slicer.app.layoutManager().sliceWidget("Red").mrmlSliceNode().GetSliceToRAS().DeepCopy(viewMatrixRed)

```

The only thing I was not able to get working quickly is to force updating the Red view. So it is not instantly re-drawn at the new new slice position.  
But if you, for now, pan the view a little (drag while holding the middle mouse button), it is updated and the saved slice setting is shown.  
If someone else could pitch in how to force the slice view to update / re-draw, that would be perfect.

---

<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, 2019, 2:55am UTC](https://discourse.slicer.org/t/how-to-load-new-volume-while-keeping-the-view-parameters-such-as-3d-orientation-2d-slice-number/5597/4 "2019-02-02T02:55:58Z")

</div>

> [@stephan](#):
>
> If someone else could pitch in how to force the slice view to update / re-draw, that would be perfect.

You can call `slicer.app.layoutManager().sliceWidget("Red").mrmlSliceNode()->UpdateMatrices()` to update slice views after modifying SliceToRAS

If the goal is to load the volume but leave the viewers intact, add `{"show": False}` to [`slicer.util.loadVolume(...)`](https://slicer.readthedocs.io/en/latest/developer_guide/slicer.html#slicer.util.loadVolume) properties parameter. You can then show the volume without moving slice views using [`slicer.util.setSliceViewerLayers()`](https://slicer.readthedocs.io/en/latest/developer_guide/slicer.html#slicer.util.setSliceViewerLayers) method.
