src/Visualise.jl

changeset 16
9b0cfc67d6cb
parent 15
6ac8641e7cfb
child 24
f6630036e588
equal deleted inserted replaced
15:6ac8641e7cfb 16:9b0cfc67d6cb
13 import GR 13 import GR
14 14
15 using AlgTools.Util 15 using AlgTools.Util
16 using AlgTools.StructTools 16 using AlgTools.StructTools
17 using AlgTools.LinkedLists 17 using AlgTools.LinkedLists
18 using AlgTools.Comms
18 19
19 ############## 20 ##############
20 # Our exports 21 # Our exports
21 ############## 22 ##############
22 23
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

mercurial