Skip to content

Commit

Permalink
restore mutating versions
Browse files Browse the repository at this point in the history
  • Loading branch information
t-bltg committed Feb 7, 2022
1 parent ea3081d commit 5bb1ab4
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/interface/contourplot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ julia> contourplot(-1:.1:1, -1:.1:1, (x, y) -> √(x^2 + y^2))
# See also
`Plot`, `scatterplot`
[`Plot`](@ref), [`scatterplot`](@ref)
"""
function contourplot(
x::AbstractVector,
Expand Down
28 changes: 27 additions & 1 deletion src/interface/isosurface.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ julia> isosurface(-1:.1:1, -1:.1:1, -1:.1:1, torus, elevation = 50, zoom = 2)
# See also
`Plot`, `scatterplot`
[`Plot`](@ref), [`scatterplot`](@ref)
"""
function isosurface(
x::AbstractVector,
Expand All @@ -77,7 +77,33 @@ function isosurface(
projection = projection,
kw...,
)
isosurface!(
plot,
x,
y,
z,
V;
color = color,
isovalue = isovalue,
centroid = centroid,
legacy = legacy,
cull = cull,
)
end

function isosurface!(
plot::Plot{<:Canvas},
x::AbstractVector,
y::AbstractVector,
z::AbstractVector,
V::AbstractArray;
color::UserColorType = KEYWORDS.color,
name::AbstractString = KEYWORDS.name,
isovalue::Number = 0,
centroid::Bool = true,
legacy::Bool = false,
cull::Bool = false,
)
color = color == :auto ? next_color!(plot) : color

mc = MarchingCubes.MC(V, Int; x = collect(x), y = collect(y), z = collect(z))
Expand Down
46 changes: 32 additions & 14 deletions src/interface/surfaceplot.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,15 @@ julia> surfaceplot(-8:.5:8, -8:.5:8, sombrero)
# See also
`Plot`, `scatterplot`
[`Plot`](@ref), [`scatterplot`](@ref)
"""
function surfaceplot(
x::AbstractVecOrMat,
y::AbstractVecOrMat,
A::Union{Function,AbstractVecOrMat};
canvas::Type = BrailleCanvas,
name::AbstractString = KEYWORDS.name,
color::UserColorType = nothing, # NOTE: nothing as default to override colormap
color::UserColorType = nothing, # NOTE: nothing as default (uses colormap), but allow single color
colormap = KEYWORDS.colormap,
colorbar::Bool = true,
projection::Union{MVP,Symbol} = KEYWORDS.projection,
Expand Down Expand Up @@ -96,26 +96,44 @@ function surfaceplot(
length(X) == length(Y) == length(Z) == length(H) ||
throw(DimensionMismatch("X, Y, Z and H must have same length"))

callback = colormap_callback(colormap)
plot = Plot(
[mx, Mx],
[my, My],
[mz, Mz],
canvas;
projection = projection,
colormap = callback,
colorbar = colorbar && color === nothing,
colorbar_lim = (mh, Mh),
kw...,
plot = Plot([mx, Mx], [my, My], [mz, Mz], canvas; projection = projection, kw...)
surfaceplot!(
plot,
X,
Y,
Z,
H;
name = name,
color = color,
colormap = colormap,
colorbar = colorbar,
lines = lines,
)
end

function surfaceplot!(
plot::Plot{<:Canvas},
X::AbstractVecOrMat,
Y::AbstractVecOrMat,
Z::AbstractVecOrMat,
H::AbstractVecOrMat;
name::AbstractString = KEYWORDS.name,
color::UserColorType = nothing,
colormap = KEYWORDS.colormap,
colorbar::Bool = true,
lines::Bool = false,
)
plot.colorbar_lim = mh, Mh = NaNMath.extrema(as_float(H))
plot.colormap = callback = colormap_callback(colormap)
plot.colorbar = colorbar && color === nothing

if color === nothing
color =
UserColorType[isfinite(h) ? callback(h, mh, Mh) : nothing for h in @view(H[:])]
end

callable = lines ? lineplot! : scatterplot!
callable(plot, @view(X[:]), @view(Y[:]), @view(Z[:]); color = color, name = name)
plot
end

"""
Expand Down
8 changes: 4 additions & 4 deletions src/volume.jl
Original file line number Diff line number Diff line change
Expand Up @@ -271,14 +271,14 @@ struct MVP{T}
end
end

get_tr_mat(t::MVP, n::Symbol) =
MVP_matrix(t::MVP, n::Symbol) =
(user = t.mvp_mat, orthographic = t.mvp_ortho_mat, perspective = t.mvp_persp_mat)[n]

is_ortho(t::MVP, n::Symbol) = (user = t.ortho, orthographic = true, perspective = false)[n]

function (t::MVP{T})(p::AbstractMatrix, n::Symbol = :user) where {T}
# homogeneous coordinates
dat = get_tr_mat(t, n) * (size(p, 1) == 4 ? p : vcat(p, ones(1, size(p, 2))))
dat = MVP_matrix(t, n) * (size(p, 1) == 4 ? p : vcat(p, ones(1, size(p, 2))))
xs, ys, zs, ws = dat[1, :], dat[2, :], dat[3, :], dat[4, :]
@inbounds for (i, w) in enumerate(ws)
if abs(w) > eps(T)
Expand All @@ -292,7 +292,7 @@ end

function (t::MVP{T})(v::Union{AbstractVector,NTuple{3}}, n::Symbol = :user) where {T}
# homogeneous coordinates
x, y, z, w = get_tr_mat(t, n) * [v..., 1]
x, y, z, w = MVP_matrix(t, n) * [v..., 1]
if abs(w) > eps(T)
x /= w
y /= w
Expand All @@ -317,7 +317,7 @@ function draw_axes!(plot, p = [0, 0, 0], len = nothing, scale = 0.25)
proj = :orthographic # force axes projection

pos = if length(p) == 2
(get_tr_mat(T, proj) \ vcat(p, 0, 1))[1:3]
(MVP_matrix(T, proj) \ vcat(p, 0, 1))[1:3]
else
p
end
Expand Down

0 comments on commit 5bb1ab4

Please sign in to comment.