1
0
Fork 0
mirror of https://gitlab.rlp.net/mobitar/ReCo.jl.git synced 2024-09-19 19:01:17 +00:00

Debugging additions seperation

This commit is contained in:
Mo8it 2022-01-06 01:49:54 +01:00
parent 6f7d7fef37
commit f429f03237

View file

@ -26,13 +26,16 @@ function animate_bundle!(args, sim_consts)
color = get(args.color_scheme, rem2pi(bundle_φ[i, frame], RoundDown) / π2) color = get(args.color_scheme, rem2pi(bundle_φ[i, frame], RoundDown) / π2)
args.colors[][i] = RGBAf(color) args.colors[][i] = RGBAf(color)
if args.debug if args.show_interaction_circle
args.interaction_circles[][i] = Circle( args.interaction_circles[][i] = Circle(
Point2(c[1], c[2]), sim_consts.interaction_r Point2(c[1], c[2]), sim_consts.interaction_r
) )
args.interaction_colors[][i] = RGBAf(color, 0.08)
end
if args.show_skin_circle
args.skin_circles[][i] = Circle(Point2(c[1], c[2]), sim_consts.skin_r) args.skin_circles[][i] = Circle(Point2(c[1], c[2]), sim_consts.skin_r)
args.interaction_colors[][i] = RGBAf(color, 0.08)
args.skin_colors[][i] = RGBAf(color, 0.04) args.skin_colors[][i] = RGBAf(color, 0.04)
end end
end end
@ -47,21 +50,24 @@ function animate_bundle!(args, sim_consts)
) )
end end
if args.n_bundle == 1 if args.n_bundle == 1 # First and only frame of first bundle
poly!(args.ax, args.circles; color=args.colors) poly!(args.ax, args.circles; color=args.colors)
if args.show_center_of_mass if args.show_center_of_mass
poly!(args.ax, args.center_of_mass_circle; color=RGBAf(1, 1, 1, 0.5)) poly!(args.ax, args.center_of_mass_circle; color=RGBAf(1, 1, 1, 0.5))
end end
if args.debug if args.show_interaction_circle
poly!(args.ax, args.interaction_circles; color=args.interaction_colors) poly!(args.ax, args.interaction_circles; color=args.interaction_colors)
end
if args.show_skin_circle
poly!(args.ax, args.skin_circles; color=args.skin_colors) poly!(args.ax, args.skin_circles; color=args.skin_colors)
end end
println("Recording started!") println("Recording started!")
else else
if args.debug && frame > 1 if args.show_frame_diff && frame > 1
@simd for i in 1:(sim_consts.n_particles) @simd for i in 1:(sim_consts.n_particles)
first_ind = 2 * i - 1 first_ind = 2 * i - 1
second_ind = 2 * i second_ind = 2 * i
@ -79,6 +85,9 @@ function animate_bundle!(args, sim_consts)
args.ax, args.segments_x, args.segments_y; color=args.colors args.ax, args.segments_x, args.segments_y; color=args.colors
) )
end end
notify(args.segments_x)
notify(args.segments_y)
end end
notify(args.circles) notify(args.circles)
@ -88,15 +97,14 @@ function animate_bundle!(args, sim_consts)
notify(args.center_of_mass_circle) notify(args.center_of_mass_circle)
end end
if args.debug && frame > 1 if args.show_interaction_circle
notify(args.interaction_circles) notify(args.interaction_circles)
notify(args.interaction_colors) notify(args.interaction_colors)
end
if args.show_skin_circle
notify(args.skin_circles) notify(args.skin_circles)
notify(args.skin_colors) notify(args.skin_colors)
notify(args.segments_x)
notify(args.segments_y)
end end
end end
@ -108,8 +116,32 @@ function animate_bundle!(args, sim_consts)
return nothing return nothing
end end
function sort_bundle_paths(bundle_paths::Vector{String})
n_bundles = length(bundle_paths)
bundle_nums = Vector{Int64}(undef, n_bundles)
extension_length = 5 # == length(".jld2")
for i in 1:n_bundles
bundle_path = bundle_paths[i]
bundle_num_string = bundle_path[(findfirst("bundle_", s).stop + 1):(end - extension_length)]
bundle_nums[i] = parse(Int64, bundle_num_string)
end
sort_perm = sortperm(bundle_nums)
return bundle_paths[sort_perm]
end
function animate_with_sim_consts( function animate_with_sim_consts(
dir::String, sim_consts, framerate::Int64, show_center_of_mass::Bool, debug::Bool dir::String,
sim_consts,
framerate::Int64,
show_center_of_mass::Bool,
show_interaction_circle::Bool,
show_skin_circle::Bool,
show_frame_diff::Bool,
) )
set_theme!(theme_black()) set_theme!(theme_black())
@ -153,26 +185,24 @@ function animate_with_sim_consts(
) )
end end
if debug if show_interaction_circle
segments_x = Observable(zeros(2 * n_particles))
segments_y = Observable(zeros(2 * n_particles))
interaction_circles = Observable(Vector{Circle}(undef, n_particles)) interaction_circles = Observable(Vector{Circle}(undef, n_particles))
skin_circles = Observable(Vector{Circle}(undef, n_particles)) skin_circles = Observable(Vector{Circle}(undef, n_particles))
end
if show_skin_circle
interaction_colors = Observable(Vector{RGBAf}(undef, n_particles)) interaction_colors = Observable(Vector{RGBAf}(undef, n_particles))
skin_colors = Observable(Vector{RGBAf}(undef, n_particles)) skin_colors = Observable(Vector{RGBAf}(undef, n_particles))
end end
if show_frame_diff
segments_x = Observable(zeros(2 * n_particles))
segments_y = Observable(zeros(2 * n_particles))
end
bundle_paths = readdir("$dir/bundles"; join=true, sort=false) bundle_paths = readdir("$dir/bundles"; join=true, sort=false)
sort_perm = sortperm([ bundle_paths = sort_bundle_paths(bundle_paths)
parse(Int64, s[(findfirst("bundle_", s).stop + 1):(end - length(".jld2"))]) for
s in bundle_paths
])
bundle_paths = bundle_paths[sort_perm]
sort_perm = nothing
@showprogress 1 for (n_bundle, bundle_path) in enumerate(bundle_paths) @showprogress 1 for (n_bundle, bundle_path) in enumerate(bundle_paths)
bundle::Bundle = JLD2.load_object(bundle_path) bundle::Bundle = JLD2.load_object(bundle_path)
@ -180,7 +210,9 @@ function animate_with_sim_consts(
args = (; args = (;
# Input # Input
show_center_of_mass, show_center_of_mass,
debug, show_interaction_circle,
show_skin_circle,
show_frame_diff,
# Intern # Intern
io, io,
ax, ax,
@ -207,13 +239,26 @@ function animate_with_sim_consts(
end end
function animate( function animate(
dir::String; framerate::Int64=1, show_center_of_mass::Bool=false, debug::Bool=false dir::String;
framerate::Int64=1,
show_center_of_mass::Bool=false,
show_interaction_circle::Bool=false,
show_skin_circle::Bool=false,
show_frame_diff::Bool=false,
) )
println("Generating animation...") println("Generating animation...")
sim_consts = JSON3.read(read("$dir/sim_consts.json", String)) sim_consts = JSON3.read(read("$dir/sim_consts.json", String))
animate_with_sim_consts(dir, sim_consts, framerate, show_center_of_mass, debug) animate_with_sim_consts(
dir,
sim_consts,
framerate,
show_center_of_mass,
show_interaction_circle,
show_skin_circle,
show_frame_diff,
)
println("Animation done.") println("Animation done.")