working on glvisualize

This commit is contained in:
Thomas Breloff 2016-06-25 10:56:51 -04:00
parent 69b69714cb
commit 9048053669

View File

@ -31,9 +31,9 @@ supported_args(::GLVisualizeBackend) = merge_with_base_supported([
]) ])
supported_types(::GLVisualizeBackend) = [:surface, :scatter, :scatter3d, :path, :path3d] supported_types(::GLVisualizeBackend) = [:surface, :scatter, :scatter3d, :path, :path3d]
supported_styles(::GLVisualizeBackend) = [:auto, :solid] supported_styles(::GLVisualizeBackend) = [:auto, :solid]
supported_markers(::GLVisualizeBackend) = [:none, :auto, :circle] supported_markers(::GLVisualizeBackend) = vcat([:none, :auto, :circle], keys(_gl_marker_map))
supported_scales(::GLVisualizeBackend) = [:identity] supported_scales(::GLVisualizeBackend) = [:identity]
is_subplot_supported(::GLVisualizeBackend) = false is_subplot_supported(::GLVisualizeBackend) = true
# -------------------------------------------------------------------------------------- # --------------------------------------------------------------------------------------
@ -41,14 +41,14 @@ is_subplot_supported(::GLVisualizeBackend) = false
function _initialize_backend(::GLVisualizeBackend; kw...) function _initialize_backend(::GLVisualizeBackend; kw...)
@eval begin @eval begin
import GLVisualize, GeometryTypes, GLAbstraction, GLWindow import GLVisualize, GeometryTypes, GLAbstraction, GLWindow
import GeometryTypes: Point2f0, Point3f0 import GeometryTypes: Point2f0, Point3f0, Vec2f0, Vec3f0
export GLVisualize export GLVisualize
end end
end end
# --------------------------------------------------------------------------- # ---------------------------------------------------------------------------
# initialize the figure/window
function _create_backend_figure(plt::Plot{GLVisualizeBackend}) function _create_backend_figure(plt::Plot{GLVisualizeBackend})
# init a screen # init a screen
screen = if isdefined(GLVisualize, :ROOT_SCREEN) screen = if isdefined(GLVisualize, :ROOT_SCREEN)
@ -59,36 +59,74 @@ function _create_backend_figure(plt::Plot{GLVisualizeBackend})
s s
end end
empty!(screen) empty!(screen)
screen
end end
# size as a percentage of the window size
function gl_relative_size(plt::Plot{GLVisualizeBackend}, msize::Number) function gl_relative_size(plt::Plot{GLVisualizeBackend}, msize::Number)
winsz = min(plt[:size]...) winsz = min(plt[:size]...)
Float32(msize / winsz) Float32(msize / winsz)
end end
const _gl_marker_map = KW(
:rect => '■',
:star5 => '★',
:diamond => '◆',
:hexagon => '⬢',
:cross => '✚',
:xcross => '❌',
:utriangle => '▲',
:dtriangle => '▼',
:pentagon => '⬟',
:octagon => '⯄',
:star4 => '✦',
:star6 => '✶',
:star8 => '✷',
:vline => '┃',
:hline => '━',
)
# create a marker/shape type
function gl_marker(shape::Symbol, msize::Number, _3d::Bool) function gl_marker(shape::Symbol, msize::Number, _3d::Bool)
GeometryTypes.HyperSphere((_3d ? Point3f0 : Point2f0)(0), msize) GeometryTypes.HyperSphere((_3d ? Point3f0 : Point2f0)(0), msize)
end end
# convert to RGBA
function gl_color(c, a) function gl_color(c, a)
c = convertColor(c, a)[1] c = convertColor(c, a)[1]
@show typeof(c)
RGBA{Float32}(c) RGBA{Float32}(c)
end end
function gl_viewport(bb, rect)
l, b, bw, bh = bb
rw, rh = rect.w, rect.h
GLVisualize.SimpleRectangle(
round(Int, rect.x + rw * l),
round(Int, rect.y + rh * b),
round(Int, rw * bw),
round(Int, rh * bh)
)
end
# draw everything
function gl_display(plt::Plot{GLVisualizeBackend}) function gl_display(plt::Plot{GLVisualizeBackend})
screen = plt.o screen = plt.o
# for sp in plt.subplots sw, sh = plt[:size]
sw, sh = sw*px, sh*px
for (name, sp) in plt.spmap for (name, sp) in plt.spmap
# TODO: setup subplot
f = rect -> gl_viewport(bbox(sp), rect) # initialize the sub-screen for this subplot
sp_screen = Screen( # note: we create a lift function to update the size on resize
rel_bbox = bbox_to_pcts(bbox(sp), sw, sh)
f = rect -> gl_viewport(rel_bbox, rect)
sp_screen = GLVisualize.Screen(
screen, screen,
name = name, name = name,
area = GLVisualize.const_lift(f, screen.area) area = GLVisualize.const_lift(f, screen.area)
) )
# loop over the series and add them to the subplot
for series in series_list(sp) for series in series_list(sp)
d = series.d d = series.d
st = d[:seriestype] st = d[:seriestype]
@ -103,19 +141,37 @@ function gl_display(plt::Plot{GLVisualizeBackend})
GLVisualize.view(viz, sp_screen, camera = :perspective) GLVisualize.view(viz, sp_screen, camera = :perspective)
else else
points = if is3d(st) _3d = is3d(st)
points = if _3d
z = map(Float32, d[:z]) z = map(Float32, d[:z])
Point3f0[Point3f0(xi,yi,zi) for (xi,yi,zi) in zip(x, y, z)] Point3f0[Point3f0(xi,yi,zi) for (xi,yi,zi) in zip(x, y, z)]
else else
Point2f0[Point2f0(xi,yi) for (xi,yi) in zip(x, y)] Point2f0[Point2f0(xi,yi) for (xi,yi) in zip(x, y)]
end end
camera = is3d(st) ? :perspective : :orthographic_pixel camera = _3d ? :perspective : :orthographic_pixel
# markers? # markers?
if st in (:scatter, :scatter3d) || d[:markershape] != :none if st in (:scatter, :scatter3d) || d[:markershape] != :none
marker = gl_marker(d[:markershape], msize, is3d(st)) extrakw = KW()
viz = GLVisualize.visualize((marker, points), color = gl_color(d[:markercolor], d[:markeralpha])) c = gl_color(d[:markercolor], d[:markeralpha])
# get the marker
shape = d[:markershape]
shape = get(_gl_marker_map, shape, shape)
marker = if isa(shape, Char)
# extrakw[:scale] = Vec2f0(_3d ? 0.6*d[:markersize] : msize)
extrakw[:scale] = Vec2f0(msize)
shape
else
gl_marker(d[:markershape], msize, _3d)
end
viz = GLVisualize.visualize(
(marker, points);
color = c,
extrakw...
)
GLVisualize.view(viz, sp_screen, camera = camera) GLVisualize.view(viz, sp_screen, camera = camera)
# TODO: might need to switch to these forms later? # TODO: might need to switch to these forms later?
@ -128,13 +184,18 @@ function gl_display(plt::Plot{GLVisualizeBackend})
# paths # paths
lw = d[:linewidth] lw = d[:linewidth]
if !(st in (:scatter, :scatter3d)) && lw > 0 if !(st in (:scatter, :scatter3d)) && lw > 0
viz = GLVisualize.visualize(points, :lines) #, color=colors, model=rotation) c = gl_color(d[:linecolor], d[:linealpha])
viz = GLVisualize.visualize(
points,
:lines,
color = c,
thickness = Float32(lw)
)
GLVisualize.view(viz, sp_screen, camera = camera) GLVisualize.view(viz, sp_screen, camera = camera)
end end
end end
end end
end end
# GLAbstraction.center!(screen)
# TODO: render one frame at a time? (no renderloop) # TODO: render one frame at a time? (no renderloop)
# GLWindow.render_frame(screen) # GLWindow.render_frame(screen)
@ -151,6 +212,5 @@ end
# # TODO: write a png to io # # TODO: write a png to io
# end # end
# function _display(plt::Plot{GLVisualizeBackend}) function _display(plt::Plot{GLVisualizeBackend})
# gl_display(plt) end
# end