# CpuRaycasting too pixelated for small voxel data

**URL:** <https://discourse.slicer.org/t/cpuraycasting-too-pixelated-for-small-voxel-data/16245>\
**Category:** Support\
**Created:** [February 26, 2021, 5:50pm UTC](https://discourse.slicer.org/t/cpuraycasting-too-pixelated-for-small-voxel-data/16245 "2021-02-26T17:50:31Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![muratmaga](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/muratmaga/32/3622_2.png) [@muratmaga](https://discourse.slicer.org/u/muratmaga)\
**Post date:** [February 26, 2021, 5:50pm UTC](https://discourse.slicer.org/t/cpuraycasting-too-pixelated-for-small-voxel-data/16245/1 "2021-02-26T17:50:31Z")

</div>

We will be running our SlicerMOrph workshop using cloud resources, which doesn’t have a GPU. I have been testing CPUraycasting. While large voxel spacing rendering quality is good. For small voxel data seems very noisy. This seems to replicate both in the stable and the preview. Is there a solution for this?  
CPU:  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/5/d/5d5eb5bd3d21a230de4a0449d47b46f9b0ff9b1d.jpeg)

same with GPU  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/7/a/7a9870897b5cab9efb0fc8da14c49fe4494cd93d.jpeg)

same volume with CPU rendering spacing increased by 10X (0.035 to 0.35mm)  
 ![image](https://us1.discourse-cdn.com/flex002/uploads/slicer/original/3X/4/0/40cc1c76223150503bcad487c41789a2cca1cdd3.jpeg)

@lassoan @pieper

---

<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:** [February 26, 2021, 8:23pm UTC](https://discourse.slicer.org/t/cpuraycasting-too-pixelated-for-small-voxel-data/16245/2 "2021-02-26T20:23:28Z")

</div>

Unfortunately there probably are some ray casting heuristics that don’t work well across scales.

For many environments you can enable GPU even if there’s no hardware and the software fallback will still work - I take it this didn’t work for you on your virtual system?

For example GPU ray cast mode works in this docker even though it’s not hardware:  
`docker run --rm -p 8080:8080 stevepieper/slicer-morph:4.11.20200930` connecting to `localhost:8080`

Not sure if there’s a short-term fix otherwise, but if you post the sample data we could determine if this is a Slicer thing or is reproducible in native VTK.

---

<div class="post-metadata">

**Author:** ![muratmaga](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/muratmaga/32/3622_2.png) [@muratmaga](https://discourse.slicer.org/u/muratmaga)\
**Post date:** [February 26, 2021, 8:24pm UTC](https://discourse.slicer.org/t/cpuraycasting-too-pixelated-for-small-voxel-data/16245/3 "2021-02-26T20:24:36Z")

</div>

> [@pieper](#):
>
> For many environments you can enable GPU even if there’s no hardware and the software fallback will still work - I take it this didn’t work for you on your virtual system?

It works ok up to a limit. For large datasets, GPU software rendering is way too slow. Performance is much better on CPU, when you have enough cores.

---

<div class="post-metadata">

**Author:** ![muratmaga](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/muratmaga/32/3622_2.png) [@muratmaga](https://discourse.slicer.org/u/muratmaga)\
**Post date:** [February 26, 2021, 8:26pm UTC](https://discourse.slicer.org/t/cpuraycasting-too-pixelated-for-small-voxel-data/16245/4 "2021-02-26T20:26:30Z")

</div>

> [@pieper](#):
>
> Not sure if there’s a short-term fix otherwise, but if you post the sample data we could determine if this is a Slicer thing or is reproducible in native VTK.

It is the sample data we distribute with slicermorph: [SampleData/sample\_Skyscan\_mCT\_reconstruction.zip at master · SlicerMorph/SampleData · GitHub](https://github.com/SlicerMorph/SampleData/blob/master/sample_Skyscan_mCT_reconstruction.zip) it is 0.035mm isotropic voxel.

---

<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 26, 2021, 8:35pm UTC](https://discourse.slicer.org/t/cpuraycasting-too-pixelated-for-small-voxel-data/16245/5 "2021-02-26T20:35:05Z")

</div>

The CPU volume renderer in VTK does not take into account the user matrix (that we use to position, orient, and scale the volume). It would be hard to change this, because it is a complex mechanism and the CPU renderer is not developed anymore in VTK. However, we can work around this by passing just the scaling to the volume renderer, and use the user matrix only for positioning and scaling. I’ll send a pull request with this workaround.

There is a difference between the GPU and CPU volume renderer in that after scaling, the CPU-rendered volume becomes more transparent (as it should), while the GPU-rendered version does not. Probably the GPU volume renderer transfer function evaluation code does not take into account the user transform when evaluating the transfer functions, which may be justified if we consider user transform as a way to position/scale the rendered object (in that case, the same workaround should be applied to it as for the CPU renderer).

Note that the GPU volume renderer has already many more features than the CPU volume renderer (for example, custom shaders), and the gap will get even wider in the future.

---

<div class="post-metadata">

**Author:** ![muratmaga](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/muratmaga/32/3622_2.png) [@muratmaga](https://discourse.slicer.org/u/muratmaga)\
**Post date:** [February 26, 2021, 8:37pm UTC](https://discourse.slicer.org/t/cpuraycasting-too-pixelated-for-small-voxel-data/16245/6 "2021-02-26T20:37:51Z")

</div>

Thanks Andras. I will try when you can fix the issue.

> [@lassoan](#):
>
> Note that the GPU volume renderer has already many more features than the CPU volume renderer (for example, custom shaders), and the gap will get even wider in the future.

Unfortunately, economically it is 3-4 times as expensive to have the same cloud server with the GPU (and the only thing GPU is used for rendering, which is a small but important part of the course). Yes, normally we always use the GPU rendering (hence never was aware of this issue until now).

---

<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 26, 2021, 8:41pm UTC](https://discourse.slicer.org/t/cpuraycasting-too-pixelated-for-small-voxel-data/16245/7 "2021-02-26T20:41:21Z")

</div>

I’ve pushed the [fix](https://github.com/Slicer/Slicer/commit/717b7c4a99028583ebcb55e248701367baf5bce6). It will be in the Slicer Preview Release tomorrow. It would be great if you could test it (I wanted to give it some more testing and send a pull request, but accidentally pushed it directly to the master).
