Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP julia 1.0 update #15

Merged
merged 9 commits into from
Oct 2, 2018
Merged
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
19 changes: 12 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
# Documentation: http://docs.travis-ci.com/user/languages/julia/
language: julia
sudo: required
os:
- linux
# - osx
julia:
- 0.6
- nightly
matrix:
allow_failures:
- julia: nightly
- 0.7
- 1.0

addons:
apt:
packages:
- libgtk-3-dev

notifications:
email: false
script:
- if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
- julia --check-bounds=yes -e 'Pkg.clone("https://github.com/tawheeler/Vec.jl.git"); Pkg.clone("https://github.com/tawheeler/Records.jl.git"); Pkg.clone("https://github.com/tawheeler/AutomotiveDrivingModels.jl.git"); Pkg.clone(pwd()); Pkg.test("AutoViz"; coverage=true)'
- julia --project --check-bounds=yes -e 'using Pkg; Pkg.add(PackageSpec(url="https://github.com/sisl/Vec.jl")); Pkg.add(PackageSpec(url="https://github.com/sisl/Records.jl")); Pkg.add(PackageSpec(url="https://github.com/sisl/AutomotiveDrivingModels.jl")); Pkg.build("AutoViz"); Pkg.test("AutoViz"; coverage=true)'
after_success:
- julia -e 'cd(Pkg.dir("AutoViz")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'
- julia --project -e 'using Pkg; cd(Pkg.dir("AutoViz")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(Coveralls.process_folder())'
24 changes: 24 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name = "AutoViz"
uuid = "82aa6e0c-a491-5edf-8d4b-c16b98e4ea17"
repo = "https://github.com/sisl/AutoViz.jl.git"
version = "0.6.2"

[deps]
Cairo = "159f3aea-2a34-519c-b102-8c37f9878175"
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
Parameters = "d96e819e-fc66-5662-9728-84c9c7592b0a"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
Reel = "71555da5-176e-5e73-a222-aebc6c6e4f2f"
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"

[extras]
Interact = "c601a237-2ae4-5e1e-952c-7a85b0c7eef1"
NBInclude = "0db19996-df87-5ea3-a455-e3a50d440464"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Reactive = "a223df75-4e93-5b7c-acf9-bdd599c0f4de"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Interact", "NBInclude", "Random", "Reactive", "Test"]
10 changes: 0 additions & 10 deletions REQUIRE

This file was deleted.

11 changes: 11 additions & 0 deletions deps/build.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Pkg
packages = keys(Pkg.installed())
if !in("Vec", packages)
Pkg.add(PackageSpec(url="https://github.com/sisl/Vec.jl.git"))
end
if !in("Records", packages)
Pkg.add(PackageSpec(url="https://github.com/sisl/Records.jl.git"))
end
if !in("AutomotiveDrivingModels", packages)
Pkg.add(PackageSpec(url="https://github.com/sisl/AutomotiveDrivingModels.jl.git"))
end
273 changes: 123 additions & 150 deletions doc/AutoViz.ipynb

Large diffs are not rendered by default.

35 changes: 18 additions & 17 deletions notebooks/tutorial.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,18 @@
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": false
},
"outputs": [],
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"\u001b[1m\u001b[36mINFO: \u001b[39m\u001b[22m\u001b[36mPrecompiling module AutomotiveDrivingModels.\n",
"\u001b[39m"
]
}
],
"source": [
"using AutomotiveDrivingModels\n",
"using AutoViz"
Expand All @@ -36,9 +43,7 @@
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"data": {
Expand All @@ -54,7 +59,7 @@
],
"source": [
"roadway = gen_stadium_roadway(2)\n",
"scene = Vector{Any}(0)\n",
"scene = Vector{Any}(undef, 0)\n",
"push!(scene, roadway)\n",
"render(scene)"
]
Expand Down Expand Up @@ -98,9 +103,7 @@
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"data": {
Expand All @@ -121,9 +124,7 @@
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"data": {
Expand Down Expand Up @@ -179,15 +180,15 @@
"metadata": {
"anaconda-cloud": {},
"kernelspec": {
"display_name": "Julia 0.6.2",
"display_name": "Julia 0.6.0",
"language": "julia",
"name": "julia-0.6"
},
"language_info": {
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "0.6.2"
"version": "0.6.0"
}
},
"nbformat": 4,
Expand Down
10 changes: 5 additions & 5 deletions src/2d/roadways.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function render!(rendermodel::RenderModel, lane::Lane, roadway::Roadway;
)

n = length(lane.curve)
pts = Array{Float64}(2, n + has_next(lane))
pts = Array{Float64}(undef, 2, n + has_next(lane))
for (i,pt) in enumerate(lane.curve)
pts[1,i] = pt.pos.x
pts[2,i] = pt.pos.y
Expand Down Expand Up @@ -51,7 +51,7 @@ function render!(rendermodel::RenderModel, roadway::Roadway;
laneR = seg.lanes[1]
laneL = seg.lanes[end]

pts = Array{Float64}(2, length(laneL.curve) + has_next(laneL) +
pts = Array{Float64}(undef, 2, length(laneL.curve) + has_next(laneL) +
length(laneR.curve) + has_next(laneR) +
2*length(seg.lanes))
pts_index = 0
Expand Down Expand Up @@ -117,7 +117,7 @@ function render!(rendermodel::RenderModel, roadway::Roadway;
halfwidth = lane.width/2

# always render the left lane marking
pts_left = Array{Float64}(2, N)
pts_left = Array{Float64}(undef, 2, N)
for (i,pt) in enumerate(lane.curve)
p_left = pt.pos + polar(halfwidth, pt.pos.θ + π/2)

Expand All @@ -135,7 +135,7 @@ function render!(rendermodel::RenderModel, roadway::Roadway;

# only render the right lane marking if this is the first lane
if lane.tag.lane == 1
pts_right = Array{Float64}(2, N)
pts_right = Array{Float64}(undef, 2, N)

for (i,pt) in enumerate(lane.curve)
p_right = pt.pos - polar(halfwidth, pt.pos.θ + π/2)
Expand All @@ -160,6 +160,6 @@ function render!(rendermodel::RenderModel, roadway::Roadway;
end

# for case when there is no roadway
render!(rendermodel::RenderModel, roadway::Void) = rendermodel
render!(rendermodel::RenderModel, roadway::Nothing) = rendermodel

Base.show(io::IO, ::MIME"image/png", roadway::Roadway) = show(io, MIME"image/png"(), render(roadway))
1 change: 1 addition & 0 deletions src/AutoViz.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ using Reexport
using Parameters
using StaticArrays
using AutomotiveDrivingModels
using Printf

@reexport using Colors
@reexport using Cairo
Expand Down
16 changes: 8 additions & 8 deletions src/cameras.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export
SceneFollowCamera

abstract type Camera end
camera_set!{S,D,I,R}(::RenderModel, cam::Camera, ::EntityFrame{S,D,I}, ::R, canvas_width::Int, canvas_height::Int) = error("camera_set! not implemented for Camera $cam")
camera_set!(::RenderModel, cam::Camera, ::EntityFrame{S,D,I}, ::R, canvas_width::Int, canvas_height::Int) where {S,D,I,R} = error("camera_set! not implemented for Camera $cam")

mutable struct StaticCamera <: Camera
pos::VecE2
Expand All @@ -21,7 +21,7 @@ function camera_set!(rendermodel::RenderModel, cam::StaticCamera, canvas_width::

rendermodel
end
camera_set!{S,D,I,R}(rendermodel::RenderModel, cam::StaticCamera, scene::EntityFrame{S,D,I}, roadway::R, canvas_width::Int, canvas_height::Int) = camera_set!(rendermodel, cam, canvas_width, canvas_height)
camera_set!(rendermodel::RenderModel, cam::StaticCamera, scene::EntityFrame{S,D,I}, roadway::R, canvas_width::Int, canvas_height::Int) where {S,D,I,R} = camera_set!(rendermodel, cam, canvas_width, canvas_height)

# method for new interface
camera_set!(rm::RenderModel, cam::StaticCamera, scene, canvas_width::Int, canvas_height::Int) = camera_set!(rm, cam, canvas_width, canvas_height)
Expand All @@ -34,7 +34,7 @@ function camera_set!(rendermodel::RenderModel, cam::FitToContentCamera, canvas_w
camera_fit_to_content!(rendermodel, canvas_width, canvas_height, percent_border=cam.percent_border)
rendermodel
end
camera_set!{S,D,I,R}(rendermodel::RenderModel, cam::FitToContentCamera, scene::EntityFrame{S,D,I}, roadway::R, canvas_width::Int, canvas_height::Int) = camera_set!(rendermodel, cam, canvas_width, canvas_height)
camera_set!(rendermodel::RenderModel, cam::FitToContentCamera, scene::EntityFrame{S,D,I}, roadway::R, canvas_width::Int, canvas_height::Int) where {S,D,I,R} = camera_set!(rendermodel, cam, canvas_width, canvas_height)

# method for new interface
camera_set!(rendermodel::RenderModel, cam::FitToContentCamera, scene, canvas_width::Int, canvas_height::Int) = camera_set!(rendermodel, cam, canvas_width, canvas_height)
Expand All @@ -45,7 +45,7 @@ mutable struct CarFollowCamera{I} <: Camera
end
CarFollowCamera(targetid::I) where {I} = CarFollowCamera{I}(targetid, 3.0)

function camera_set!{S<:State1D,D,I,R}(rendermodel::RenderModel, cam::CarFollowCamera{I}, scene::EntityFrame{S,D,I}, roadway::R, canvas_width::Int, canvas_height::Int)
function camera_set!(rendermodel::RenderModel, cam::CarFollowCamera{I}, scene::EntityFrame{S,D,I}, roadway::R, canvas_width::Int, canvas_height::Int) where {S<:State1D,D,I,R}

veh_index = findfirst(scene, cam.targetid)
if veh_index != 0
Expand All @@ -58,7 +58,7 @@ function camera_set!{S<:State1D,D,I,R}(rendermodel::RenderModel, cam::CarFollowC

rendermodel
end
function camera_set!{S<:VehicleState,D,I,R}(rendermodel::RenderModel, cam::CarFollowCamera{I}, scene::EntityFrame{S,D,I}, roadway::R, canvas_width::Int, canvas_height::Int)
function camera_set!(rendermodel::RenderModel, cam::CarFollowCamera{I}, scene::EntityFrame{S,D,I}, roadway::R, canvas_width::Int, canvas_height::Int) where {S<:VehicleState,D,I,R}

veh_index = findfirst(scene, cam.targetid)
if veh_index != 0
Expand All @@ -75,7 +75,7 @@ end
# method for new interface
function camera_set!(rendermodel::RenderModel, cam::CarFollowCamera, scene, canvas_width::Int, canvas_height::Int)

inds = find(x -> x isa ArrowCar && id(x) == cam.targetid, scene)
inds = findall(x -> x isa ArrowCar && id(x) == cam.targetid, scene)
if isempty(inds)
ids = [c.id for c in scene if c isa ArrowCar]
add_instruction!( rendermodel, render_text, ("CarFollowCamera did not find an ArrowCar with id $(cam.targetid) (found ids: $ids)", 10, 15, 15, colorant"white"), incameraframe=false)
Expand All @@ -93,7 +93,7 @@ mutable struct SceneFollowCamera <: Camera
zoom::Float64 # [pix/meter]
SceneFollowCamera(zoom::Float64=3.0) = new(zoom)
end
function camera_set!{S<:State1D,D,I,R}(rendermodel::RenderModel, cam::SceneFollowCamera, scene::EntityFrame{S,D,I}, roadway::R, canvas_width::Int, canvas_height::Int)
function camera_set!(rendermodel::RenderModel, cam::SceneFollowCamera, scene::EntityFrame{S,D,I}, roadway::R, canvas_width::Int, canvas_height::Int) where {S<:State1D,D,I,R}


if length(scene) > 0
Expand All @@ -114,7 +114,7 @@ function camera_set!{S<:State1D,D,I,R}(rendermodel::RenderModel, cam::SceneFollo

rendermodel
end
function camera_set!{S<:VehicleState,D,I,R}(rendermodel::RenderModel, cam::SceneFollowCamera, scene::EntityFrame{S,D,I}, roadway::R, canvas_width::Int, canvas_height::Int)
function camera_set!(rendermodel::RenderModel, cam::SceneFollowCamera, scene::EntityFrame{S,D,I}, roadway::R, canvas_width::Int, canvas_height::Int) where {S<:VehicleState,D,I,R}


if length(scene) > 0
Expand Down
18 changes: 9 additions & 9 deletions src/interface.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
function render!{S,D,I}(
function render!(
rendermodel::RenderModel,
scene::EntityFrame{S,D,I};
car_color::Colorant=COLOR_CAR_OTHER, # default color
car_colors::Dict{I,Colorant}=Dict{I,Colorant}(), # id -> color
)
) where {S,D,I}

for veh in scene
render!(rendermodel, veh, get(car_colors, veh.id, car_color))
Expand All @@ -12,12 +12,12 @@ function render!{S,D,I}(
rendermodel
end

function render{R<:Roadway}(roadway::R;
function render(roadway::R;
canvas_width::Int=DEFAULT_CANVAS_WIDTH,
canvas_height::Int=DEFAULT_CANVAS_HEIGHT,
rendermodel = RenderModel(),
cam::Camera = FitToContentCamera(),
)
) where {R<:Roadway}

s = CairoRGBSurface(canvas_width, canvas_height)
ctx = creategc(s)
Expand All @@ -30,11 +30,11 @@ function render{R<:Roadway}(roadway::R;
return s
end

function render{S,D,I,R}(ctx::CairoContext, scene::EntityFrame{S,D,I}, roadway::R;
function render(ctx::CairoContext, scene::EntityFrame{S,D,I}, roadway::R;
rendermodel::RenderModel=RenderModel(),
cam::Camera=SceneFollowCamera(),
car_colors::Dict{I,Colorant}=Dict{I,Colorant}(),
)
) where {S,D,I,R}

canvas_width = floor(Int, Cairo.width(ctx))
canvas_height = floor(Int, Cairo.height(ctx))
Expand All @@ -49,20 +49,20 @@ function render{S,D,I,R}(ctx::CairoContext, scene::EntityFrame{S,D,I}, roadway::
render(rendermodel, ctx, canvas_width, canvas_height)
ctx
end
function render{S,D,I,R}(scene::EntityFrame{S,D,I}, roadway::R;
function render(scene::EntityFrame{S,D,I}, roadway::R;
canvas_width::Int=DEFAULT_CANVAS_WIDTH,
canvas_height::Int=DEFAULT_CANVAS_HEIGHT,
rendermodel::RenderModel=RenderModel(),
cam::Camera=SceneFollowCamera(),
car_colors::Dict{I,Colorant}=Dict{I,Colorant}(), # id
)
) where {S,D,I,R}

s, ctx = get_surface_and_context(canvas_width, canvas_height)
render(ctx, scene, roadway, rendermodel=rendermodel, cam=cam, car_colors=car_colors)
s
end

function get_pastel_car_colors{S,D,I}(scene::EntityFrame{S,D,I}; saturation::Float64=0.85, value::Float64=0.85)
function get_pastel_car_colors(scene::EntityFrame{S,D,I}; saturation::Float64=0.85, value::Float64=0.85) where {S,D,I}
retval = Dict{I,Colorant}()
n = length(scene)
for (i,veh) in enumerate(scene)
Expand Down
8 changes: 4 additions & 4 deletions src/overlays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ export

abstract type SceneOverlay end

function render{S,D,I,O<:SceneOverlay,R}(scene::EntityFrame{S,D,I}, roadway::R, overlays::AbstractVector{O};
function render(scene::EntityFrame{S,D,I}, roadway::R, overlays::AbstractVector{O};
canvas_width::Int=DEFAULT_CANVAS_WIDTH,
canvas_height::Int=DEFAULT_CANVAS_HEIGHT,
rendermodel::RenderModel=RenderModel(),
cam::Camera=SceneFollowCamera(),
car_colors::Dict{I,Colorant}=Dict{I,Colorant}(),
)
) where {S,D,I,O<:SceneOverlay,R}

s = CairoRGBSurface(canvas_width, canvas_height)
ctx = creategc(s)
Expand Down Expand Up @@ -76,7 +76,7 @@ end
line_spacing::Float64 = 1.5 # multiple of font_size
incameraframe=false
end
function render!{S,D,I,R}(rendermodel::RenderModel, overlay::TextOverlay, scene::EntityFrame{S,D,I}, roadway::R)
function render!(rendermodel::RenderModel, overlay::TextOverlay, scene::EntityFrame{S,D,I}, roadway::R) where {S,D,I,R}
x = overlay.pos.x
y = overlay.pos.y
y_jump = overlay.line_spacing*overlay.font_size
Expand All @@ -103,7 +103,7 @@ end
mutable struct Overwash <: SceneOverlay
color::Colorant
end
function render!{S,D,I,R}(rendermodel::RenderModel, overlay::Overwash, scene::EntityFrame{S,D,I}, roadway::R)
function render!(rendermodel::RenderModel, overlay::Overwash, scene::EntityFrame{S,D,I}, roadway::R) where {S,D,I,R}
add_instruction!(rendermodel, render_paint, (overlay.color,))
rendermodel
end
Empty file removed src/render_scenes.jl
Empty file.
2 changes: 1 addition & 1 deletion src/renderable.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function isrenderable end

isrenderable(object) = isrenderable(typeof(object))
isrenderable(::Type{R}) where R <: Renderable = true
isrenderable(t::Type) = method_exists(render!, Tuple{RenderModel, t})
isrenderable(t::Type) = hasmethod(render!, Tuple{RenderModel, t})
isrenderable(t::Type{Roadway}) = true

"""
Expand Down
Loading