Makie: Colouring 3D Contours by another Array

You can get/color your contours according to the values of the Entropy, using MarchingCubes.jl, respectively PlotlyJS.jl.
PlotlyJS can plot volumes and contours, but not according to the values of an additional array.
You can use instead MarchingCubes to carve each contour into the volume, KinEnergy, and PlotlyJS to display it as a 3d Mesh, colored according to the values of Entropy at its points.
Below is defined an arbitrary function (sin(z)) to color each contour, just to see how it works.
Hence you have to get the values of entropy at the points of coordinates
(xv[i], yv[i], zv[i]), i=1:N, through interpolation.

using PlotlyJS, MarchingCubes
function mesh_data(fvals::Array{T,3};  v₀=0.0) where T <: AbstractFloat
    #instantiate the structure MC (Marching Cube)
    mc = MC(fvals, Int)
    m = march(mc, v₀) #v₀ is the isovalue
    #extract data for the 3d mesh to be plotly plotted
    xv, yv, zv = eachrow(reduce(hcat, mc.vertices))    
    I, J, K = eachrow(reduce(hcat, mc.triangles) .- 1) #0-based  indices for triangles
    return xv, yv, zv, I, J, K
end
begin
    domain_size = 2π
    npts = 64; dx = domain_size / npts
    points = LinRange(dx / 2, domain_size - dx / 2, npts)

    data = [InitConds(x, y, z) for x = points, y = points, z = points]
    KinEnergy = getindex.(data, 1)
    Entropy = getindex.(data, 2)
    pl_data= AbstractTrace[]
    for v0 in [0.1, 0.3, 0.5, 0.7, 0.9]
        xv, yv, zv, I, J, K = mesh_data(KinEnergy; v₀= v0)
        push!(pl_data, mesh3d(x=xv, y=yv, z=zv,
                     i=I, j=J, k=K,
                     intensity=sin.(zv),#here would go the Entropy evaluated, through interpolation, at the contour points
                     colorscale=colors.plasma,   
                     showscale=false,
                     opacity=0.6,
                     lighting=attr(ambient=0.65,
                                   diffuse=0.5,
                                   fresnel=0.25,        
                                   specular=0.25,
                                   roughness=0.23),
                     lightposition=attr(x=1000, y=1000, z=100)
             ))
    end            
    layout = Layout(
                 width=600,
                 height=600,
                 scene=attr( 
                    aspectmode="data",
                    camera_eye=attr(x=1.6, y=1.15, z=0.8),
                    ))
         
    pl = Plot(pl_data, layout) 
end

contours

1 Like