From 81170b434273e844922f9e43c275d01f8a22f195 Mon Sep 17 00:00:00 2001 From: t-bltg Date: Mon, 5 Jul 2021 02:15:51 +0200 Subject: [PATCH] GR: add support for mesh3d --- src/backends.jl | 1 + src/backends/gr.jl | 38 +++++++++++++++++++++++++++++++++++--- src/examples.jl | 2 +- 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/src/backends.jl b/src/backends.jl index 85ebfe98a..1387ae184 100644 --- a/src/backends.jl +++ b/src/backends.jl @@ -352,6 +352,7 @@ const _gr_seriestype = [ :scatter3d, :surface, :wireframe, + :mesh3d, :volume, :shape, ] diff --git a/src/backends/gr.jl b/src/backends/gr.jl index 41b98e968..74f11e663 100644 --- a/src/backends/gr.jl +++ b/src/backends/gr.jl @@ -1676,7 +1676,7 @@ function gr_add_series(sp, series) end elseif st === :contour gr_draw_contour(series, x, y, z, clims) - elseif st in (:surface, :wireframe) + elseif st in (:surface, :wireframe, :mesh3d) gr_draw_surface(series, x, y, z, clims) elseif st === :volume sp[:legend] = :none @@ -1843,7 +1843,8 @@ end function gr_draw_surface(series, x, y, z, clims) e_kwargs = series[:extra_kwargs] - if series[:seriestype] === :surface + st = series[:seriestype] + if st === :surface fillalpha = get_fillalpha(series) fillcolor = get_fillcolor(series) # NOTE: setting nx = 0 or ny = 0 disables GR.gridit interpolation @@ -1858,9 +1859,40 @@ function gr_draw_surface(series, x, y, z, clims) else GR.gr3.surface(x, y, z, d_opt) end - else # wireframe + elseif st === :wireframe GR.setfillcolorind(0) GR.surface(x, y, z, get(e_kwargs, :display_option, GR.OPTION_FILLED_MESH)) + elseif st === :mesh3d + conn = series[:connections] + if typeof(conn) <: Tuple{Array, Array, Array} + ci, cj, ck = conn + if !(length(ci) == length(cj) == length(ck)) + throw(ArgumentError("Argument connections must consist of equally sized arrays.")) + end + else + throw(ArgumentError("Argument connections has to be a tuple of three arrays.")) + end + xx = zeros(eltype(x), 4length(ci)) + yy = zeros(eltype(y), 4length(cj)) + zz = zeros(eltype(z), 4length(ck)) + @inbounds for I ∈ 1:length(ci) + i = ci[I] + 1 # connections are 0-based + j = cj[I] + 1 + k = ck[I] + 1 + m = 4(I - 1) + 1; n = m + 1; o = m + 2; p = m + 3 + xx[m] = xx[p] = x[i] + yy[m] = yy[p] = y[i] + zz[m] = zz[p] = z[i] + xx[n] = x[j] + yy[n] = y[j] + zz[n] = z[j] + xx[o] = x[k] + yy[o] = y[k] + zz[o] = z[k] + end + GR.polyline3d(xx, yy, zz) + else + throw(ArgumentError("Not handled !")) end end diff --git a/src/examples.jl b/src/examples.jl index eb99e5fe3..dd4eb8c46 100644 --- a/src/examples.jl +++ b/src/examples.jl @@ -1214,7 +1214,7 @@ const _examples = PlotExample[ # Some constants for PlotDocs and PlotReferenceImages _animation_examples = [2, 31] _backend_skips = Dict( - :gr => [25, 30, 47], + :gr => [25, 30], :pyplot => [2, 25, 30, 31, 47, 49, 55], :plotlyjs => [2, 21, 24, 25, 30, 31, 49, 51, 55], :plotly => [2, 21, 24, 25, 30, 31, 49, 50, 51, 55],