contourlines now returns Vector{IsoContourLines}
This commit is contained in:
parent
a184b6ee14
commit
e90a63f627
@ -1135,6 +1135,22 @@ mutable struct ContourLine
|
|||||||
ContourLine(z) = new(1, Vector{Float64}(), Vector{Float64}(), z)
|
ContourLine(z) = new(1, Vector{Float64}(), Vector{Float64}(), z)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
mutable struct IsoContourLines
|
||||||
|
lines::Vector{ContourLine}
|
||||||
|
paths::Vector{String}
|
||||||
|
z::Float64
|
||||||
|
function IsoContourLines(lines::Vector{ContourLine})
|
||||||
|
z = unique(getfield.(lines, :z))
|
||||||
|
@assert length(z) == 1
|
||||||
|
paths = Vector{String}()
|
||||||
|
for i in 1:length(lines)
|
||||||
|
append!(paths, data2string(lines[i].x, lines[i].y))
|
||||||
|
push!(paths, "")
|
||||||
|
end
|
||||||
|
return new(lines, paths, z[1])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function contourlines(args...; cntrparam="level auto 10")
|
function contourlines(args...; cntrparam="level auto 10")
|
||||||
tmpfile = Base.Filesystem.tempname()
|
tmpfile = Base.Filesystem.tempname()
|
||||||
sid = Symbol("j", Base.Libc.getpid())
|
sid = Symbol("j", Base.Libc.getpid())
|
||||||
@ -1151,16 +1167,16 @@ function contourlines(args...; cntrparam="level auto 10")
|
|||||||
Gnuplot.exec(sid, "reset")
|
Gnuplot.exec(sid, "reset")
|
||||||
|
|
||||||
cur = ContourLine(NaN)
|
cur = ContourLine(NaN)
|
||||||
out = Vector{ContourLine}()
|
lines = Vector{ContourLine}()
|
||||||
for l in readlines(tmpfile)
|
for l in readlines(tmpfile)
|
||||||
l = strip(l)
|
l = strip(l)
|
||||||
if l == ""
|
if l == ""
|
||||||
(length(cur.x) > 2) && push!(out, cur)
|
(length(cur.x) > 2) && push!(lines, cur)
|
||||||
cur = ContourLine(cur.z)
|
cur = ContourLine(cur.z)
|
||||||
continue
|
continue
|
||||||
end
|
end
|
||||||
if !isnothing(findfirst("# Contour ", l))
|
if !isnothing(findfirst("# Contour ", l))
|
||||||
(length(cur.x) > 2) && push!(out, cur)
|
(length(cur.x) > 2) && push!(lines, cur)
|
||||||
cur = ContourLine(Meta.parse(strip(split(l, ':')[2])))
|
cur = ContourLine(Meta.parse(strip(split(l, ':')[2])))
|
||||||
continue
|
continue
|
||||||
end
|
end
|
||||||
@ -1171,17 +1187,15 @@ function contourlines(args...; cntrparam="level auto 10")
|
|||||||
push!(cur.x, n[1])
|
push!(cur.x, n[1])
|
||||||
push!(cur.y, n[2])
|
push!(cur.y, n[2])
|
||||||
end
|
end
|
||||||
(length(cur.x) > 2) && push!(out, cur)
|
(length(cur.x) > 2) && push!(lines, cur)
|
||||||
rm(tmpfile)
|
rm(tmpfile)
|
||||||
|
@assert length(lines) > 0
|
||||||
|
lines = lines[sortperm(getfield.(lines, :z))]
|
||||||
|
|
||||||
if length(out) > 0
|
out = Vector{IsoContourLines}()
|
||||||
out = out[sortperm(getfield.(out, :z))]
|
for z in unique(getfield.(lines, :z))
|
||||||
for i in 2:length(out)
|
i = findall(getfield.(lines, :z) .== z)
|
||||||
@assert out[i].z >= out[i-1].z
|
push!(out, IsoContourLines(lines[i]))
|
||||||
if out[i].z > out[i-1].z
|
|
||||||
out[i].level = out[i-1].level + 1
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
return out
|
return out
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user