Use GR.polygonmesh3d for :mesh3d seriestype (#3868)

* Use `GR.polygonmesh3d` for `:mesh3d` seriestype

* Remove unecessary code

* Update GR version dependency

* Add drawing of edges in `:mesh3d` with GR
This commit is contained in:
Lukas Hauertmann 2021-10-13 11:35:06 +02:00 committed by Zhanibek
parent ba2ac2d1e9
commit d47d7864e8
2 changed files with 40 additions and 9 deletions

View File

@ -37,7 +37,7 @@ UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
Contour = "0.5" Contour = "0.5"
FFMPEG = "0.2 - 0.4" FFMPEG = "0.2 - 0.4"
FixedPointNumbers = "0.6 - 0.8" FixedPointNumbers = "0.6 - 0.8"
GR = "0.53 - 0.61" GR = "0.60 - 0.61"
GeometryBasics = "0.2, 0.3.1, 0.4" GeometryBasics = "0.2, 0.3.1, 0.4"
JSON = "0.21, 1" JSON = "0.21, 1"
Latexify = "0.14 - 0.15" Latexify = "0.14 - 0.15"

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)))
@ -2038,14 +2041,42 @@ 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
series[:fillcolor]
else
fill(series[:fillcolor], n_polygons)
end
facecolor = map(fc -> set_RGBA_alpha(fillalpha, fc), facecolor)
GR.setborderwidth(get_linewidth(series))
GR.setbordercolorind(gr_getcolorind(get_linecolor(series)))
GR.polygonmesh3d(x, y, z, vcat(cns...), signed.(gr_color.(facecolor)))
else else
throw(ArgumentError("Not handled !")) throw(ArgumentError("Not handled !"))
end end