Dear All,
Here is another chapter of the struggle to make cool figures with Makie.
My aim is to generate numerous visualizations of the 3D images that are represented by voxels. While i used the hints from the examples of the volume function, even the simplest solution for a binary (0 and 1) 3D matrix visualization still avoids me.
Here is the example of the solution i would like to achieve:
Now, here is the piece of code i could generate that i expected will produce the image above (but it does not do the trick):
using GLMakie, ColorSchemes
using GeometryBasics: Rect3f
let
path="d:\\path\\to\\BCC_100.raw" #this is a .raw binary example for visuazliation
cd(dirname(path))
cubesize=trunc(Int64,round(filesize(path)^(1/3)))
stream = open(path, "r")
#x, y, z = cubesize
points3d = Array{UInt8,3}(undef, cubesize, cubesize, cubesize)
read!(stream, points3d)
points3d = deepcopy(points3d)
close(stream)
for k=1:cubesize, i=1:cubesize, j=1:cubesize
points3d[i,j,k]=points3d[j,i,k]
end
x = y = z = 1:1:cubesize
vol1 = [ix * iy * iz for ix in x, iy in y, iz in z]
#points3d = [Point3f(ix, iy, iz) for ix in x, iy in y, iz in z]
# scale everything to the interval 0,1 (things don't seem to work with colorrange)
#vol2 = (vol1 .+ 1) ./ 2
# colormap with transparency in the middle
cmap = :Hiroshige
colors = to_colormap(cmap, 101)
n = length(colors)
g(x) = x^2
alphas = [g(x) for x in range(1, cubesize, length = n)]
cmap_alpha = RGBAf.(colors, alphas)
# the plot
fig = Figure(resolution = (1000, 1000))
#ax1 = Axis3(fig[1, 1], perspectiveness = 0.5, azimuth = 7.19,
# elevation = 0.57, aspect = (1, 1, 1))
#ax2 = Axis3(fig[1, 2], perspectiveness = 0.5, azimuth = 6.62,
# elevation = 0.57, aspect = (1, 1, 1))
#ax3 = Axis3(fig[2, 1], perspectiveness = 0.5, azimuth = 7.38,
# elevation = 0.57, aspect = (1, 1, 1))
ax4 = Axis3(fig[1, 1], perspectiveness = 0.5, azimuth = 6.64,
elevation = 0.57, aspect = (1, 1, 1))
#volume!(ax1, x, y, z, vol2; colormap = cmap, transparency = true)
#contour!(ax2, x, y, z, vol1; colormap = cmap, alpha = 0.05,
# levels = [collect(-1:0.01:-0.3)..., collect(0.3:0.01:1)...])
#meshscatter!(ax3, vec(points3d); color = vec(vol1), colormap = cmap_alpha)
meshscatter!(ax4, vec(points3d); color = vec(vol1), colormap = cmap_alpha,
marker = Rect3f(Vec3f(-1), Vec3f(2)))
limits!(ax4, 0, 301, 0, 301, 0, 301)
#display(fig)
Makie.save("test.png", fig)
end
The example raw binary (path=“d:\path\to\BCC_100.raw”) for visualization (a 100^3 matrix of 0 and 1 with the structure as on the image below) can be downloaded here:
Many thanks in advance for providing a direction of how i can make some nice visualizations (which i eventually want to extend to non binary multi-colored 3D structures).
Kirill