Skip to content

Instantly share code, notes, and snippets.

@zsunberg
Last active February 26, 2018 19:36
Show Gist options
  • Save zsunberg/e54a58825f9f2267bd16cd8e8c179ea6 to your computer and use it in GitHub Desktop.
Save zsunberg/e54a58825f9f2267bd16cd8e8c179ea6 to your computer and use it in GitHub Desktop.

AutoViz.jl

A package for rendering simple scenes primarily consisting of cars on roadways using Cairo.

Usage

The main function is

render(scene)

where scene is an iterable of renderable objects including cars and roadways.

Example:

roadway = gen_straight_roadway(3, 100.0)
car = ArrowCar([0.0, 0.0], 0.0, color=colorant"blue") # [north, east], angle
render([roadway, car, "some text"])

Renderable

What does it mean to be "renderable"?

An object is directly renderable if the function render!(rm::RenderModel, object) is implemented for it.

An object is renderable by conversion if convert(Renderable, object) returns a directly renderable object.

When render() is invoked, direct renderability is checked with isrenderable(object), which defaults to method_exists(render!, Tuple{RenderModel, typeof(object)}). If this check fails, a conversion attempt is made with convert(Renderable, object).

Roadways and ArrowCars

The primary basic directly renderable types are Roadway (now from AutomotiveDrivingModels; soon from Roadways.jl) and ArrowCar.

ArrowCars are the pink cars with arrows that are in everyone's videos. The type will look like this:

@with_kw struct ArrowCar{A<:AbstractArray{Float64}, C<:Color}
    pos::A         = SVector(0.0, 0.0)
    angle::Float64 = 0.0
    color::C       = PINK
    text::String   = "" # some debugging text to print by the car
    id::Int        = 0
end

ArrowCar(pos::AbstractArray, angle::Float64=0.0; color=PINK, text="", id=0) = ArrowCar(pos, angle, color, "", id)

How to make types renderable

There are two ways to make renderable types.

  1. You can make your existing types renderable by conversion by defining convert(::Type{Renderable}, ::MyType) which should return a directly renderable object, e.g. an ArrowCar.
  2. You can make types directly renderable by defining render!(::RenderModel, ::MyType). To make things easier for the compiler, you can also define isrenderable(::Type{MyType}) = true. If you want to allow others to convert to this type to make their types renderable by conversion, make your type a subtype of Renderable.

Overlays

Overlays will function as in the previous version of AutoViz. They will be rendered last with render!(rendermodel, overlay, scene).

Additional keyword arguments for render()

The following additional keyword arguments will accepted by render():

  • canvas_width
  • canvas_height
  • rendermodel
  • cam - a camera controlling the field of view as in the previous version of AutoViz
@MaximeBouton
Copy link

Is the Renderable type defined in Cairo?

@zsunberg
Copy link
Author

No, Renderable will be defined in AutoViz. Cairo is lower-level. I think we want to work with Tim's good medium level RenderModel stuff.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment