# VTK JS Image Slicing basics

**URL:** https://discourse.vtk.org/t/vtk-js-image-slicing-basics/4739
**Category:** Web
**Created:** [November 26, 2020, 3:19pm UTC](https://discourse.vtk.org/t/vtk-js-image-slicing-basics/4739 "2020-11-26T15:19:43Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![kit](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/k/9fc29f/32.png) [@kit](https://discourse.vtk.org/u/kit)
#### Post date: [November 26, 2020, 3:19pm UTC](https://discourse.vtk.org/t/vtk-js-image-slicing-basics/4739/1 "2020-11-26T15:19:43Z")

</div>

Hi,

I was experimenting with the image slicing example

> <https://github.com/KitwareMedical/vtk.js-examples/blob/master/src/image-slicing.js>

which are really nice btw. But if I change

`mapper.setSlicingMode(SlicingMode.Z)`

to

`mapper.setSlicingMode(SlicingMode.Y)`

The rendered image disappears (no errors). I was expecting it to take the slices using a Y- orthogonal plane instead. What else do I need to change?

---

<div class="post-metadata">

### Author: ![Forrest](https://discourse.vtk.org/user_avatar/discourse.vtk.org/forrest/32/300_2.png) [@Forrest](https://discourse.vtk.org/u/Forrest)
#### Post date: [November 30, 2020, 5:58pm UTC](https://discourse.vtk.org/t/vtk-js-image-slicing-basics/4739/2 "2020-11-30T17:58:28Z")

</div>

Hi Kit,

Have you updated your camera as well? The rendered slice respects world orientation, so showing a Y-slice when the camera is looking down the Z axis will “disappear” from the camera’s POV.

---

<div class="post-metadata">

### Author: ![kit](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/k/9fc29f/32.png) [@kit](https://discourse.vtk.org/u/kit)
#### Post date: [December 3, 2020, 3:58pm UTC](https://discourse.vtk.org/t/vtk-js-image-slicing-basics/4739/3 "2020-12-03T15:58:42Z")

</div>

That was it. Thanks.

---

<div class="post-metadata">

### Author: ![h4rry](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/h/50afbb/32.png) [@h4rry](https://discourse.vtk.org/u/h4rry)
#### Post date: [December 30, 2024, 11:12pm UTC](https://discourse.vtk.org/t/vtk-js-image-slicing-basics/4739/4 "2024-12-30T23:12:03Z")

</div>

Hi, i’ve tried updating the camera by calling `renderer.updateCamera()`, but browser throws an error (activeCamera.render() is not a function)

Do I have to manually update the parameters (viewUp, directionOfProjection, etc) instead?

---

<div class="post-metadata">

### Author: ![finetjul](https://discourse.vtk.org/user_avatar/discourse.vtk.org/finetjul/32/154_2.png) [@finetjul](https://discourse.vtk.org/u/finetjul)
#### Post date: [December 31, 2024, 2:06pm UTC](https://discourse.vtk.org/t/vtk-js-image-slicing-basics/4739/5 "2024-12-31T14:06:39Z")

</div>

Indeed, `renderer.updateCamera()` seems to not apply for “regular” cameras (but remote cameras)…

I’m not sure to understand what you are trying to do…

---

<div class="post-metadata">

### Author: ![h4rry](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/h/50afbb/32.png) [@h4rry](https://discourse.vtk.org/u/h4rry)
#### Post date: [January 1, 2025, 1:28am UTC](https://discourse.vtk.org/t/vtk-js-image-slicing-basics/4739/6 "2025-01-01T01:28:17Z")

</div>

I’m switching between different slicing modes (X, Y, Z) within the `image-slicing.js` to view the volume from different planes (axial, sagittal or coronal).

If I change `mapper.setSlicingMode(SlicingMode.Z)` to `mapper.setSlicingMode(SlicingMode.Y)` or `mapper.setSlicingMode(SlicingMode.X)`, the renderWindow just turns black. I know that I have to update the camera properties, just not sure which values to set for each slicing mode.

---

<div class="post-metadata">

### Author: ![finetjul](https://discourse.vtk.org/user_avatar/discourse.vtk.org/finetjul/32/154_2.png) [@finetjul](https://discourse.vtk.org/u/finetjul)
#### Post date: [January 2, 2025, 8:50am UTC](https://discourse.vtk.org/t/vtk-js-image-slicing-basics/4739/7 "2025-01-02T08:50:40Z")

</div>

Gotcha,

When you change slicing mode, your camera focal point does not change.  
You only need to change the camera position.  
It should be `newCameraPosition = focalPoint + distance * newSlicingNormal`. where distance could be the one before changing the slicing mode: `distance = cameraPosition - focalPoint`.
