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

segmentation

(Jeff Cao) #1

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.


(Timeanddoctor) #2

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


(Stephan Hohmann) #3

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.


(Andras Lasso) #4

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(...) properties parameter. You can then show the volume without moving slice views using slicer.util.setSliceViewerLayers() method.