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

Numerous changes in order to get GLVisualize running from Plots in Ju… #260

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
julia 0.6
julia 0.7

StaticArrays 0.6.0
GeometryTypes 0.4.1
Expand Down Expand Up @@ -29,3 +29,5 @@ Images 0.9.0 # first version working on 0.6
AxisArrays
ImageAxes
IndirectArrays

Statistics
2 changes: 1 addition & 1 deletion src/GLVisualize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ using Packing
using SignedDistanceFields
using FreeType
import IterTools
using Base.Markdown
using Markdown
using FreeTypeAbstraction

import ColorVectorSpace
Expand Down
2 changes: 1 addition & 1 deletion src/boundingbox.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function (B::Type{AABB{T}})(
return primitive
end
tsr::Tuple{Point3f0, Vec3f0, Mat4f0}, state = next(ti, state)
points = decompose(Point3f0, primitive)::Vector{Point3f0}
points = decompose(Point3f0, primitive) #::Vector{Point3f0}
bb = transform(tsr[1], tsr[2], tsr[3], points)
while !done(ti, state)
tsr, state = next(ti, state)
Expand Down
6 changes: 4 additions & 2 deletions src/camera.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using Statistics

function cubeside_const_lift(_, id, mousehover)
h_id, h_index = value(mousehover)
if h_id == id && h_index >= 1 && h_index <= 6
Expand Down Expand Up @@ -28,7 +30,7 @@ function colored_cube()
ydir = Vec3f0(0f0,1f0,0f0)
zdir = Vec3f0(0f0,0f0,1f0)
origin = Vec3f0(-0.5)
const quads = [
quads = [
(Quad(origin + zdir, xdir, ydir), RGBA(1.0f0,0f0,0f0,1f0)), # Top
(Quad(origin, ydir, xdir), RGBA(0.5f0,0f0,0f0,1f0)), # Bottom
(Quad(origin + ydir, zdir, xdir), RGBA(0f0,1.0f0,0f0,1f0)), #Front
Expand All @@ -39,7 +41,7 @@ function colored_cube()
cube_steering = merge(map(GLNormalMesh, quads))
end

Base.middle(r::SimpleRectangle{T}) where {T} = Point{2, T}(r.x+(r.w/T(2)), r.y+(r.mousehover/T(2)))
middle(r::SimpleRectangle{T}) where {T} = Point{2, T}(r.x+(r.w/T(2)), r.y+(r.mousehover/T(2)))


function get_rotation(m)
Expand Down
2 changes: 1 addition & 1 deletion src/documentation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ end
function print_type(x::TypeVar)
string(x.name)
end
print_type(x::TypeName) = print_type(x.name)
#print_type(x::TypeName) = print_type(x.name)
print_type(x::UnionAll) = sprint(io-> show(io, x))
print_type(x) = print_type(x.name)
function print_type(x::Union)
Expand Down
2 changes: 1 addition & 1 deletion src/gui/buttons.jl
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ end
function widget(
r::Signal{T}, screen::Screen;
args...
) where T <: Range
) where T <: AbstractRange
slider(value(r), screen; args...)
end
function playbutton(screen; icon_size = 10mm)
Expand Down
5 changes: 3 additions & 2 deletions src/gui/numbers.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using Printf

drag_x(drag_id) = drag_id[1][1]

Expand Down Expand Up @@ -39,9 +40,9 @@ function add_mouse_drags(t0, mouse_down1, mouseposition1, objectid, id_tolookfor
(accum, mouse_down1, Vec2f0(0), 0, accum, 0)
end

Base.clamp(x, r::Range) = clamp(x, first(r), last(r))
Base.clamp(x, r::AbstractRange) = clamp(x, first(r), last(r))

function slide(startvalue, slide_pos, range::Range)
function slide(startvalue, slide_pos, range::AbstractRange)
val = startvalue + (slide_pos*step(range))
clamp(val, range)
end
Expand Down
1 change: 1 addition & 0 deletions src/parallel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ using FileIO
using Packing
using SignedDistanceFields
using FreeType
using Distributed


# Parallel helper function to launch our glvisualize operations on the process,
Expand Down
4 changes: 2 additions & 2 deletions src/renderloop.jl
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ function fold_loop(v0, _)
(val, range, index)
end

function loop(range::Range, rate=60)
function loop(range::AbstractRange, rate=60)
t = get_timer_signal(rate)
map(first, foldp(fold_loop, (first(range), range, 1), t))
end
Expand All @@ -125,7 +125,7 @@ function fold_bounce(v0, _)
(val, range, index, direction)
end

function bounce(range::Range{T}, rate=60) where T
function bounce(range::AbstractRange{T}, rate=60) where T
t = get_timer_signal(rate)
map(first, foldp(fold_bounce, (first(range), range, 1, 1), t))
end
Expand Down
15 changes: 8 additions & 7 deletions src/texture_atlas.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,15 @@ begin #basically a singleton for the textureatlas
# random list of chars we cache
# basically to make runtests fast, until we figure out a better way to cache
# newly rendered chars.
const local _tobe_cached = [
#const local _tobe_cached = [
local _tobe_cached = [
'π','∮','⋅','→','∞','∑','∏','∀','∈','ℝ','⌈','⌉','−','⌊','⌋','α','∧','β','∨','ℕ','⊆','₀',
'⊂','ℤ','ℚ','ℂ','⊥','≠','≡','≤','≪','⊤','⇒','⇔','₂','⇌','Ω','⌀',
]
const local _atlas_cache = Dict{WeakRef, TextureAtlas}()
const local _cache_path = joinpath(dirname(@__FILE__), "..", ".cache", "texture_atlas.jls")
const local _default_font = Vector{Ptr{FreeType.FT_FaceRec}}[]
const local _alternative_fonts = Vector{Ptr{FreeType.FT_FaceRec}}[]
local _atlas_cache = Dict{WeakRef, TextureAtlas}()
local _cache_path = joinpath(dirname(@__FILE__), "..", ".cache", "texture_atlas.jls")
local _default_font = Vector{Ptr{FreeType.FT_FaceRec}}[]
local _alternative_fonts = Vector{Ptr{FreeType.FT_FaceRec}}[]

function defaultfont()
if isempty(_default_font)
Expand Down Expand Up @@ -79,13 +80,13 @@ begin #basically a singleton for the textureatlas
TextureAtlas(fields...)
end
catch e
info("You can likely ignore the following warning, if you just switched Julia versions for GLVisualize")
@info("You can likely ignore the following warning, if you just switched Julia versions for GLVisualize")
warn(e)
rm(_cache_path)
end
end
atlas = TextureAtlas()
info("Caching fonts, this may take a while. Needed only on first run!")
@info("Caching fonts, this may take a while. Needed only on first run!")
for c in '\u0000':'\u00ff' #make sure all ascii is mapped linearly
insert_glyph!(atlas, c, defaultfont())
end
Expand Down
20 changes: 10 additions & 10 deletions src/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
@enum RaymarchAlgorithm IsoValue Absorption MaximumIntensityProjection AbsorptionRGBA IndexedAbsorptionRGBA
@enum CubeSides TOP BOTTOM FRONT BACK RIGHT LEFT

struct Grid{N, T <: Range}
struct Grid{N, T <: AbstractRange}
dims::NTuple{N, T}
end
Base.ndims(::Grid{N,T}) where {N,T} = N

Grid(ranges::Range...) = Grid(ranges)
Grid(ranges::AbstractRange...) = Grid(ranges)
function Grid(a::Array{T, N}) where {N, T}
s = Vec{N, Float32}(size(a))
smax = maximum(s)
Expand Down Expand Up @@ -74,8 +74,8 @@ import Base: getindex, length, next, start, done
to_cpu_mem(x) = x
to_cpu_mem(x::GPUArray) = gpu_data(x)

const ScaleTypes = Union{Vector, Vec, AbstractFloat, Void, Grid}
const PositionTypes = Union{Vector, Point, AbstractFloat, Void, Grid}
const ScaleTypes = Union{Vector, Vec, AbstractFloat, Nothing, Grid}
const PositionTypes = Union{Vector, Point, AbstractFloat, Nothing, Grid}

mutable struct ScalarRepeat{T}
scalar::T
Expand Down Expand Up @@ -132,22 +132,22 @@ end



function ArrayOrStructOfArray(::Type{T}, array::Void, a, elements...) where T
function ArrayOrStructOfArray(::Type{T}, array::Nothing, a, elements...) where T
StructOfArrays(T, a, elements...)
end
function ArrayOrStructOfArray(::Type{T}, array::StaticVector, a, elements...) where T
StructOfArrays(T, a, elements...)
end
function ArrayOrStructOfArray(::Type{T}, scalar::StaticVector, a::Void, elements::Void...) where T
function ArrayOrStructOfArray(::Type{T}, scalar::StaticVector, a::Nothing, elements::Nothing...) where T
ScalarRepeat(transform_convert(T, scalar))
end
function ArrayOrStructOfArray(::Type{T1}, array::Array{T2}, a::Void, elements::Void...) where {T1,T2}
function ArrayOrStructOfArray(::Type{T1}, array::Array{T2}, a::Nothing, elements::Nothing...) where {T1,T2}
array
end
function ArrayOrStructOfArray(::Type{T1}, grid::Grid, x::Void, y::Void, z::Array) where T1<:Point
function ArrayOrStructOfArray(::Type{T1}, grid::Grid, x::Nothing, y::Nothing, z::Array) where T1<:Point
GridZRepeat(grid, z)
end
function ArrayOrStructOfArray(::Type{T1}, array::Grid, a::Void, elements::Void...) where T1<:Point
function ArrayOrStructOfArray(::Type{T1}, array::Grid, a::Nothing, elements::Nothing...) where T1<:Point
array
end
function ArrayOrStructOfArray(::Type{T}, scalar::T) where T
Expand Down Expand Up @@ -259,7 +259,7 @@ struct GLVisualizeShader <: AbstractLazyShader
kw_args::Dict{Symbol, Any}
function GLVisualizeShader(paths::String...; view = Dict{String, String}(), kw_args...)
# TODO properly check what extensions are available
@static if !is_apple()
@static if !Sys.isapple()
view["GLSL_EXTENSIONS"] = "#extension GL_ARB_conservative_depth: enable"
view["SUPPORTED_EXTENSIONS"] = "#define DETPH_LAYOUT"
end
Expand Down
4 changes: 2 additions & 2 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ isa_image(x::Matrix) = isa_image(typeof(x))
isa_image(x) = false

# Splits a dictionary in two dicts, via a condition
function Base.split(condition::Function, associative::Associative)
function Base.split(condition::Function, associative::AbstractDict)
A = similar(associative)
B = similar(associative)
for (key, value) in associative
Expand Down Expand Up @@ -170,7 +170,7 @@ function dragged_on(robj::RenderObject, button::MouseButton, window::Screen)
end)
end

points2f0(positions::Vector{T}, range::Range) where {T} = Point2f0[Point2f0(range[i], positions[i]) for i=1:length(range)]
points2f0(positions::Vector{T}, range::AbstractRange) where {T} = Point2f0[Point2f0(range[i], positions[i]) for i=1:length(range)]

extrema2f0(x::Array{T,N}) where {T<:Intensity,N} = Vec2f0(extrema(reinterpret(Float32,x)))
extrema2f0(x::Array{T,N}) where {T,N} = Vec2f0(extrema(x))
Expand Down
2 changes: 1 addition & 1 deletion src/videotool.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# ffmpeg version
# ffmpeg -r 24 -pattern_type glob -i '*.png' -vcodec libx264 -crf 25 -pix_fmt yuv420p test.mp4

immutable VideoStream
struct VideoStream
io
buffer
window
Expand Down
1 change: 0 additions & 1 deletion src/visualize/image_like.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""
A matrix of colors is interpreted as an image
"""

_default(::Signal{Array{RGBA{N0f8}, 2}}, ::Style{:default}, ::Dict{Symbol,Any})


Expand Down
7 changes: 5 additions & 2 deletions src/visualize/lines.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,10 @@ function ticks(points, resolution)
end


function _default(position::Union{VecTypes{T}, MatTypes{T}}, s::style"lines", data::Dict) where T<:Point
_default(position::Union{VecTypes{T}, MatTypes{T}}, s::style"lines", data::Dict) where T<:Point = _default_l(position, s, data)
_default(position::Union{Array{T,1}, GPUArray{T,1}, Signal{Array{T,1}}}, s::style"lines", data::Dict) where T<:Point = _default_l(position, s, data)

function _default_l(position::Union{VecTypes{T}, MatTypes{T}}, s::style"lines", data::Dict) where T<:Point
pv = value(position)
p_vec = if isa(position, GPUArray)
position
Expand Down Expand Up @@ -137,7 +140,7 @@ function _default(positions::VecTypes{T}, s::style"linesegment", data::Dict) whe
data
end

function _default(positions::Vector{T}, range::Range, s::style"lines", data::Dict) where T <: AbstractFloat
function _default(positions::Vector{T}, range::AbstractRange, s::style"lines", data::Dict) where T <: AbstractFloat
length(positions) != length(range) && throw(
DimensionMismatsch("length of $(typeof(positions)) $(length(positions)) and $(typeof(range)) $(length(range)) must match")
)
Expand Down
3 changes: 1 addition & 2 deletions src/visualize/particles.jl
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,7 @@ primitive_scale(c) = Vec2f0(0.1)
Extracts the offset from a primitive.
"""
#primitive_offset(prim::GeometryPrimitive) = Vec2f0(minimum(prim))

primitive_offset(x, scale::Void) = Vec2f0(0) # default offset
primitive_offset(x, scale::Nothing) = Vec2f0(0) # default offset
primitive_offset(x, scale) = const_lift(/, scale, -2f0) # default offset


Expand Down
2 changes: 1 addition & 1 deletion src/visualize/text.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function Base.setindex!(t::Text, value::Char, i::Integer)
t.scales[i] = gs
end

function Base.setindex!(t::Text, value::Associative, i::Integer)
function Base.setindex!(t::Text, value::AbstractDict, i::Integer)
for (k,v) in value
getfield(t, k)[i] = v
end
Expand Down