This would be really good to add to the docs, I never need volume plots but there is just one example and it’s not clear at all how to use the other modes.
I would expect to see two intersecting ellipsoids, with axis sitting behind (less visible due to being behind more than one layer). Here I plotted the smaller (closer) surface first. The impression is that both sit behind the axis, and the closer one appears behind the further because transparency is only with respect to axes. I have tried applying an alpha to colormap (suggested above), but I haven’t had much luck improving this
using GLMakie
X = -40:5:40
ellipse1 = [X^2/2 + Y^2 + 2Z^2 for X in X, Y in X, Z in X];
ellipse2 = [X^2/2 + (Y-20)^2 + 2Z^2 for X in X, Y in X, Z in X];
v1=volume(ellipse2, algorithm = :iso,isovalue =350,isorange = 50,transparency=true)
volume!(ellipse1, algorithm = :iso, isovalue =700,isorange = 50,transparency=true)
v1
using GLMakie, ColorSchemes
cbarPal= :plasma
cmap = get(colorschemes[cbarPal], LinRange(0,1,100))
cmap2 = [(cmap[i],0.65) for i in 1:100]
X = -40:5:40
ellipse1 = [X^2/2 + Y^2 + 2Z^2 for X in X, Y in X, Z in X];
ellipse2 = [X^2/2 + (Y-20)^2 + 2Z^2 for X in X, Y in X, Z in X];
volume(ellipse2, algorithm = :iso,isovalue =350,isorange = 50, colormap=cmap2)
volume!(ellipse1, algorithm = :iso, isovalue =700,isorange = 50, colormap=cmap2)
current_figure()
Ok, getting closer. Still puzzling: I make a torus geometry. Why isn’t the full torus visible even though there is an alpha? It seems that the alpha is applied to another surface (dual ellipsoid case above), but not to different parts of the same surface. We should be able to see the core of the torus, and the back surface:
using GLMakie
using ColorSchemes
cmap3 = get(colorschemes[:plasma], LinRange(0,1,100))
cmap4 = [(cmap3[i],0.65) for i in 1:100]
ξ = -40:1:40
c = 20
a = 15
torus = [((hypot(X,Y)-c)^2+Z^2-a^2) for X in ξ, Y in ξ, Z in ξ]
volume(torus, algorithm = :iso,isovalue =100,isorange =50, colormap=cmap4)
current_figure()
It seems like contour can sort of do this, but the visibility is not great and there is also a loss of surface information and the result is not really very clear:
(@v1.10) pkg> status GLMakie
Status `~/.julia/environments/v1.10/Project.toml`
[e9467ef8] GLMakie v0.10.2
using GLMakie
using ColorSchemes
cmap3 = get(colorschemes[:plasma], LinRange(0,1,100))
cmap4 = [(cmap3[i],0.65) for i in 1:100]
ξ = -40:1:40
c = 20
a = 15
torus = [((hypot(X,Y)-c)^2+Z^2-a^2) for X in ξ, Y in ξ, Z in ξ]
contour(torus,levels=[1],colormap=:greens,alpha=0.1)
Maybe I am not using the right parameters or light sources?
Is there a way to get the best of both worlds, more like the matlab figure above?
I have also tried making the colormap transparent, and that didn’t help.
using GLMakie, Meshing, GeometryBasics
ξ = -40:.5:40
c = 20
a = 15
torus = [((hypot(X,Y)-c)^2+Z^2-a^2) for X in ξ, Y in ξ, Z in ξ]
##
with_theme(theme_dark()) do
algo = MarchingCubes(iso=100)
vts, fcs = isosurface(torus, algo)
mc = Makie.GeometryBasics.Mesh(vts .|> Makie.Point3, fcs .|> Makie.GeometryBasics.TriangleFace)
f ,ax,pl=mesh(normal_mesh(mc),
color=(:dodgerblue, .7),
diffuse = Vec3f0(0.8),
specular = Vec3f0(1.1),
shininess = 30f0,
backlight = 5f0,
axis = (show_axis = false, ))
f
end