| 62 ################ |
63 ################ |
| 63 # Visualisation |
64 # Visualisation |
| 64 ################ |
65 ################ |
| 65 |
66 |
| 66 function bg_visualise(rc) |
67 function bg_visualise(rc) |
| 67 while true |
68 process_channel(do_visualise, rc) |
| 68 imgs=take!(rc) |
|
| 69 # Take only the latest image to visualise |
|
| 70 while isready(rc) |
|
| 71 imgs=take!(rc) |
|
| 72 end |
|
| 73 # We're done if we were fed an empty image |
|
| 74 if isnothing(imgs) |
|
| 75 break |
|
| 76 end |
|
| 77 do_visualise(imgs) |
|
| 78 end |
|
| 79 return |
|
| 80 end |
69 end |
| 81 |
70 |
| 82 # function do_visualise(imgs) |
71 # function do_visualise(imgs) |
| 83 # plt = im -> plot(grayimg(im), showaxis=false, grid=false, aspect_ratio=:equal, margin=2mm) |
72 # plt = im -> plot(grayimg(im), showaxis=false, grid=false, aspect_ratio=:equal, margin=2mm) |
| 84 # display(plot([plt(imgs[i]) for i =1:length(imgs)]..., reuse=true, margin=0mm)) |
73 # display(plot([plt(imgs[i]) for i =1:length(imgs)]..., reuse=true, margin=0mm)) |
| 87 grayGR = x -> begin |
76 grayGR = x -> begin |
| 88 y = round(UInt32, 0xff*clip(x)) |
77 y = round(UInt32, 0xff*clip(x)) |
| 89 return 0x010101*y + 0xff000000 |
78 return 0x010101*y + 0xff000000 |
| 90 end |
79 end |
| 91 |
80 |
| 92 function do_visualise(imgs) |
81 function do_visualise(imgs; refresh=true) |
| 93 n = length(imgs) |
82 n = length(imgs) |
| 94 # Get device dimensions in metres and pixels |
83 # Get device dimensions in metres and pixels |
| 95 scrw, scrh, pw, ph = GR.inqdspsize() |
84 scrw, scrh, pw, ph = GR.inqdspsize() |
| 96 # Scaling to maximums ize window |
85 # Scaling to maximums ize window |
| 97 sc=0.7 |
86 sc=0.7 |
| 114 for i=1:n |
103 for i=1:n |
| 115 im = imgs[i]' |
104 im = imgs[i]' |
| 116 sz = size(im) |
105 sz = size(im) |
| 117 GR.drawimage(i-1, i, 0, 1, sz[1], sz[2], grayGR.(im)) |
106 GR.drawimage(i-1, i, 0, 1, sz[1], sz[2], grayGR.(im)) |
| 118 end |
107 end |
| 119 GR.updatews() |
108 if refresh |
| |
109 GR.updatews() |
| |
110 end |
| 120 end |
111 end |
| 121 |
112 |
| 122 function visualise(channel_or_toggle, imgs) |
113 function visualise(channel_or_toggle, imgs) |
| 123 if isa(channel_or_toggle, Channel) |
114 if isa(channel_or_toggle, Channel) |
| 124 rc = channel_or_toggle |
115 put_onlylatest!(channel_or_toggle, imgs) |
| 125 while isready(rc) |
|
| 126 take!(rc) |
|
| 127 end |
|
| 128 put!(rc, imgs) |
|
| 129 elseif isa(channel_or_toggle, Bool) && channel_or_toggle |
116 elseif isa(channel_or_toggle, Bool) && channel_or_toggle |
| 130 do_visualise(imgs) |
117 do_visualise(imgs) |
| 131 end |
118 end |
| 132 end |
119 end |
| 133 |
120 |