# VTK multivolume/cinematic volume rendering

**URL:** <https://discourse.slicer.org/t/vtk-multivolume-cinematic-volume-rendering/31981>\
**Category:** Support\
**Created:** [October 1, 2023, 2:16pm UTC](https://discourse.slicer.org/t/vtk-multivolume-cinematic-volume-rendering/31981 "2023-10-01T14:16:11Z")\
**Posts on this page:** 20\
**Page:** 2

<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:** [October 11, 2023, 4:47pm UTC](https://discourse.slicer.org/t/vtk-multivolume-cinematic-volume-rendering/31981/21 "2023-10-11T16:47:21Z")

</div>

Looks like that variable didn’t get set. Probably it needs to be exposed in the UI. For now you can just comment out this line (put `#` at the front) in /Users/amaga/Desktop/SlicerPreview.app/Contents/Extensions-32228/Sandbox/lib/Slicer-5.5/qt-scripted-modules/ColorizeVolume.py", line 348. or set the variable manually.

> <https://github.com/PerkLab/SlicerSandbox/blob/master/ColorizeVolume/ColorizeVolume.py#L348>

---

<div class="post-metadata">

**Author:** ![muratmaga](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/muratmaga/32/83011_2.png) [@muratmaga](https://discourse.slicer.org/u/muratmaga)\
**Post date:** [October 11, 2023, 5:02pm UTC](https://discourse.slicer.org/t/vtk-multivolume-cinematic-volume-rendering/31981/22 "2023-10-11T17:02:10Z")

</div>

OMG! This is a game changer for us.

We just now a way to adjust TF per segment basis somehow… And regular shadows/lights work great, just need the ambient shadows as @lassoan mentioned.

 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/6/c/6c5a532f77905930b10be6ff74d8539992e8f41f.jpeg)

---

<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:** [October 11, 2023, 5:06pm UTC](https://discourse.slicer.org/t/vtk-multivolume-cinematic-volume-rendering/31981/23 "2023-10-11T17:06:29Z")

</div>

gorgeous image! Keep 'em coming.

---

<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:** [October 11, 2023, 5:11pm UTC](https://discourse.slicer.org/t/vtk-multivolume-cinematic-volume-rendering/31981/24 "2023-10-11T17:11:00Z")

</div>

I’m making some changes/fixes. You’ll get even better results! Just need an hour or so.

---

<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:** [October 11, 2023, 10:37pm UTC](https://discourse.slicer.org/t/vtk-multivolume-cinematic-volume-rendering/31981/25 "2023-10-11T22:37:16Z")

</div>

It’s all ready. You can update manually from github or download the Slicer Preview Release tomorrow to get the updated version.

Example renderings:

Default rendering:

[https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/e/6/e6ab346a328e725ba3fe8b4f1b95f5c1d186cc27.mp4](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/e/6/e6ab346a328e725ba3fe8b4f1b95f5c1d186cc27.mp4)

Using gradient opacity:

[https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/0/a/0a318ef6ec27092d0732ca3ef376bc9096c23534.mp4](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/0/a/0a318ef6ec27092d0732ca3ef376bc9096c23534.mp4)

---

<div class="post-metadata">

**Author:** ![muratmaga](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/muratmaga/32/83011_2.png) [@muratmaga](https://discourse.slicer.org/u/muratmaga)\
**Post date:** [October 11, 2023, 11:07pm UTC](https://discourse.slicer.org/t/vtk-multivolume-cinematic-volume-rendering/31981/27 "2023-10-11T23:07:34Z")

</div>

> [@lassoan](#):
>
> It’s all ready. You can update manually from github or download the Slicer Preview Release tomorrow to get the updated version.

I am now working home with remote connection to lab server, and while it works with CPU rendering, I am getting bad memory allocation with GPU rendering.

This is probably an issue with virtualGL. However, when I invoke slicer without vgl, I still get the error with GPU rendering (which should use the software renderer). Tomorrow, when I back I will try with windows and report back.

`  
"Slicer has caught an application error, please save your work and restart.

The application has run out of memory. Increasing swap size in system settings or adding more RAM may fix this issue. f you have a repeatable sequence of steps that causes this message, please report the issue following instructions available at [https://slicer.org](https://slicer.org)\n\n\nThe message detail is:\n\nException thrown in event: std::bad\_alloc"  
`

---

<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:** [October 11, 2023, 11:21pm UTC](https://discourse.slicer.org/t/vtk-multivolume-cinematic-volume-rendering/31981/28 "2023-10-11T23:21:40Z")

</div>

You can crop&resample the volume if you run out of memory. Or, as suggested, increase the swap size.

We use a couple of temporary buffers during computation that we release when the processing is completed. We can tune the code a bit to delete the buffers immediately when they are no longer needed. Let me know what line fails (you can run the module in a debugger or add logs to get the location).

---

<div class="post-metadata">

**Author:** ![muratmaga](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/muratmaga/32/83011_2.png) [@muratmaga](https://discourse.slicer.org/u/muratmaga)\
**Post date:** [October 11, 2023, 11:51pm UTC](https://discourse.slicer.org/t/vtk-multivolume-cinematic-volume-rendering/31981/29 "2023-10-11T23:51:26Z")

</div>

I dont think out of memory is real (it is working off a gpu with 48gb and all iof which is available) and system has hundreds of gigs available.

---

<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:** [October 12, 2023, 1:01am UTC](https://discourse.slicer.org/t/vtk-multivolume-cinematic-volume-rendering/31981/30 "2023-10-12T01:01:37Z")

</div>

GPU RAM should be fine. "The application has run out of memory…“ popup means that a memory allocation failed due to not enough CPU RAM / swap size configured in the OS. To confirm that you run out of memory, please crop&resample the input image. You can also send me the image and I can test it for you.

---

<div class="post-metadata">

**Author:** ![muratmaga](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/muratmaga/32/83011_2.png) [@muratmaga](https://discourse.slicer.org/u/muratmaga)\
**Post date:** [October 12, 2023, 1:40am UTC](https://discourse.slicer.org/t/vtk-multivolume-cinematic-volume-rendering/31981/31 "2023-10-12T01:40:29Z")

</div>

It doesn’t run out of memory during other datasets (that are much bigger). But anyways, if you like to try on your own I am using the files starting with 35\_mic

> <https://github.com/muratmaga/mouse_CT_atlas/tree/master/data/templates>
>
> //github.com/muratmaga/mouse\_CT\_atlas/tree/master/data/templates

---

<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:** [October 12, 2023, 2:21am UTC](https://discourse.slicer.org/t/vtk-multivolume-cinematic-volume-rendering/31981/32 "2023-10-12T02:21:38Z")

</div>

I don’t see any problems with this mouse template on my computer. It is quite small, loads and renders quickly:

[https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/e/3/e3ce4368d60da5c96be446bbaa63005e68c0e14b.mp4](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/e/3/e3ce4368d60da5c96be446bbaa63005e68c0e14b.mp4)

---

<div class="post-metadata">

**Author:** ![muratmaga](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/muratmaga/32/83011_2.png) [@muratmaga](https://discourse.slicer.org/u/muratmaga)\
**Post date:** [October 12, 2023, 2:30am UTC](https://discourse.slicer.org/t/vtk-multivolume-cinematic-volume-rendering/31981/33 "2023-10-12T02:30:02Z")

</div>

Yes, it works fine on my Mac too (that’s why I think it has smoething to do with remote connection or the virtualgl). Curious that your exported color volume doesn’t also show the brain endocast. When i redid a second time, that’s when it became visible…

---

<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:** [October 12, 2023, 3:00am UTC](https://discourse.slicer.org/t/vtk-multivolume-cinematic-volume-rendering/31981/34 "2023-10-12T03:00:25Z")

</div>

The endocast is air, and even if you color the region by the segmentation, it will still remain empty and will not show up (the boundary may be somewhat visible due to the edge smoothing). To display the endocast you can use “Mask volume” effect to virtually fill it with water or some other material.

---

<div class="post-metadata">

**Author:** ![Deep\_Learning](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/deep_learning/32/15345_2.png) [@Deep\_Learning](https://discourse.slicer.org/u/Deep_Learning)\
**Post date:** [October 12, 2023, 3:39pm UTC](https://discourse.slicer.org/t/vtk-multivolume-cinematic-volume-rendering/31981/35 "2023-10-12T15:39:36Z")

</div>

Unreal… I am having better/awesome experience with windows. Ubuntu, I am getting the alloc error.

---

<div class="post-metadata">

**Author:** ![muratmaga](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/muratmaga/32/83011_2.png) [@muratmaga](https://discourse.slicer.org/u/muratmaga)\
**Post date:** [October 12, 2023, 3:51pm UTC](https://discourse.slicer.org/t/vtk-multivolume-cinematic-volume-rendering/31981/36 "2023-10-12T15:51:17Z")

</div>

Yes, I think the out of memory error with vtkGPURaycasting is real. I am getting it even with mrhead simply when I am using GPURaycasting on vanialla data (no colorization or anything (with or without vgl).

Probably better to post this on the GH issues though.

---

<div class="post-metadata">

**Author:** ![muratmaga](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/muratmaga/32/83011_2.png) [@muratmaga](https://discourse.slicer.org/u/muratmaga)\
**Post date:** [October 13, 2023, 4:43am UTC](https://discourse.slicer.org/t/vtk-multivolume-cinematic-volume-rendering/31981/37 "2023-10-13T04:43:08Z")

</div>

I opened a bug report on Slicer repo, because I can reproduce the behavior without installing any extension. See

> <https://github.com/Slicer/Slicer/issues/7281>
>
> 1. Download and install the latest preview (I used r32228) for Linux (testing wi…th Ubuntu 20 and 22, both on cloud and locally). 
> 2. obtain MRHead and try to volume rendering with gpu rendering. 
> 
> Consistently crashes with bad allocation error. See screenshot above. Doesn't reproduce on windows or mac. 
> 
> 
> 
> \<img width="1225" alt="image" src="https://github.com/Slicer/Slicer/assets/21285140/daf51f74-60e2-4dea-9aa2-3bc1e579ab7e"\>
> 
> @lassoan @pieper

---

<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:** [October 13, 2023, 1:50pm UTC](https://discourse.slicer.org/t/vtk-multivolume-cinematic-volume-rendering/31981/39 "2023-10-13T13:50:19Z")

</div>

This looks really, really nice!

To make it a sequence, add the colorized volume to the sequence:

- in Sequences module, click the green `+` icon to add a new sequence
- in the table below set the colorized volume as `Proxy node`
- enable `Save changes`

After this, you can generate the colorized volume sequence by iterating through the time points of the sequence (manually, using the sequence toolbar) and click `Apply` for each. Since the colorized volume is assigned to a sequence and you enabled saving, the a new colorized volume is stored for each time point.

You can create an animation video by using Screen Capture module with “sequence” animation mode.

It would be great if you could post the resulting video here.

---

<div class="post-metadata">

**Author:** ![Deep\_Learning](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/deep_learning/32/15345_2.png) [@Deep\_Learning](https://discourse.slicer.org/u/Deep_Learning)\
**Post date:** [October 13, 2023, 2:33pm UTC](https://discourse.slicer.org/t/vtk-multivolume-cinematic-volume-rendering/31981/40 "2023-10-13T14:33:09Z")

</div>

I’m sorry, I was not specific enough.

I start with a segmentation sequence and a volume sequence. 20 segmentations and 20 volumes.  
Saved as an .mrb. It’s awesome… drag and drop.

When using Colorize Volume, I have Input volume = Volume Sequence and Input segmentation =Segmentation sequence. The result is a single colorized volume selected from the sequence browser. I’m not sure how that exactly happens.

I see two paths:

1. A separate python script to iterate over n=20 segs and vols. But my guess is that this would necessitate the creation of the Colorize Volume Widget, setting all options, …20 times…
2. Hacking the “Colorize Volume Extension” to “Colorize Volume Sequence Extension”. The options in the ui would be set once and used. Create a new sequence and fill it.

I think that option #2 is the best… just wanted to confirm…it’s a lot of trial and error. I am now familar with scripting a shape rendered sequence, but this is my first volume render…

Really nice extension!!! Thank you!!!

---

<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:** [October 13, 2023, 3:00pm UTC](https://discourse.slicer.org/t/vtk-multivolume-cinematic-volume-rendering/31981/41 "2023-10-13T15:00:26Z")

</div>

> [@Deep\_Learning](#):
>
> I start with a segmentation sequence and a volume sequence. 20 segmentations and 20 volumes.  
> Saved as an .mrb. It’s awesome… drag and drop.

After this, use Colorize volume on one time point and then add the created colorized volume to the sequence as I described in my previous post.

If it is acceptable to do two keypresses per time point (Ctrl + Shift + Right-arrow to go to the next frame and Space key to Apply colorization) then there is no need for any programming. If you do this regularly then you can write a tiny Python script that automates these two actions (3-4 lines of code).

If it is commonly needed by other users, too, then we can add an `Apply to all time points` option to the Colorize volume module that automates these few steps (adding the colorized volume to a sequence + apply colorization for all time points, not just the current one).

---

<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:** [October 15, 2023, 7:54pm UTC](https://discourse.slicer.org/t/vtk-multivolume-cinematic-volume-rendering/31981/43 "2023-10-15T19:54:51Z")

</div>

Thanks for sharing, this looks pretty amazing!

[Previous page](https://discourse.slicer.org/t/vtk-multivolume-cinematic-volume-rendering/31981.md?page=1)

[Next page](https://discourse.slicer.org/t/vtk-multivolume-cinematic-volume-rendering/31981.md?page=3)
