Skip to content

Commit

Permalink
minor clean ups
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonDanisch committed Aug 16, 2016
1 parent 33f2f3e commit c6aa437
Showing 1 changed file with 17 additions and 33 deletions.
50 changes: 17 additions & 33 deletions src/backends/glvisualize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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()
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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])
Expand All @@ -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])
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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",
Expand All @@ -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]
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c6aa437

Please sign in to comment.