1 | // TODO: call fullyConfigured in normal constructor |
2 | // (so we don't end up erroneously making EMPTY G22ShapeCollectorPanel's) |
3 | sclass G22ShapeCollectorPanel > MetaWithChangeListeners is Swingable { |
4 | settable G22Utils g22utils; |
5 | settable bool qoiAlways; |
6 | settableWithVar S imageSourceDesc = "Left screen half"; |
7 | |
8 | AnalyzedImage completedImage; |
9 | |
10 | // seconds per gradient color cycle |
11 | settable double gradientCycleTime = 2.0; |
12 | |
13 | settable int maxDrift = 100; |
14 | new MouseInComponentMonitor mouseMonitor; |
15 | PicturesByMD5 pics; |
16 | new JMaxSpeedAnimation anim; |
17 | JCheckBox cbOn = jcheckbox("On", true); |
18 | //JCheckBox cbFreezeOnHover = jcheckbox("Freeze on hover", true); |
19 | JCheckBox cbAnimateGradients = jcheckbox("Animate gradients", false); |
20 | JSpinner colorsSpinner = jListSpinner(itemPlus(2, dropFirst(firstNCubes(16)))); |
21 | JSpinner blurSpinner = jSpinner(0, 0, 99); |
22 | JLabel lblStats = rightAlignedLabel(); |
23 | JSlider driftSlider; |
24 | JCheckBox cbAntiDrift = jcheckbox("Antidrift", true); |
25 | |
26 | class AnalyzedImage extends G22DataWrangler { |
27 | G22DataWrangler wrangler() { this; } |
28 | |
29 | simplyCached byte[] qoiData() { |
30 | ret g22utils.timeFunction("QOI compress", |
31 | -> toQOI(inputImage())); |
32 | } |
33 | |
34 | simplyCached S qoiMD5() { |
35 | ret md5(qoiData()); |
36 | } |
37 | |
38 | S saveImage() { |
39 | pics.put(qoiMD5(), qoiData()); |
40 | ret qoiMD5(); |
41 | } |
42 | } |
43 | |
44 | void init { |
45 | if (pics != null) ret; |
46 | pics = g22utils.picturesByMD5(); |
47 | |
48 | driftSlider = jSlider(-maxDrift, maxDrift, 0); |
49 | componentPopupMenuItem(driftSlider, |
50 | "Reset", r { driftSlider.setValue(0) }); |
51 | |
52 | //looselyBindLiveValueToCheckBox(g22utils.liveProjectVar("Freeze on hover"), cbFreezeOnHover); |
53 | looselyBindLiveValueToCheckBox(g22utils.liveProjectVar("Animate gradients"), cbAnimateGradients); |
54 | looselyBindLiveValueToSpinner(g22utils.liveProjectVar("colors"), colorsSpinner); |
55 | looselyBindLiveValueToSpinner(g22utils.liveProjectVar("blur"), blurSpinner); |
56 | looselyBindLiveValueToSlider(g22utils.liveProjectVar("brightnessDrift"), driftSlider); |
57 | looselyBindLiveValueToCheckBox(g22utils.liveProjectVar("Antidrift"), cbAntiDrift); |
58 | } |
59 | |
60 | swappable BufferedImage nextInputImage() { |
61 | ret shootLeftScreenHalf(); |
62 | } |
63 | |
64 | selfType imageSource(IF0<BufferedImage> imageSource, S imageSourceDesc default str(imageSource)) { |
65 | nextInputImage = imageSource; |
66 | imageSourceDesc = imageSourceDesc; |
67 | this; |
68 | } |
69 | |
70 | bool running() { |
71 | ret isChecked(cbOn) |
72 | /*&& !(isChecked(cbFreezeOnHover) && mouseMonitor!)*/; |
73 | } |
74 | |
75 | BufferedImage nextFrame() { |
76 | if (!running()) { |
77 | sleepSeconds(0.1); |
78 | null; |
79 | } |
80 | |
81 | var inputImage = nextInputImage(); |
82 | new AnalyzedImage ai; |
83 | |
84 | var wrangler = ai.wrangler(); |
85 | wrangler.timings(g22utils.functionTimings()); |
86 | wrangler.inputImage(inputImage); |
87 | wrangler.colors(intFromSpinner(colorsSpinner)); |
88 | wrangler.blur(intFromSpinner(blurSpinner)); |
89 | |
90 | // drift is between -1 and 1 |
91 | var drift = (float) (intFromSlider(driftSlider)/100.0); |
92 | if (isChecked(cbAnimateGradients)) |
93 | drift = (float) transformFromZeroToOne(-1, 1, frac(sysSeconds()/gradientCycleTime)); |
94 | |
95 | wrangler.drift(drift); |
96 | wrangler.antiDrift(isChecked(cbAntiDrift) || isChecked(cbAnimateGradients) ? -drift : 0); |
97 | |
98 | wrangler.stepUntilStage(wrangler.regionsStage); |
99 | g22utils.setTransientProjectVar("Last wrangler", wrangler); |
100 | |
101 | L qoiInfo = !qoiAlways ? null : ll( |
102 | "QOI: " + str_toK(l(ai.qoiData())), |
103 | "Hash: " + takeFirst(3, ai.qoiMD5()), |
104 | "Saved: " + yesNo_short(pics.has(ai.qoiMD5()))); |
105 | |
106 | setText(lblStats, commaCombine( |
107 | anim.fps(), |
108 | nRegions(wrangler.regions), |
109 | qoiInfo, |
110 | nImages(pics.imageCount()) + " saved", |
111 | n2(countConcepts(g22utils.concepts(), G22PointOfInterest), "POI") |
112 | ); |
113 | |
114 | completedImage = ai; |
115 | g22utils.setTransientProjectVar("Last analyzed image", ai); |
116 | ret toBufferedImage(wrangler.posterizedImage); |
117 | } |
118 | |
119 | cachedVisualize { |
120 | init(); |
121 | |
122 | anim.renderFrame(l0 nextFrame); |
123 | |
124 | mouseMonitor.init(anim.imageSurface()); |
125 | |
126 | // UI main layout |
127 | |
128 | ret northAndCenterWithMargins( |
129 | northAndCenterWithMargin( |
130 | jcenteredline(withLabel("Watching:", liveValueLabel(varImageSourceDesc()))), |
131 | jCenteredSection(" Visual Controls ", |
132 | jHigherScrollPane_borderless_center(withSideMargin( |
133 | jcenteredline( |
134 | cbOn, //cbFreezeOnHover, |
135 | jCenteredSection("Colors", colorsSpinner), |
136 | jCenteredSection("Blur", blurSpinner), |
137 | cbAnimateGradients, |
138 | jCenteredSection("Drift", driftSlider), |
139 | cbAntiDrift, |
140 | ) |
141 | )))), |
142 | centerAndSouthWithMargin( |
143 | jCenteredSection(" What I See ", anim), |
144 | centerAndEastWithMargin(lblStats, |
145 | jThreadedButton("Save image", -> { |
146 | completedImage?.saveImage(); |
147 | }))) |
148 | ); |
149 | } |
150 | |
151 | ImageSurface imageSurface() { |
152 | ret anim.imageSurface(); |
153 | } |
154 | |
155 | static G22ShapeCollectorPanel fullyConfigured(G22Utils g22utils) { |
156 | ret (G22ShapeCollectorPanel) g22utils.leftArrow([[ |
157 | collector <- new G22ShapeCollectorPanel, g22utils < g22utils |
158 | collector visualize |
159 | is <- collector imageSurface |
160 | hoveringOverRegion <- new Var<IImageRegion> |
161 | is addOverlay < G2Drawable g -> { |
162 | region <- hoveringOverRegion get |
163 | if notNull region { |
164 | //zoomGraphics g (is zoomY) (is zoomY) |
165 | for outline in g22_allBorderTraces_autoDiagonals region { |
166 | for p in outline { |
167 | p <- scalePt p (is zoomY) (is zoomY) |
168 | //drawPixel g p < Color green |
169 | fillRect g (Color green) (p x) (p y) (iceil < is zoomX) (iceil < is zoomY) |
170 | } |
171 | } |
172 | } |
173 | } |
174 | |
175 | collector anim, displayNewImage <- IVF1 image -> { |
176 | pt <- is mousePosition |
177 | if isNull pt { |
178 | hoveringOverRegion clear |
179 | } else { |
180 | ai <- collector completedImage |
181 | regionMaker <- ai wrangler, regionMaker |
182 | hoveringOverRegion set < |
183 | regionMaker getRegion < regionMaker regionAt pt |
184 | // TODO: doesn't work like this |
185 | // if not < collector running { is repaint } |
186 | } |
187 | //toolTip is hoveringOverRegion |
188 | collector anim, displayNewImage_base image |
189 | } |
190 | |
191 | is imageSurfaceOnLeftClick < IVF1 pt -> { |
192 | region <- hoveringOverRegion get |
193 | if isNull region { ret } |
194 | ai <- collector completedImage |
195 | md5 <- ai saveImage |
196 | poi <- new G22PointOfInterest |
197 | poi imageMD5 <- md5 |
198 | poi pt <- pt |
199 | poi bnpSettings <- ai wrangler, bnpSettings |
200 | poi source <- spaceCombine "Clicked" (byUser) "on" ( ymdWithSlashes) |
201 | registerConcept (concepts) poi |
202 | } |
203 | |
204 | collector |
205 | ]]); |
206 | } |
207 | } |
Began life as a copy of #1035943
download show line numbers debug dex old transpilations
Travelled to 1 computer(s): mqqgnosmbjvj
No comments. add comment
Snippet ID: | #1036105 |
Snippet name: | G22ShapeCollectorPanel backup before screen parts |
Eternal ID of this version: | #1036105/1 |
Text MD5: | 75d039ccb69bc91c6336ec191caaa3dd |
Author: | stefan |
Category: | javax / gazelle 22 |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-09-15 18:24:08 |
Source code size: | 7032 bytes / 207 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 117 / 124 |
Referenced in: | [show references] |