Use GR.polygonmesh3d for :mesh3d seriestype

This commit is contained in:
Lukas Hauertmann 2021-10-07 16:32:57 +02:00
parent c26561eab3
commit a41787ecc8

View File

@ -104,6 +104,9 @@ function gr_color(c, ::Type{<:AbstractGray})
end end
gr_color(c, ::Type) = gr_color(RGBA(c), RGB) gr_color(c, ::Type) = gr_color(RGBA(c), RGB)
set_RGBA_alpha(alpha, c::RGBA) = RGBA(red(c), green(c), blue(c), alpha)
set_RGBA_alpha(alpha::Nothing, c::RGBA) = c
function gr_getcolorind(c) function gr_getcolorind(c)
gr_set_transparency(float(alpha(c))) gr_set_transparency(float(alpha(c)))
convert(Int, GR.inqcolorfromrgb(red(c), green(c), blue(c))) convert(Int, GR.inqcolorfromrgb(red(c), green(c), blue(c)))
@ -2030,14 +2033,41 @@ function gr_draw_surface(series, x, y, z, clims)
GR.setfillcolorind(0) GR.setfillcolorind(0)
GR.surface(x, y, z, get(e_kwargs, :display_option, GR.OPTION_FILLED_MESH)) GR.surface(x, y, z, get(e_kwargs, :display_option, GR.OPTION_FILLED_MESH))
elseif st === :mesh3d elseif st === :mesh3d
@warn "GR: mesh3d is experimental (no face colors)" if series[:connections] isa AbstractVector{<:AbstractVector{Int}}
gr_set_line( # Combination of any polygon types
get_linewidth(series), cns = [[length(polyinds), polyinds...] for polyinds in series[:connections]]
get_linestyle(series), elseif series[:connections] isa AbstractVector{NTuple{N,Int}} where {N}
get_linecolor(series), # Only N-gons - connections have to be 1-based (indexing)
series, N = length(series[:connections][1])
) cns = [[N, polyinds...] for polyinds in series[:connections]]
GR.polyline3d(mesh3d_triangles(x, y, z, series[:connections])...) elseif series[:connections] isa NTuple{3,<:AbstractVector{Int}}
# Only triangles - connections have to be 0-based (indexing)
ci, cj, ck = series[:connections]
if !(length(ci) == length(cj) == length(ck))
throw(
ArgumentError(
"Argument connections must consist of equally sized arrays.",
),
)
end
cns = [([3, ci[i] + 1, cj[i] + 1, ck[i] + 1]) for i in eachindex(ci)]
else
throw(
ArgumentError(
"Unsupported `:connections` type $(typeof(series[:connections])) for seriestype=$st",
),
)
end
fillalpha = get_fillalpha(series)
n_polygons = length(cns)
facecolor = if series[:fillcolor] isa AbstractArray
[typeof(fc)(fc) for fc in series[:fillcolor]]
else
fill(series[:fillcolor], n_polygons)
end
# gr_set_transparency(fillalpha) # not supported via GR.jl yet -> set_RGBA_alpha
facecolor = map(fc -> set_RGBA_alpha(fillalpha, fc), facecolor)
GR.polygonmesh3d(x, y, z, vcat(cns...), signed.(gr_color.(facecolor)))
else else
throw(ArgumentError("Not handled !")) throw(ArgumentError("Not handled !"))
end end