Skip to content
Snippets Groups Projects
Commit f0524fe6 authored by François  LAURENT's avatar François LAURENT
Browse files

minor refacto

parent 178fe0d8
No related branches found
No related tags found
No related merge requests found
Pipeline #73405 failed with stage
in 37 seconds
......@@ -11,7 +11,7 @@ To run `LarvaTagger.jl`, you will need `julia>=1.6` and a `trx.mat` file in a fr
## Install
In a fresh directory:
```
julia --project=. -e 'using Pkg; Pkg.add(["https://gitlab.pasteur.fr/nyx/planarlarvae.jl.git","https://gitlab.pasteur.fr/nyx/larvatagger.jl.git"])
julia --project=. -e 'using Pkg; Pkg.add(["https://gitlab.pasteur.fr/nyx/planarlarvae.jl.git","https://gitlab.pasteur.fr/nyx/larvatagger.jl.git"])'
```
Take note of the location of your new virtual environment, associated with the local directory (`--project=.`).
......
......@@ -9,7 +9,7 @@ using Statistics
using Observables
using Meshes
export larvaviewer
export larvaviewer#, larvaeditor
include("sources.jl")
include("models.jl")
......@@ -19,26 +19,11 @@ include("controllers.jl")
include("viewers.jl")
function larvaviewer(path)
tag_lut = Dict(
:small_motion => :grey90,
:stop_large => :green,
:run_large => :black,
:cast_large => :red,
:hunch_large => :blue,
:back_large => :cyan,
:roll_large => :yellow,
)
# read the data
datasources = loaddata(path)
# simplify
_, data = first(datasources[:trx].data)
# preprocess
times = PlanarLarvae.times(data)
model = [LarvaModel(id, ts, tag_lut, times) for (id, ts) in pairs(data)]
# view
model, ctrl = load_trx_large(path)
scene = Figure()
larvaplayer!(scene, model, tag_lut, times)
# main loop
# playercontrols must be called before larvaviewer!
scene.layout[2, 1] = playercontrols(scene, ctrl.player)
larvaviewer!(scene.layout[1, 1], model, ctrl)
return scene
end
......
......@@ -104,6 +104,11 @@ gettime(controller::Animator, step::Int) = controller.times[step]
)
end
"""
playercontrols(gridpos, animator)
Important note: must be called _before_ `larvaviewer!`
"""
function playercontrols(scene, controller::Animator)
bind!(controller, scene)
times = controller.times
......
......@@ -37,9 +37,10 @@ function Makie.plot!(larva::LarvaPlot{<:MinimalLarva})
return larva
end
function gettag(tag_lut, tags, default_color)
function gettag(tag_lut, state, default_color)
haskey(state, :tags) || return (nothing, default_color)
tags′ = collect(keys(tag_lut))
tags = tags′ tags.tags
tags = tags′ state.tags
if isempty(tags)
return (nothing, default_color)
else
......
@recipe(LarvaViewer) do scene
Theme(
:show_grid => false,
)
end
##
function larvaplayer!(scene, model, tag_lut, times)
ctrl = GeneralController(model, tag_lut, times)
mainview = Axis(scene.layout[1, 1], aspect=DataAspect())
scene.layout[2, 1] = playercontrols(scene, ctrl.player)
views = nothing
function Makie.plot!(viewer::LarvaViewer{Tuple{Vector{<:LarvaModel}, <:GeneralController}})
throw(ErrorException("use larvaviewer! instead"))
end
function larvaviewer!(view, model, ctrl)
if view isa Axis
# ok
elseif view isa GridPosition
view = Axis(view, aspect=DataAspect())
elseif view isa Figure
view = Axis(view.layout[1, 1], aspect=DataAspect())
else
throw(ErrorException("not implemented for view type $(typeof(view))"))
end
childviews = nothing
for larva in model
@debug "initializing larva $(larva.id)"
plot = larvaplot!(mainview, larva, ctrl)
plot = larvaplot!(view, larva, ctrl)
# store
if isnothing(views)
views = Dict{LarvaID, typeof(plot)}()
if isnothing(childviews)
childviews = Dict{LarvaID, typeof(plot)}()
end
views[larva.id] = plot
childviews[larva.id] = plot
end
@debug "all larvae ok"
setbounds!(mainview, ctrl, model)
setbounds!(view, ctrl, model)
@debug "main view ok"
DataInspector(mainview, range=2, textsize=14)
DataInspector(view, range=2, textsize=14)
@debug "inspector ok"
setmouseevents!(mainview, views, ctrl)
setkeyboardevents!(mainview, views, ctrl)
# initial state
timestep!(ctrl, 1)
setmouseevents!(view, childviews, ctrl)
setkeyboardevents!(view, childviews, ctrl)
@debug "event handling ok"
#hidedecorations!(view)
return (view=view, childviews=childviews)
end
function load_trx_large(path)
tag_lut = Dict(
:small_motion => :grey90,
:stop_large => :green,
:run_large => :black,
:cast_large => :red,
:hunch_large => :blue,
:back_large => :cyan,
:roll_large => :yellow,
)
# read the data
datasources = loaddata(path)
# simplify
_, data = first(datasources[:trx].data)
# preprocess
times = PlanarLarvae.times(data)
model = [LarvaModel(id, ts, tag_lut, times) for (id, ts) in pairs(data)]
#
ctrl = GeneralController(model, tag_lut, times)
#
return (model=model, controller=ctrl)
end
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment