From c6aa437eab3e1c91fba9cab59e6ce74b0f1e3765 Mon Sep 17 00:00:00 2001 From: Simon Danisch Date: Tue, 16 Aug 2016 16:31:40 +0200 Subject: [PATCH] minor clean ups --- src/backends/glvisualize.jl | 50 +++++++++++++------------------------ 1 file changed, 17 insertions(+), 33 deletions(-) diff --git a/src/backends/glvisualize.jl b/src/backends/glvisualize.jl index e17946ccf6..f68a0371d2 100644 --- a/src/backends/glvisualize.jl +++ b/src/backends/glvisualize.jl @@ -56,16 +56,13 @@ is_subplot_supported(::GLVisualizeBackend) = true function _initialize_backend(::GLVisualizeBackend; kw...) @eval begin - import GLVisualize, GeometryTypes, Reactive, GLAbstraction, GLWindow, Contour + import GLVisualize, GeometryTypes, Reactive, GLAbstraction, GLWindow#, Contour import GeometryTypes: Point2f0, Point3f0, Vec2f0, Vec3f0, GLNormalMesh import FileIO, Images export GLVisualize import Reactive: Signal import GLAbstraction: Style import GLVisualize: visualize - - # # TODO: remove this when PlotUtils is registered - # import PlotUtils end end @@ -84,18 +81,19 @@ function _create_backend_figure(plt::Plot{GLVisualizeBackend}) Reactive.stop() @async begin while isopen(s) - tic() - if Base.n_avail(Reactive._messages) > 0 + # tic() + #if Base.n_avail(Reactive._messages) > 0 GLWindow.render_frame(s) GLWindow.swapbuffers(s) - Reactive.run_till_now() - end - GLWindow.pollevents() + #end yield() - diff = (1/60) - toq() - if diff > 0.0 - sleep(diff) - end + GLWindow.pollevents() + Reactive.run_till_now() + Reactive.run_till_now() + # diff = (1/60) - toq() + # if diff > 0.0 + # sleep(diff) + # end end GLWindow.destroy!(s) GLVisualize.cleanup_old_screens() @@ -155,11 +153,7 @@ function extract_marker(d, kw_args) kw_args[:color] = nothing dim = Plots.is3d(d) ? 3 : 2 if haskey(d, :markersize) - msize = if dim == 3 # sadly, 3D has a different unit system - Float32(d[:markersize]) - else - d[:markersize]*2f0 - end + msize = d[:markersize] if isa(msize, AbstractArray) kw_args[:scale] = map(GeometryTypes.Vec{dim, Float32}, msize) else @@ -180,10 +174,11 @@ function extract_marker(d, kw_args) kw_args[:stroke_color] = scalar_color(d, :markerstroke) kw_args[:stroke_width] = Float32(d[:markerstrokewidth]) end - #extract_any_color(d, kw_args) if haskey(d, :markercolor) kw_args[:color] = scalar_color(d, :marker) end + extract_any_color(d, kw_args) + end function _extract_surface(d::Plots.Surface) @@ -213,7 +208,6 @@ end make_gradient(c) = make_gradient(cgrad()) function extract_any_color(d, kw_args) - kw_args[:color] = nothing if d[:marker_z] == nothing c = scalar_color(d, :fill) if isa(c, Colorant) @@ -231,6 +225,7 @@ function extract_any_color(d, kw_args) end end else + kw_args[:color] = nothing clims = d[:subplot][:clims] if Plots.is_2tuple(clims) if isfinite(clims[1]) && isfinite(clims[2]) @@ -256,7 +251,6 @@ function extract_color_grad(d, kw_args) kw_args[:color] = nothing if d[:marker_z] == nothing c = scalar_color(d, :marker) - @show typeof(c) kw_args[:color_map] = make_gradient(c) else kw_args[:intensity] = convert(Vector{Float32}, d[:marker_z]) @@ -482,7 +476,6 @@ function gl_bar(d, kw_args) positions, scales = scales, positions end kw_args[:scale] = scales - kw_args[:offset] = Vec2f0(0) visualize((GLVisualize.RECTANGLE, positions), Style(:default), kw_args) end @@ -608,7 +601,6 @@ function _display(plt::Plot{GLVisualizeBackend}) sw, sh = plt[:size] sw, sh = sw*px, sh*px for (name, sp) in plt.spmap - println("jojoj subplot in da house! $name") _3d = Plots.is3d(sp) camera = _3d ? :perspective : :orthographic_pixel # camera = :perspective @@ -643,7 +635,6 @@ function _display(plt::Plot{GLVisualizeBackend}) kw_args[:model] = model_m # add transformation kw_args[:boundingbox] = nothing # don't calculate bb, we dont need it end - @show st if st == :surface || st == :wireframe x, y, z = extract_surface(d) extract_color_grad(d, kw_args) @@ -653,8 +644,6 @@ function _display(plt::Plot{GLVisualizeBackend}) kw_args[:wireframe] = true kw_args[:stroke_color] = d[:linecolor] kw_args[:stroke_width] = Float32(d[:linewidth] / minimum(diff(x))) / 100f0 - @show kw_args[:stroke_width] - @show kw_args[:stroke_color] end vis = GL.surface(x, y, z, kw_args) elseif (st == :path || st == :path3d) && d[:linewidth] > 0 @@ -723,7 +712,6 @@ function _show(io::IO, ::MIME"image/png", plt::Plot{GLVisualizeBackend}) _display(plt) GLWindow.render_frame(plt.o) GLWindow.swapbuffers(plt.o) - yield(); buff = GLWindow.screenbuffer(plt.o) png = Images.Image(buff, colorspace = "sRGB", @@ -732,10 +720,6 @@ function _show(io::IO, ::MIME"image/png", plt::Plot{GLVisualizeBackend}) FileIO.save(FileIO.Stream(FileIO.DataFormat{:PNG}, io), png) end -# function _display(plt::Plot{GLVisualizeBackend}) -# end - - function image(img, kw_args) rect = kw_args[:primitive] @@ -800,12 +784,12 @@ end function poly(points, kw_args) - push!(points, Point2f0(last(points)[1], 0), Point2f0(0)) # fill shape + push!(points, Point2f0(last(points)[1], 0), Point2f0(first(points)[1], 0)) # fill shape mesh = GLNormalMesh(points) # make polygon if !isempty(GeometryTypes.faces(mesh)) # check if polygonation has any faces return GLVisualize.visualize(mesh, Style(:default), kw_args) else - warn("Couldn't draw da polygonz") + warn("Couldn't draw the polygon: $points") end [] end