# Center a volume in 3D scene

**URL:** <https://discourse.slicer.org/t/center-a-volume-in-3d-scene/6318>\
**Category:** Development\
**Created:** [March 28, 2019, 4:30am UTC](https://discourse.slicer.org/t/center-a-volume-in-3d-scene/6318 "2019-03-28T04:30:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alex1](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@Alex1](https://discourse.slicer.org/u/Alex1)\
**Post date:** [March 28, 2019, 4:30am UTC](https://discourse.slicer.org/t/center-a-volume-in-3d-scene/6318/1 "2019-03-28T04:30:03Z")

</div>

Hi, I want to center a certain volume in the 3D view. I tried  
layoutManager = slicer.app.layoutManager()  
threeDWidget = layoutManager.threeDWidget(0)  
threeDView = threeDWidget.threeDView()  
threeDView.resetFocalPoint()  
in the scripted repository, but I have more than one nodes in the scene and I don’t want to delete them, so it doesn’t work. Does anyone have any idea how to do this?

Thanks for your time!

---

<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:** [March 29, 2019, 9:17pm UTC](https://discourse.slicer.org/t/center-a-volume-in-3d-scene/6318/2 "2019-03-29T21:17:25Z")

</div>

You don’t need to delete the nodes that you don’t want to include in the center computation, just temporarily hide them (`node.GetDisplayNode().SetVisibility(False)`).

---

<div class="post-metadata">

**Author:** ![Alex1](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@Alex1](https://discourse.slicer.org/u/Alex1)\
**Post date:** [March 31, 2019, 2:14am UTC](https://discourse.slicer.org/t/center-a-volume-in-3d-scene/6318/3 "2019-03-31T02:14:11Z")

</div>

Hi Andras,  
Thanks for your answer! I tried hiding them but it is still not at the center on the scene.  
If I have more than one volumes, even if I hide the others, the volume still won’t be at the center on the scene.  
What I want to know is how to center one specific volume while other volumes are still there.  
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:** [March 31, 2019, 4:17am UTC](https://discourse.slicer.org/t/center-a-volume-in-3d-scene/6318/4 "2019-03-31T04:17:00Z")

</div>

You can center the camera on a node by basic VTK method calls. Something like this should work:

```auto
node = getNode('CTChest')
threedView = slicer.app.layoutManager().threeDWidget(0).threeDView()

# Get volume center
bounds=[0,0,0,0,0,0]
node.GetRASBounds(bounds)
nodeCenter = [(bounds[0]+bounds[1])/2, (bounds[2]+bounds[3])/2, (bounds[4]+bounds[5])/2]

# Shift camera to look at the new focal point
renderWindow = threedView.renderWindow()
renderer = renderWindow.GetRenderers().GetFirstRenderer()
camera = renderer.GetActiveCamera()
oldFocalPoint = camera.GetFocalPoint()
oldPosition = camera.GetPosition()
cameraOffset = [nodeCenter[0]-oldFocalPoint[0], nodeCenter[1]-oldFocalPoint[1], nodeCenter[2]-oldFocalPoint[2]]
camera.SetFocalPoint(nodeCenter)
camera.SetPosition(oldPosition[0]+cameraOffset[0], oldPosition[1]+cameraOffset[1], oldPosition[2]+cameraOffset[2])

```
