Skip to content
This repository has been archived by the owner on Apr 28, 2021. It is now read-only.

Commit

Permalink
use Signal instead of Input. See JuliaGizmos/Reactive.jl#65
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonDanisch committed Nov 15, 2015
1 parent 18d281a commit bbbab0c
Show file tree
Hide file tree
Showing 31 changed files with 154 additions and 82 deletions.
2 changes: 1 addition & 1 deletion examples/image_processing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ vec2i(vec::Vec) = vec2i(vec...)
function screen(robj, w)
bb = boundingbox(robj).value
m = vec2i(bb.minimum)
area = Input(Rectangle{Int}(0,0, ((vec2i(bb.maximum)-m)+30)...))
area = Signal(Rectangle{Int}(0,0, ((vec2i(bb.maximum)-m)+30)...))
view(visualize(area, style=Cint(OUTLINED)), method=:fixed_pixel)
robj[:model] = translationmatrix(Vec3f0(15,15,0)-bb.minimum)
view(robj, method=:fixed_pixel)
Expand Down
47 changes: 37 additions & 10 deletions examples/juliaset.jl
Original file line number Diff line number Diff line change
@@ -1,21 +1,48 @@
meshgrid(v::AbstractVector) = meshgrid(v, v)

function meshgrid{T}(vx::AbstractVector{T}, vy::AbstractVector{T})
m, n = length(vy), length(vx)
vx = reshape(vx, 1, n)
vy = reshape(vy, m, 1)
(repmat(vx, m, 1), repmat(vy, 1, n))
end

function meshgrid{T}(vx::AbstractVector{T}, vy::AbstractVector{T},
vz::AbstractVector{T})
m, n, o = length(vy), length(vx), length(vz)
vx = reshape(vx, 1, n, 1)
vy = reshape(vy, m, 1, 1)
vz = reshape(vz, 1, 1, o)
om = ones(Int, m)
on = ones(Int, n)
oo = ones(Int, o)
(vx[om, :, oo], vy[:, on, oo], vz[om, on, :])
end

# Calculate the Julia set on a grid
x = [Float32(i)*im for i=-1.5:0.5:500]
y = [Float32(i)*im for i=-1:1:500]
x,y = meshgrid(-1.5f0:0.5f0:500f0, -1f0:1f0:500f0)
x *= 1im
y *= 1im
println(size(x))
println(size(y))
z = x + 1im * y

julia = zeros(Float32, size(z))
const julia = zeros(Float32, size(z))

for i=1:50
z = z^2 - 0.70176 - 0.3842im
julia += 1 / 2f0 + i) * (z * conj(z) > 4)
for i in eachindex(julia)
z[i] = (z[i]^2) - 0.70176 - 0.3842im
x = (z[i] * (real(conj(z[i])) > 4))
julia[i] += real(1f0 / (2f0 + i) * x)
end
end

maxval = maximum(julia)
map!(julia ) do val
val / maxval
end
using GLVisualize
w,r =glscreen()
# Display it
view(visualize(julia))

# A view into the "Canyon"
view(65, 27, 322, [30., -13.7, 136])
show()

r()
2 changes: 1 addition & 1 deletion examples/mario.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const mario_images = Dict()
play{T}(array::Array{T, 3}, slice) = array[:, :, slice]


signify{T}(x::Array{T, 2}) = Input(x)
signify{T}(x::Array{T, 2}) = Signal(x)
function signify{T}(x::Array{T, 3})
const_lift(play, x, loop(1:size(x, 3)))
end
Expand Down
14 changes: 7 additions & 7 deletions examples/tests/minimal_test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ function visualize_default(grid::Union{Texture{Float32, 2}, Matrix{Float32}})
:grid_max => grid_max,
:scale => scale,
:norm => Vec2f0(0, 5),
:model => Input(eye(Mat4f0)),
:light => Input(Vec3f0[Vec3f0(1.0,1.0,1.0), Vec3f0(0.1,0.1,0.1), Vec3f0(0.9,0.9,0.9), Vec3f0(20,20,20)]),
:model => Signal(eye(Mat4f0)),
:light => Signal(Vec3f0[Vec3f0(1.0,1.0,1.0), Vec3f0(0.1,0.1,0.1), Vec3f0(0.9,0.9,0.9), Vec3f0(20,20,20)]),
:preferred_camera => :perspective
)
end
Expand All @@ -207,9 +207,9 @@ function visualize(grid::Texture{Float32, 2}, customizations=visualize_default(g
frag_shader
)
checkerror()
boundingbox = Input(AABB(Vec3f0(0), Vec3f0(1)))
boundingbox = Signal(AABB(Vec3f0(0), Vec3f0(1)))

robj = instanced_renderobject(data, Input(program), boundingbox, GL_TRIANGLES, grid)
robj = instanced_renderobject(data, Signal(program), boundingbox, GL_TRIANGLES, grid)
checkerror()
robj
end
Expand All @@ -236,7 +236,7 @@ push!(ROOT_SCREEN.renderlist, robj2)
push!(ROOT_SCREEN.renderlist, robj3)
push!(ROOT_SCREEN.renderlist, robj4)

const SELECTION = Dict{Symbol, Input{Matrix{Vec{2, Int}}}}()
const SELECTION = Dict{Symbol, Signal{Matrix{Vec{2, Int}}}}()
const SELECTION_QUERIES = Dict{Symbol, Rectangle{Int}}()
immutable SelectionID{T}
objectid::T
Expand All @@ -246,14 +246,14 @@ typealias GLSelection SelectionID{UInt16}
typealias ISelection SelectionID{Int}
function insert_selectionquery!(name::Symbol, value::Rectangle)
SELECTION_QUERIES[name] = value
SELECTION[name] = Input(Vec{2, Int}[]')
SELECTION[name] = Signal(Vec{2, Int}[]')
SELECTION[name]
end
function insert_selectionquery!(name::Symbol, value::Signal{Rectangle{Int}})
const_lift(value) do v
SELECTION_QUERIES[name] = v
end |> preserve
SELECTION[name] = Input(Array(Vec{2, Int}, value.value.w, value.value.h))
SELECTION[name] = Signal(Array(Vec{2, Int}, value.value.w, value.value.h))
SELECTION[name]
end
function delete_selectionquery!(name::Symbol)
Expand Down
4 changes: 2 additions & 2 deletions examples/tests/nbody.jl
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ function send_frame(i, planets)
reshape(p, (2,2))
end

const time_i = Input(1)
const time_i = Signal(1)
println(size(planets[:, 1]))
const positions = const_lift(send_frame, time_i, Input(planets))
const positions = const_lift(send_frame, time_i, Signal(planets))
const robj = visualize(positions, model=scalematrix(Vec3(0.1f0)))
len = length(planets[:, 1])
const planet_lines = [visualize(reshape(planets[:, i], (250, 100)), particle_color=RGBA(rand(Float32,3)..., 0.4f0), model=scalematrix(Vec3(0.01f0))) for i=1:4]
Expand Down
2 changes: 1 addition & 1 deletion examples/tests/test_color.jl
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ end
const dragdiff_id = get_drag_diff(inputs)
gizmo_dir = const_lift(/, const_lift(gizmodir_const_lift, dragdiff_id), 10f0)

model = getmodel(Input(0f0), Input(0f0), Input(0f0), gizmo_dir)
model = getmodel(Signal(0f0), Signal(0f0), Signal(0f0), gizmo_dir)


msh = GLNormalMesh(file"cat.obj")
Expand Down
2 changes: 1 addition & 1 deletion examples/tests/test_lines.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ lines = std_renderobject(Dict(
:vertex => GLBuffer(verts), #NOT WORKING
:index => indexbuffer(indexes), #NOT WORKING
:projectionview => GLVisualize.ROOT_SCREEN.perspectivecam.projectionview
), Input(lineshader), Input(AABB{Float32}(verts)), GL_LINES) #Input(AABB(verts)) -> calculates boundingbox
), Signal(lineshader), Signal(AABB{Float32}(verts)), GL_LINES) #Signal(AABB(verts)) -> calculates boundingbox

push!(GLVisualize.ROOT_SCREEN.renderlist, lines)

Expand Down
2 changes: 1 addition & 1 deletion examples/tests/test_particle2.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using GLVisualize, AbstractGPUArray, GLAbstraction, GeometryTypes, Reactive, ColorTypes, Meshes, MeshIO

# install a time varying signal
const timer = Input(1)
const timer = Signal(1)

function mkCube(p::GeometryTypes.Point3{Float32}, hsz::Float32)
cube = GLNormalMesh( Cube( Vec3( p.x, p.y, p.z), Vec3(hsz)))
Expand Down
4 changes: 2 additions & 2 deletions examples/tests/test_reactangle.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using GLVisualize, GeometryTypes, GLAbstraction, Reactive, ColorTypes


a = Input(Rectangle{Int64}(20,20,900,1000))
b = Input(Rectangle{Int64}(960,0,960,1280))
a = Signal(Rectangle{Int64}(20,20,900,1000))
b = Signal(Rectangle{Int64}(960,0,960,1280))
view(visualize(a, color=RGBA(1f0,0f0,1f0,0.5f0)))
#view(visualize(b, color=RGBA(0f0,0f0,1f0,1f0)))

Expand Down
2 changes: 1 addition & 1 deletion examples/tests/test_transformation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ end
const dragdiff_id = get_drag_diff(inputs)
gizmo_dir = const_lift(/, const_lift(gizmodir_const_lift, dragdiff_id), 10f0)

model = getmodel(Input(0f0), Input(0f0), Input(0f0), gizmo_dir)
model = getmodel(Signal(0f0), Signal(0f0), Signal(0f0), gizmo_dir)


msh = GLNormalMesh(file"cat.obj")
Expand Down
4 changes: 2 additions & 2 deletions examples/tests/wip_text_input.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ include(Pkg.dir("GLVisualize", "src", "visualize", "text", "utils.jl"))
unicode = w.inputs[:unicodeinput]
keys = w.inputs[:buttonspressed]

selection = Input(4:3)
selection = Signal(4:3)
text_raw = TextWithSelection([1,2,3,4], selection.value)
text = Input(text_raw)
text = Signal(text_raw)
const_lift(s->(text_raw.selection=s), selection) # is there really no other way?!

Base.IntSet(a...) = IntSet(a)
Expand Down
48 changes: 48 additions & 0 deletions src/boundingbox.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# As long as we don't calculate bounding boxes on the gpu, this needs to do:
Base.minimum(t::Texture) = minimum(gpu_data(t))
Base.maximum(t::Texture) = maximum(gpu_data(t))

call(::Type{AABB}, a::GPUArray) = AABB{Float32}(gpu_data(a))
call{T}(::Type{AABB{T}}, a::GPUArray) = AABB{T}(gpu_data(a))

call(::Type{AABB}, a::GPUArray) = AABB(gpu_data(a))
call(::Type{AABB}, a::GPUArray) = AABB(gpu_data(a))


particle_grid_bb{T}(min_xy::Vec{2,T}, max_xy::Vec{2,T}, minmax_z::Vec{2,T}) = AABB{T}(Vec(min_xy..., minmax_z[1]), Vec(max_xy..., minmax_z[2]))

Base.call{T, T2, T3}(::Type{AABB{T}}, positions::Texture{Point{3, T2}, 1}, scale::Texture{Vec{3, T3}, 1}, primitive_bb) = AABB{T}(gpu_data(positions), gpu_data(scale), primitive_bb)
Base.call{T, T2, T3}(::Type{AABB{T}}, positions::Texture{Point{3, T2}, 1}, scale::Vec{3, T3}, primitive_bb) = AABB{T}(gpu_data(positions), scale, primitive_bb)



function call{T}(Type{AABB{T}}, p::Particles)
primitive_bb = AABB{Float32}(p.primitive)
AABB{T}(p.positions, p.scale, primitive_bb)
end




function call{T, T2, T3, N}(::Type{AABB{T}}, positions::Vector{Point{N, T2}}, scale::Vec{N, T3}, primitive_bb)
primitive_scaled_min = minimum(primitive_bb) .* scale
primitive_scaled_max = maximum(primitive_bb) .* scale
pmax = max(primitive_scaled_min, primitive_scaled_max)
pmin = min(primitive_scaled_min, primitive_scaled_max)
main_bb = AABB{T}(positions)
AABB{T}(minimum(main_bb) + pmin, maximum(main_bb) + pmax)
end
function call{T, T2, T3, N}(::Type{AABB{T}}, positions::Vector{Point{N, T2}}, scale::Vector{Vec{N, T3}}, primitive_bb)
_max = Vec{N, T}(typemin(T))
_min = Vec{N, T}(typemax(T))
for (p, s) in zip(positions, scale)
p = Vec{N, T}(p)
s_min = Vec{N, T}(s) .* minimum(primitive_bb)
s_max = Vec{N, T}(s) .* maximum(primitive_bb)
s_min_r = min(s_min, s_max)
s_max_r = max(s_min, s_max)
_min = min(_min, p + s_min_r)
_max = max(_max, p + s_max_r)
end
AABB{T}(_min, _max)
end
18 changes: 9 additions & 9 deletions src/camera.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,22 +72,22 @@ Base.middle{T}(r::Rectangle{T}) = Point{2, T}(r.x+(r.w/T(2)), r.y+(r.h/T(2)))

function cubecamera(
window;
cube_area = Input(Rectangle(0,0,150,150)),
cube_area = Signal(Rectangle(0,0,150,150)),
eyeposition = Vec3f0(2),
lookatv = Vec3f0(0),
trans = Input(Vec3f0(0)),
theta = Input(Vec3f0(0))
trans = Signal(Vec3f0(0)),
theta = Signal(Vec3f0(0))
)
const T = Float32
@materialize mousebuttonspressed, window_size, mouseposition, buttonspressed = window.inputs

dd = doubleclick(window.inputs[:mousebuttonspressed], 0.2)
h = window.inputs[:mouse_hover]
id = Input(4)
id = Signal(4)
should_reset = filter(x->h.value[1] == id.value, false, dd)

p = colored_cube()
resetto = const_lift(cubeside_const_lift, should_reset, id, get_cube_rotations(eyeposition, value(lookatv))..., Input(h))
resetto = const_lift(cubeside_const_lift, should_reset, id, get_cube_rotations(eyeposition, value(lookatv))..., Signal(h))
inside_trans = Quaternions.Quaternion(1f0,0f0,0f0,0f0)
outside_trans = Quaternions.qrotation(Float32[0,1,0], deg2rad(180f0))
cube_rotation = const_lift(cube_area, mouseposition) do ca, mp
Expand Down Expand Up @@ -130,7 +130,7 @@ function cubecamera(
b == [GLFW.KEY_LEFT_CONTROL]
end
theta, trans, zoom = default_camera_control(window.inputs, theta=theta, trans=trans, filtersignal=use_cam)
far, near, fov = Input(100f0), Input(1f0), Input(43f0)
far, near, fov = Signal(100f0), Signal(1f0), Signal(43f0)
main_cam = PerspectiveCamera(
window.area,eyeposition,lookatv,
theta,trans,zoom,fov,near,far,
Expand All @@ -143,17 +143,17 @@ function cubecamera(
model = const_lift(cube_rotation, const_lift(inv, rot)) do cr, r
translationmatrix(Vec3f0(3,3,0)) * Mat{4,4,T}(cr) * translationmatrix(Vec3f0(-3,-3,0)) * Mat{4,4,T}(r)
end
cubescreen = Screen(window, area=cube_area, transparent=Input(true))
cubescreen = Screen(window, area=cube_area, transparent=Signal(true))
cubescreen.cameras[:cube_cam] = DummyCamera(
farclip=far,
nearclip=near,
view=Input(lookat(eyeposition, value(lookatv), Vec3f0(0,0,1))),
view=Signal(lookat(eyeposition, value(lookatv), Vec3f0(0,0,1))),
projection=const_lift(perspectiveprojection, cube_area, fov, near, far)
)
robj = visualize(p, model=model, preferred_camera=:cube_cam)
start_colors = p.attributes
color_tex = robj[:attributes]
preserve(const_lift(cubeside_color, id, h, Input(start_colors), Input(color_tex)))
preserve(const_lift(cubeside_color, id, h, Signal(start_colors), Signal(color_tex)))

push!(id, robj.id)
view(robj, cubescreen);
Expand Down
6 changes: 3 additions & 3 deletions src/display/renderloop.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ typealias GLSelection SelectionID{UInt16}
typealias ISelection SelectionID{Int}
function insert_selectionquery!(name::Symbol, value::Rectangle, selection, selectionquery)
selectionquery[name] = value
selection[name] = Input(Vec{2, Int}[]')
selection[name] = Signal(Vec{2, Int}[]')
selection[name]
end

Expand All @@ -15,7 +15,7 @@ insert_selectionquery(value, selectionquery, name) = selectionquery[name] = valu

function insert_selectionquery!(name::Symbol, value::Signal{Rectangle{Int}}, selection, selectionquery)
preserve(const_lift(insert_selectionquery, value, selectionquery, name))
selection[name] = Input(Array(Vec{2, Int}, value.value.w, value.value.h))
selection[name] = Signal(Array(Vec{2, Int}, value.value.w, value.value.h))
selection[name]
end
function delete_selectionquery!(name::Symbol, selection, selectionquery)
Expand Down Expand Up @@ -107,7 +107,7 @@ function glscreen()
screen.inputs[:framebuffer] = framebuffer
postprocess_robj = postprocess(framebuffer, screen)

selection = Dict{Symbol, Input{Matrix{Vec{2, Int}}}}()
selection = Dict{Symbol, Signal{Matrix{Vec{2, Int}}}}()
selectionquery = Dict{Symbol, Rectangle{Int}}()
insert_selectionquery!(:mouse_hover, const_lift(mouse_selection, screen.inputs[:mouseposition]), selection, selectionquery)
add_complex_signals(screen, selection) #add the drag events and such
Expand Down
4 changes: 2 additions & 2 deletions src/edit/line_edit.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
float_diff(a,b) = Vec2f2(a-b)
function vizzedit{T}(points::Vector{Point{2,T}}, window; color=default(RGBA))
line = visualize(Input(points), :lines)
line = visualize(Signal(points), :lines)
point_gpu = line[:vertex]
points = visualize(Texture(point_gpu), shape=Cint(CIRCLE), style=Cint(GLOWING) | Cint(FILLED) | Cint(OUTLINED))
hovering_lines = is_hovering(line, window)
Expand Down Expand Up @@ -31,7 +31,7 @@ function edit_line(
line, direction_restriction::Vec2f0, clampto, window;
color=default(RGBA{Float32}, Style{:default}())
)
line_robj = visualize(Input(line), :lines, color=color, thickness = 4f0)
line_robj = visualize(Signal(line), :lines, color=color, thickness = 4f0)
point_gpu = line_robj[:vertex]
points = visualize(
Texture(point_gpu),
Expand Down
2 changes: 1 addition & 1 deletion src/edit/numbers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ function vizzedit(range::Range, inputs, numberwidth=5; startvalue=middle(range))
mouse_add_drag_id = foldp(
add_mouse_drags,
(zero(T), false, Vec2f0(0), 0, zero(T), 0),
mousedown, inputs[:mouseposition], inputs[:mouse_hover], Input(Int(vizz.id)), Input(numberwidth+1) #plus space
mousedown, inputs[:mouseposition], inputs[:mouse_hover], Signal(Int(vizz.id)), Signal(numberwidth+1) #plus space
)
addition_vec = droprepeats(const_lift(first, mouse_add_drag_id))

Expand Down
4 changes: 2 additions & 2 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ macro visualize_gen(input, target, S)

function visualize(signal::Signal{$input}, s::$S, customizations=visualize_default(signal.value, s))
tex = $target(signal.value)
preserve(const_lift(update!, Input(tex), signal))
preserve(const_lift(update!, Signal(tex), signal))
visualize(tex, s, customizations)
end
end)
Expand Down Expand Up @@ -58,7 +58,7 @@ function GLVisualizeShader(shaders...; attributes...)
end

function default_boundingbox(main, model)
main == nothing && return Input(AABB{Float32}(Vec3f0(0), Vec3f0(1)))
main == nothing && return Signal(AABB{Float32}(Vec3f0(0), Vec3f0(1)))
const_lift(*, model, AABB{Float32}(main))
end
function assemble_std(main, dict, shaders...; boundingbox=default_boundingbox(main, get(dict, :model, eye(Mat{4,4,Float32}))), primitive=GL_TRIANGLES)
Expand Down
Loading

0 comments on commit bbbab0c

Please sign in to comment.