# How to unsmooth GLMakie volume plot?

**URL:** https://discourse.julialang.org/t/how-to-unsmooth-glmakie-volume-plot/107659
**Category:** Visualization
**Tags:** glmakie
**Created:** [December 15, 2023, 12:01pm UTC](https://discourse.julialang.org/t/how-to-unsmooth-glmakie-volume-plot/107659 "2023-12-15T12:01:09Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![xinady](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xinady/32/33502_2.png) [@xinady](https://discourse.julialang.org/u/xinady)
#### Post date: [December 15, 2023, 12:01pm UTC](https://discourse.julialang.org/t/how-to-unsmooth-glmakie-volume-plot/107659/1 "2023-12-15T12:01:09Z")

</div>

Hi, I’m working with 3d voxels data and want to use volume function from GLMakie.  
I noticed that visualized volume is kind of smoothed/averaged. For example, code for one voxel inside cube is:

```julia
julia> using GLMakie 

julia> volume([0; 0; 0;; 0; 0; 0;; 0; 0; 0;;; 
               0; 0; 0;; 0; 1; 0;; 0; 0; 0;;; 
               0; 0; 0;; 0; 0; 0;; 0; 0; 0];)

```

I expected view of sharp voxel with distincted cube edges, but get image as below

 ![plot](https://global.discourse-cdn.com/julialang/original/3X/d/7/d77a5ac9c2661d3006afcb4fee04c952cce8a79f.png)  
I tried different arguments and cant figure out how to make plot as one sharp voxel inside cube.  
So my question is there way to make it sharp?  
Thank you!!!

Addition: [How to unsmooth GLMakie volume plot? - #4 by xinady](https://discourse.julialang.org/t/how-to-unsmooth-glmakie-volume-plot/107659/4)

---

<div class="post-metadata">

### Author: ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)
#### Post date: [December 15, 2023, 12:12pm UTC](https://discourse.julialang.org/t/how-to-unsmooth-glmakie-volume-plot/107659/2 "2023-12-15T12:12:43Z")

</div>

Check Meshes.jl viz recipe function. It does what you want:

```julia
using Meshes

import GLMakie as Mke

grid = CartesianGrid(10, 10, 10)

viz(grid, color = 1:1000)

```

![image](https://global.discourse-cdn.com/julialang/original/3X/d/3/d3dea5650ca7885b354309bc2dbae03e74ea6649.png)

---

<div class="post-metadata">

### Author: ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)
#### Post date: [December 15, 2023, 12:39pm UTC](https://discourse.julialang.org/t/how-to-unsmooth-glmakie-volume-plot/107659/3 "2023-12-15T12:39:56Z")

</div>

You can use the iso algorithm:

```julia
using GLMakie

volume([0; 0; 0;; 0; 0; 0;; 0; 0; 0;;;
    0; 0; 0;; 0; 1; 0;; 0; 0; 0;;;
    0; 0; 0;; 0; 0; 0;; 0; 0; 0]; algorithm=:iso, isovalue=0.05)

```

 ![image](https://global.discourse-cdn.com/julialang/original/3X/0/e/0efd4625ec0504b31b3693f98a8a461c10603bed.png)  
Which is documented here: [volume · Makie](https://docs.makie.org/stable/reference/plots/volume/)

---

<div class="post-metadata">

### Author: ![xinady](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xinady/32/33502_2.png) [@xinady](https://discourse.julialang.org/u/xinady)
#### Post date: [December 15, 2023, 1:15pm UTC](https://discourse.julialang.org/t/how-to-unsmooth-glmakie-volume-plot/107659/4 "2023-12-15T13:15:31Z")

</div>

@ [juliohm](https://discourse.julialang.org/u/juliohm) and [sdanisch](https://discourse.julialang.org/u/sdanisch) thanks for answering! May be my description was unclear. I dont need only voxel (cube) it was just minimal toy example. In reality volume will be with high number of voxels and different intensity of each voxel, CT like images. More real example:

 ![volume](https://global.discourse-cdn.com/julialang/original/3X/3/e/3eacbde3adbf3f14e5b7db09c5bd19a6225696ad.png)  
But on more real volume is harder to explaing smoothing effect.  
Anyway, just out of curisity as I understend clear MIP algorithm should not provide such smoothing effect or I’m wrong?

---

<div class="post-metadata">

### Author: ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)
#### Post date: [December 15, 2023, 1:23pm UTC](https://discourse.julialang.org/t/how-to-unsmooth-glmakie-volume-plot/107659/5 "2023-12-15T13:23:25Z")

</div>

You mean it should like this without interpolation?

 ![image](https://global.discourse-cdn.com/julialang/original/3X/f/a/fa6ee6d01d0604cff0efb3a090f0add5b0869466.png)

I guess we could add that as an option…

---

<div class="post-metadata">

### Author: ![xinady](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xinady/32/33502_2.png) [@xinady](https://discourse.julialang.org/u/xinady)
#### Post date: [December 15, 2023, 1:33pm UTC](https://discourse.julialang.org/t/how-to-unsmooth-glmakie-volume-plot/107659/6 "2023-12-15T13:33:10Z")

</div>

Yes. It would be great to have option for turning off the intepolation.

---

<div class="post-metadata">

### Author: ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)
#### Post date: [December 15, 2023, 1:37pm UTC](https://discourse.julialang.org/t/how-to-unsmooth-glmakie-volume-plot/107659/7 "2023-12-15T13:37:26Z")

</div>

@xinady have you seen the `alpha` transparency option of the `viz` recipe above? Is that what you want?

---

<div class="post-metadata">

### Author: ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)
#### Post date: [December 15, 2023, 1:38pm UTC](https://discourse.julialang.org/t/how-to-unsmooth-glmakie-volume-plot/107659/8 "2023-12-15T13:38:25Z")

</div>

Additional resource: [Geospatial Data Science with Julia - 2&nbsp; Scientific visualization](https://juliaearth.github.io/geospatial-data-science-with-julia/02-geoviz.html)

---

<div class="post-metadata">

### Author: ![sdanisch](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sdanisch/32/1406_2.png) [@sdanisch](https://discourse.julialang.org/u/sdanisch)
#### Post date: [December 18, 2023, 2:48pm UTC](https://discourse.julialang.org/t/how-to-unsmooth-glmakie-volume-plot/107659/9 "2023-12-18T14:48:34Z")

</div>

Added the feature here:

> <https://github.com/MakieOrg/Makie.jl/pull/3485>
>
> Feature for https://discourse.julialang.org/t/how-to-unsmooth-glmakie-volume-pl…ot/107659/3
> 
> \`\`\`julia
> using GLMakie
> 
> f, ax, pl = volume(\[0; 0; 0;; 0; 0; 0;; 0; 0; 0;;;
> 0; 0; 0;; 0; 1; 0;; 0; 0; 0;;;
> 0; 0; 0;; 0; 0; 0;; 0; 0; 0\]; interpolate=false, axis=(; type=Axis3, title="interpolate=false"))
> 
> volume(f\[1, 2\], \[0; 0; 0;; 0; 0; 0;; 0; 0; 0;;;
> 0; 0; 0;; 0; 1; 0;; 0; 0; 0;;;
> 0; 0; 0;; 0; 0; 0;; 0; 0; 0\]; interpolate=true, axis=(; type=Axis3, title="interpolate=true"))
> f
> \`\`\`
> \<img width="443" alt="image" src="https://github.com/MakieOrg/Makie.jl/assets/1010467/ace954d1-b404-437b-94b3-d29f52f43ff5"\>

 ![image](https://global.discourse-cdn.com/julialang/original/3X/8/c/8c0f3ef98e0dff67845544404f2c2abe3d943b6a.png)

---

<div class="post-metadata">

### Author: ![xinady](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xinady/32/33502_2.png) [@xinady](https://discourse.julialang.org/u/xinady)
#### Post date: [January 11, 2024, 1:00am UTC](https://discourse.julialang.org/t/how-to-unsmooth-glmakie-volume-plot/107659/10 "2024-01-11T01:00:53Z")

</div>

The alpha option works, but I’ve found that with while it works greate for small and medium sizes, performance suffers at larger sizes.

---

<div class="post-metadata">

### Author: ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)
#### Post date: [January 11, 2024, 1:16am UTC](https://discourse.julialang.org/t/how-to-unsmooth-glmakie-volume-plot/107659/11 "2024-01-11T01:16:28Z")

</div>

We are calling `Makie.meshscatter` in the 3D case. You can also try to convert the grid into a simple mesh with `convert(SimpleMesh, grid)` before plotting and that will call the `Makie.mesh` recipe instead.
