string fix; iter_segments change to use unused and skip initial NaNs; working on glvisualize shape type
This commit is contained in:
parent
9193941fd0
commit
521e753183
@ -29,7 +29,7 @@ supported_args(::GLVisualizeBackend) = merge_with_base_supported([
|
|||||||
# :clims,
|
# :clims,
|
||||||
# :inset_subplots,
|
# :inset_subplots,
|
||||||
])
|
])
|
||||||
supported_types(::GLVisualizeBackend) = [:surface, :scatter, :scatter3d, :path, :path3d]
|
supported_types(::GLVisualizeBackend) = [:surface, :scatter, :scatter3d, :path, :path3d, :shape]
|
||||||
supported_styles(::GLVisualizeBackend) = [:auto, :solid]
|
supported_styles(::GLVisualizeBackend) = [:auto, :solid]
|
||||||
supported_markers(::GLVisualizeBackend) = vcat([:none, :auto, :circle], collect(keys(_gl_marker_map)))
|
supported_markers(::GLVisualizeBackend) = vcat([:none, :auto, :circle], collect(keys(_gl_marker_map)))
|
||||||
supported_scales(::GLVisualizeBackend) = [:identity]
|
supported_scales(::GLVisualizeBackend) = [:identity]
|
||||||
@ -101,8 +101,10 @@ gl_color(c::RGBA{Float32}) = c
|
|||||||
|
|
||||||
# convert to RGBA
|
# convert to RGBA
|
||||||
function gl_color(c, a=nothing)
|
function gl_color(c, a=nothing)
|
||||||
|
@show c, a
|
||||||
c = convertColor(c, a)
|
c = convertColor(c, a)
|
||||||
RGBA{Float32}(getColor(c))
|
@show c
|
||||||
|
RGBA{Float32}(c)
|
||||||
end
|
end
|
||||||
|
|
||||||
function gl_viewport(bb, rect)
|
function gl_viewport(bb, rect)
|
||||||
@ -125,11 +127,13 @@ function gl_draw_lines_2d(x, y, color, linewidth, sp_screen)
|
|||||||
for rng in iter_segments(x, y)
|
for rng in iter_segments(x, y)
|
||||||
n = length(rng)
|
n = length(rng)
|
||||||
n < 2 && continue
|
n < 2 && continue
|
||||||
|
pts = gl_make_points(x[rng], y[rng])
|
||||||
|
@show pts, n
|
||||||
viz = GLVisualize.visualize(
|
viz = GLVisualize.visualize(
|
||||||
gl_make_points(x[rng], y[rng]),
|
pts,
|
||||||
n==2 ? :linesegment : :lines,
|
n==2 ? :linesegment : :lines,
|
||||||
color=color,
|
color = color,
|
||||||
thickness = Float32(linewidth)
|
thickness = thickness
|
||||||
)
|
)
|
||||||
GLVisualize.view(viz, sp_screen, camera=:orthographic_pixel)
|
GLVisualize.view(viz, sp_screen, camera=:orthographic_pixel)
|
||||||
end
|
end
|
||||||
@ -141,11 +145,12 @@ function gl_draw_lines_3d(x, y, z, color, linewidth, sp_screen)
|
|||||||
for rng in iter_segments(x, y, z)
|
for rng in iter_segments(x, y, z)
|
||||||
n = length(rng)
|
n = length(rng)
|
||||||
n < 2 && continue
|
n < 2 && continue
|
||||||
|
pts = gl_make_points(x[rng], y[rng], z[rng])
|
||||||
viz = GLVisualize.visualize(
|
viz = GLVisualize.visualize(
|
||||||
gl_make_points(x[rng], y[rng], z[rng]),
|
pts,
|
||||||
n==2 ? :linesegment : :lines,
|
n==2 ? :linesegment : :lines,
|
||||||
color=color,
|
color=color,
|
||||||
thickness = Float32(linewidth)
|
thickness = thickness
|
||||||
)
|
)
|
||||||
GLVisualize.view(viz, sp_screen, camera=:perspective)
|
GLVisualize.view(viz, sp_screen, camera=:perspective)
|
||||||
end
|
end
|
||||||
@ -206,7 +211,7 @@ function gl_display(plt::Plot{GLVisualizeBackend})
|
|||||||
|
|
||||||
sp.o = sp_screen
|
sp.o = sp_screen
|
||||||
if !is3d(sp)
|
if !is3d(sp)
|
||||||
gl_draw_axes_2d(sp)
|
# gl_draw_axes_2d(sp)
|
||||||
end
|
end
|
||||||
|
|
||||||
# loop over the series and add them to the subplot
|
# loop over the series and add them to the subplot
|
||||||
@ -216,16 +221,16 @@ function gl_display(plt::Plot{GLVisualizeBackend})
|
|||||||
x, y = map(Float32, d[:x]), map(Float32, d[:y])
|
x, y = map(Float32, d[:x]), map(Float32, d[:y])
|
||||||
msize = gl_relative_size(plt, d[:markersize])
|
msize = gl_relative_size(plt, d[:markersize])
|
||||||
|
|
||||||
viz = if st == :surface
|
if st == :surface
|
||||||
# TODO: can pass just the ranges and surface
|
# TODO: can pass just the ranges and surface
|
||||||
ismatrix(x) || (x = repmat(x', length(y), 1))
|
ismatrix(x) || (x = repmat(x', length(y), 1))
|
||||||
ismatrix(y) || (y = repmat(y, 1, length(x)))
|
ismatrix(y) || (y = repmat(y, 1, length(x)))
|
||||||
z = transpose_z(d, map(Float32, d[:z].surf), false)
|
z = transpose_z(d, map(Float32, d[:z].surf), false)
|
||||||
viz = GLVisualize.visualize((x, y, z), :surface)
|
viz = GLVisualize.visualize((x, y, z), :surface)
|
||||||
GLVisualize.view(viz, sp_screen, camera = :perspective)
|
GLVisualize.view(viz, sp_screen, camera = camera)
|
||||||
|
|
||||||
else
|
else
|
||||||
# paths and scatters
|
# paths, scatters, and shape
|
||||||
|
|
||||||
_3d && (z = map(Float32, d[:z]))
|
_3d && (z = map(Float32, d[:z]))
|
||||||
|
|
||||||
@ -274,6 +279,22 @@ function gl_display(plt::Plot{GLVisualizeBackend})
|
|||||||
# billboard=true
|
# billboard=true
|
||||||
#))
|
#))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if st == :shape
|
||||||
|
for rng in iter_segments(x, y)
|
||||||
|
pts = Point2f0[Point2f0(x[i], y[i]) for i in rng]
|
||||||
|
@show pts
|
||||||
|
mesh = GeometryTypes.GLNormalMesh(pts)
|
||||||
|
@show mesh
|
||||||
|
if !isempty(GeometryTypes.faces(mesh))
|
||||||
|
viz = GLVisualize.visualize(
|
||||||
|
mesh,
|
||||||
|
color = gl_color(d[:fillcolor], d[:fillalpha])
|
||||||
|
)
|
||||||
|
GLVisualize.view(viz, sp_screen, camera = camera)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
GLAbstraction.center!(sp_screen, camera)
|
GLAbstraction.center!(sp_screen, camera)
|
||||||
|
|||||||
@ -32,6 +32,7 @@ getColor(scheme::ColorScheme) = getColor(scheme, 1)
|
|||||||
getColorVector(scheme::ColorScheme) = [getColor(scheme)]
|
getColorVector(scheme::ColorScheme) = [getColor(scheme)]
|
||||||
|
|
||||||
colorscheme(scheme::ColorScheme) = scheme
|
colorscheme(scheme::ColorScheme) = scheme
|
||||||
|
colorscheme(s::AbstractString; kw...) = colorscheme(Symbol(s); kw...)
|
||||||
colorscheme(s::Symbol; kw...) = haskey(_gradients, s) ? ColorGradient(s; kw...) : ColorWrapper(convertColor(s); kw...)
|
colorscheme(s::Symbol; kw...) = haskey(_gradients, s) ? ColorGradient(s; kw...) : ColorWrapper(convertColor(s); kw...)
|
||||||
colorscheme{T<:Real}(s::Symbol, vals::AVec{T}; kw...) = ColorGradient(s, vals; kw...)
|
colorscheme{T<:Real}(s::Symbol, vals::AVec{T}; kw...) = ColorGradient(s, vals; kw...)
|
||||||
colorscheme(cs::AVec, vs::AVec; kw...) = ColorGradient(cs, vs; kw...)
|
colorscheme(cs::AVec, vs::AVec; kw...) = ColorGradient(cs, vs; kw...)
|
||||||
@ -55,10 +56,10 @@ convertColor(b::Bool) = b ? RGBA(0,0,0,1) : RGBA(0,0,0,0)
|
|||||||
|
|
||||||
function convertColor(c, α::Real)
|
function convertColor(c, α::Real)
|
||||||
c = convertColor(c)
|
c = convertColor(c)
|
||||||
RGBA(RGB(c), α)
|
RGBA(RGB(getColor(c)), α)
|
||||||
end
|
end
|
||||||
convertColor(cs::AVec, α::Real) = map(c -> convertColor(c, α), cs)
|
convertColor(cs::AVec, α::Real) = map(c -> convertColor(c, α), cs)
|
||||||
convertColor(c, α::@compat(Void)) = convertColor(c)
|
convertColor(c, α::Void) = convertColor(c)
|
||||||
|
|
||||||
# backup... try to convert
|
# backup... try to convert
|
||||||
getColor(c) = convertColor(c)
|
getColor(c) = convertColor(c)
|
||||||
@ -220,7 +221,7 @@ immutable ColorZFunction <: ColorScheme
|
|||||||
f::Function
|
f::Function
|
||||||
end
|
end
|
||||||
|
|
||||||
getColorZ(scheme::ColorFunction, z::Real) = scheme.f(z)
|
getColorZ(scheme::ColorZFunction, z::Real) = scheme.f(z)
|
||||||
|
|
||||||
# --------------------------------------------------------------
|
# --------------------------------------------------------------
|
||||||
|
|
||||||
@ -246,6 +247,7 @@ ColorWrapper(s::Symbol; alpha = nothing) = ColorWrapper(convertColor(parse(Color
|
|||||||
|
|
||||||
getColor(scheme::ColorWrapper, idx::Int) = scheme.c
|
getColor(scheme::ColorWrapper, idx::Int) = scheme.c
|
||||||
getColorZ(scheme::ColorWrapper, z::Real) = scheme.c
|
getColorZ(scheme::ColorWrapper, z::Real) = scheme.c
|
||||||
|
convertColor(c::ColorWrapper, α::Void) = c.c
|
||||||
|
|
||||||
# --------------------------------------------------------------
|
# --------------------------------------------------------------
|
||||||
|
|
||||||
|
|||||||
23
src/utils.jl
23
src/utils.jl
@ -166,13 +166,13 @@ end
|
|||||||
|
|
||||||
type SegmentsIterator
|
type SegmentsIterator
|
||||||
args::Tuple
|
args::Tuple
|
||||||
nextidx::Int
|
# nextidx::Int
|
||||||
n::Int
|
n::Int
|
||||||
end
|
end
|
||||||
function iter_segments(args...)
|
function iter_segments(args...)
|
||||||
tup = Plots.wraptuple(args)
|
tup = Plots.wraptuple(args)
|
||||||
n = maximum(map(length, tup))
|
n = maximum(map(length, tup))
|
||||||
SegmentsIterator(tup, 0, n)
|
SegmentsIterator(tup, n)
|
||||||
end
|
end
|
||||||
|
|
||||||
# helpers to figure out if there are NaN values in a list of array types
|
# helpers to figure out if there are NaN values in a list of array types
|
||||||
@ -180,10 +180,16 @@ anynan(i::Int, args...) = any(a -> !isfinite(cycle(a,i)), args)
|
|||||||
anynan(istart::Int, iend::Int, args...) = any(i -> anynan(i, args...), istart:iend)
|
anynan(istart::Int, iend::Int, args...) = any(i -> anynan(i, args...), istart:iend)
|
||||||
allnan(istart::Int, iend::Int, args...) = all(i -> anynan(i, args...), istart:iend)
|
allnan(istart::Int, iend::Int, args...) = all(i -> anynan(i, args...), istart:iend)
|
||||||
|
|
||||||
Base.start(itr::SegmentsIterator) = (itr.nextidx = 1) #resets
|
function Base.start(itr::SegmentsIterator)
|
||||||
Base.done(itr::SegmentsIterator, unused::Int) = itr.nextidx > itr.n
|
nextidx = 1
|
||||||
function Base.next(itr::SegmentsIterator, unused::Int)
|
if anynan(1, itr.args...)
|
||||||
i = istart = iend = itr.nextidx
|
_, nextidx = next(itr, 1)
|
||||||
|
end
|
||||||
|
nextidx
|
||||||
|
end
|
||||||
|
Base.done(itr::SegmentsIterator, nextidx::Int) = nextidx > itr.n
|
||||||
|
function Base.next(itr::SegmentsIterator, nextidx::Int)
|
||||||
|
i = istart = iend = nextidx
|
||||||
|
|
||||||
# find the next NaN, and iend is the one before
|
# find the next NaN, and iend is the one before
|
||||||
while i <= itr.n + 1
|
while i <= itr.n + 1
|
||||||
@ -195,7 +201,7 @@ function Base.next(itr::SegmentsIterator, unused::Int)
|
|||||||
i += 1
|
i += 1
|
||||||
end
|
end
|
||||||
|
|
||||||
# find the next non-NaN, and set itr.nextidx
|
# find the next non-NaN, and set nextidx
|
||||||
while i <= itr.n
|
while i <= itr.n
|
||||||
if !anynan(i, itr.args...)
|
if !anynan(i, itr.args...)
|
||||||
break
|
break
|
||||||
@ -203,8 +209,7 @@ function Base.next(itr::SegmentsIterator, unused::Int)
|
|||||||
i += 1
|
i += 1
|
||||||
end
|
end
|
||||||
|
|
||||||
itr.nextidx = i
|
istart:iend, i
|
||||||
istart:iend, 0
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# ------------------------------------------------------------------------------------
|
# ------------------------------------------------------------------------------------
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user