Skip to content

Commit

Permalink
Merge c0ef5cc into 7d8cfd9
Browse files Browse the repository at this point in the history
  • Loading branch information
mattuntergassmair committed Nov 5, 2019
2 parents 7d8cfd9 + c0ef5cc commit c03d600
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "AutoViz"
uuid = "82aa6e0c-a491-5edf-8d4b-c16b98e4ea17"
repo = "https://github.com/sisl/AutoViz.jl.git"
version = "0.7.5"
version = "0.7.6"

[deps]
AutomotiveDrivingModels = "99497e54-f3d6-53d3-a3a9-fa9315a7f1ba"
Expand Down
33 changes: 27 additions & 6 deletions src/cameras.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,33 @@ camera_set!(rendermodel::RenderModel, cam::FitToContentCamera, scene::EntityFram
# 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)

mutable struct CarFollowCamera{I} <: Camera
"""
Camera which follows the vehicle with ID `targetid`.
By default, the target vehicle is tracked in x and y direction.
Tracking in either direction can be disabled by setting the
`follow_x` and `follow_y` keywords to false, in which case the
position defaults to `pos_default`.
The `zoom` keyword specifies the zoom level in pixels per meter.
"""
@with_kw mutable struct CarFollowCamera{I} <: Camera
targetid::I
zoom::Float64 # [pix/meter]
zoom::Float64 = 3.0 # [pix/meter]
pos_default::VecE2 = VecE2(0.,0.)
follow_x::Bool = true
follow_y::Bool = true
end
CarFollowCamera(targetid::I) where {I} = CarFollowCamera{I}(targetid, 3.0)
CarFollowCamera(targetid::I, zoom::Float64=3.0) where {I} = CarFollowCamera{I}(targetid=targetid, zoom=zoom)
CarFollowCamera{I}(targetid::I, zoom::Float64=3.0) where {I} = CarFollowCamera{I}(targetid=targetid, zoom=zoom)

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(cam.targetid, scene)
if veh_index != nothing
camera_set_pos!(rendermodel, VecE2(scene[veh_index].state.s, 0.0))
if cam.follow_x
camera_set_pos!(rendermodel, VecE2(scene[veh_index].state.s, 0.0))
else
camera_set_pos!(rendermodel, VecE2(cam.pos_default.x, 0.0))
end
camera_setzoom!(rendermodel, cam.zoom)
else
add_instruction!( rendermodel, render_text, ("CarFollowCamera did not find id $(cam.targetid)", 10, 15, 15, colorant"white"), incameraframe=false)
Expand All @@ -55,7 +71,12 @@ function camera_set!(rendermodel::RenderModel, cam::CarFollowCamera{I}, scene::E

veh_index = findfirst(cam.targetid, scene)
if veh_index != nothing
camera_set_pos!(rendermodel, scene[veh_index].state.posG)
target_pos = scene[veh_index].state.posG
camera_pos = VecSE2(
cam.follow_x ? target_pos.x : cam.pos_default.x,
cam.follow_y ? target_pos.y : cam.pos_default.y
)
camera_set_pos!(rendermodel, camera_pos)
camera_setzoom!(rendermodel, cam.zoom)
else
add_instruction!( rendermodel, render_text, ("CarFollowCamera did not find id $(cam.targetid)", 10, 15, 15, colorant"white"), incameraframe=false)
Expand Down Expand Up @@ -136,4 +157,4 @@ function camera_set!(rendermodel::RenderModel, cam::SceneFollowCamera, scene::En
end

rendermodel
end
end
10 changes: 5 additions & 5 deletions src/overlays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -127,20 +127,20 @@ end
IDOverlay
Display the ID on top of each entity in a scene.
# Fiels
- `color::Colorant` default white
- `font_size::Int64` default 15
The text can be customized with the `color::Colorant` (default=white) and `font_size::Int64` (default=15) keywords.
The position of the ID can be adjusted using `x_off::Float64` and `y_off::Float64` (in camera coordinates).
"""
@with_kw mutable struct IDOverlay <: SceneOverlay
color::Colorant = colorant"white"
font_size::Int = 15
x_off::Float64 = 0.
y_off::Float64 = 0.
end

function AutoViz.render!(rendermodel::RenderModel, overlay::IDOverlay, scene::Frame{Entity{S,D,I}}, env::E) where {S,D,I,E}
font_size = overlay.font_size
for veh in scene
add_instruction!(rendermodel, render_text, ("$(veh.id)", veh.state.posG.x, veh.state.posG.y, font_size, overlay.color), incameraframe=true)
add_instruction!(rendermodel, render_text, ("$(veh.id)", veh.state.posG.x + overlay.x_off, veh.state.posG.y + overlay.y_off, font_size, overlay.color), incameraframe=true)
end
return rendermodel
end
Expand Down

0 comments on commit c03d600

Please sign in to comment.