Spaces:
Runtime error

Khunndev Cursor commited on
Commit
12c56cd
·
1 Parent(s): 445c3cc

Default groups=1, remove enhance toggle, fit circles inside pipes

Browse files
frontend/src/App.tsx CHANGED
@@ -26,8 +26,7 @@ export default function App() {
26
  const [groups, setGroups] = useState<DiameterGroup[]>([])
27
 
28
  // settings
29
- const [groupCount, setGroupCount] = useState<number | 'auto'>('auto')
30
- const [enhanceImage, setEnhanceImage] = useState(true)
31
  const [useTiling, setUseTiling] = useState(false)
32
  const [filterOutliers, setFilterOutliers] = useState(false)
33
 
@@ -75,7 +74,7 @@ export default function App() {
75
  try {
76
  const dets = await runDetection(image, {
77
  useTiling,
78
- enhanceImage,
79
  filterOutliers,
80
  autoTile: !useTiling,
81
  onProgress: setStatus,
@@ -189,7 +188,6 @@ export default function App() {
189
  busy={busy}
190
  modelReady={modelReady}
191
  groupCount={groupCount}
192
- enhanceImage={enhanceImage}
193
  useTiling={useTiling}
194
  filterOutliers={filterOutliers}
195
  onBack={resetToCapture}
@@ -197,7 +195,6 @@ export default function App() {
197
  onGallery={() => fileRef.current?.click()}
198
  onCount={runCount}
199
  onGroupCount={setGroupCount}
200
- onEnhanceImage={setEnhanceImage}
201
  onUseTiling={setUseTiling}
202
  onFilterOutliers={setFilterOutliers}
203
  onRecluster={recluster}
 
26
  const [groups, setGroups] = useState<DiameterGroup[]>([])
27
 
28
  // settings
29
+ const [groupCount, setGroupCount] = useState<number | 'auto'>(1)
 
30
  const [useTiling, setUseTiling] = useState(false)
31
  const [filterOutliers, setFilterOutliers] = useState(false)
32
 
 
74
  try {
75
  const dets = await runDetection(image, {
76
  useTiling,
77
+ enhanceImage: false,
78
  filterOutliers,
79
  autoTile: !useTiling,
80
  onProgress: setStatus,
 
188
  busy={busy}
189
  modelReady={modelReady}
190
  groupCount={groupCount}
 
191
  useTiling={useTiling}
192
  filterOutliers={filterOutliers}
193
  onBack={resetToCapture}
 
195
  onGallery={() => fileRef.current?.click()}
196
  onCount={runCount}
197
  onGroupCount={setGroupCount}
 
198
  onUseTiling={setUseTiling}
199
  onFilterOutliers={setFilterOutliers}
200
  onRecluster={recluster}
frontend/src/components/ResultCanvas.tsx CHANGED
@@ -42,6 +42,20 @@ function computeStagger(count: number): { staggerMs: number; durationMs: number
42
  return { staggerMs: 2, durationMs: 100 }
43
  }
44
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
  /**
46
  * Draw a single detection circle at full image resolution.
47
  * @param displayPx CSS pixels per canvas pixel (used to scale strokes/fonts to look right)
@@ -205,7 +219,7 @@ export function ResultCanvas({
205
  const ph = d.ymax - d.ymin
206
  const cx = d.xmin + pw / 2
207
  const cy = d.ymin + ph / 2
208
- const radius = Math.max(minR, Math.min(pw, ph) / 2)
209
 
210
  drawCircle(ctx!, cx, cy, radius, rgb, progress, String(origIdx + 1), showLabels, displayPx)
211
  visibleCount++
@@ -230,7 +244,7 @@ export function ResultCanvas({
230
  const ph = d.ymax - d.ymin
231
  const cx = d.xmin + pw / 2
232
  const cy = d.ymin + ph / 2
233
- const radius = Math.max(minR, Math.min(pw, ph) / 2)
234
  drawCircle(ctx!, cx, cy, radius, rgb, 1, String(origIdx + 1), showLabels, displayPx)
235
  })
236
  if (countDisplayRef?.current) {
@@ -279,7 +293,7 @@ export function ResultCanvas({
279
  const ph = d.ymax - d.ymin
280
  const cx = d.xmin + pw / 2
281
  const cy = d.ymin + ph / 2
282
- const radius = Math.max(minR, Math.min(pw, ph) / 2)
283
  drawCircle(ctx, cx, cy, radius, rgb, 1, String(idx + 1), showLabels, displayPx)
284
  })
285
 
@@ -321,7 +335,7 @@ export function ResultCanvas({
321
  const rgb = hexToRgb(group?.color ?? '#ef4444')
322
  const pw = d.xmax - d.xmin
323
  const ph = d.ymax - d.ymin
324
- drawCircle(ctx, d.xmin + pw / 2, d.ymin + ph / 2, Math.max(minR, Math.min(pw, ph) / 2), rgb, 1, String(idx + 1), showLabels, displayPx)
325
  })
326
 
327
  const area = areaRef.current
 
42
  return { staggerMs: 2, durationMs: 100 }
43
  }
44
 
45
+ /**
46
+ * Radius for a detection circle so it sits INSIDE the pipe's box and does not
47
+ * touch its neighbours. We leave a 12% gap and also reserve room for the stroke
48
+ * (which is centred on the path and extends outward by lineWidth/2), so the
49
+ * painted circle never spills past the box edge.
50
+ */
51
+ function fitRadius(pw: number, ph: number, minR: number): number {
52
+ const halfBox = Math.min(pw, ph) / 2
53
+ // gap so adjacent circles stay visually separated
54
+ const target = halfBox * 0.86
55
+ // never exceed the box (keeps tiny detections from overflowing too)
56
+ return Math.min(Math.max(minR, target), halfBox)
57
+ }
58
+
59
  /**
60
  * Draw a single detection circle at full image resolution.
61
  * @param displayPx CSS pixels per canvas pixel (used to scale strokes/fonts to look right)
 
219
  const ph = d.ymax - d.ymin
220
  const cx = d.xmin + pw / 2
221
  const cy = d.ymin + ph / 2
222
+ const radius = fitRadius(pw, ph, minR)
223
 
224
  drawCircle(ctx!, cx, cy, radius, rgb, progress, String(origIdx + 1), showLabels, displayPx)
225
  visibleCount++
 
244
  const ph = d.ymax - d.ymin
245
  const cx = d.xmin + pw / 2
246
  const cy = d.ymin + ph / 2
247
+ const radius = fitRadius(pw, ph, minR)
248
  drawCircle(ctx!, cx, cy, radius, rgb, 1, String(origIdx + 1), showLabels, displayPx)
249
  })
250
  if (countDisplayRef?.current) {
 
293
  const ph = d.ymax - d.ymin
294
  const cx = d.xmin + pw / 2
295
  const cy = d.ymin + ph / 2
296
+ const radius = fitRadius(pw, ph, minR)
297
  drawCircle(ctx, cx, cy, radius, rgb, 1, String(idx + 1), showLabels, displayPx)
298
  })
299
 
 
335
  const rgb = hexToRgb(group?.color ?? '#ef4444')
336
  const pw = d.xmax - d.xmin
337
  const ph = d.ymax - d.ymin
338
+ drawCircle(ctx, d.xmin + pw / 2, d.ymin + ph / 2, fitRadius(pw, ph, minR), rgb, 1, String(idx + 1), showLabels, displayPx)
339
  })
340
 
341
  const area = areaRef.current
frontend/src/components/SettingsPanel.tsx CHANGED
@@ -5,11 +5,9 @@ interface Props {
5
  lang: Lang
6
  open: boolean
7
  groupCount: number | 'auto'
8
- enhanceImage: boolean
9
  useTiling: boolean
10
  filterOutliers: boolean
11
  onGroupCount: (value: number | 'auto') => void
12
- onEnhanceImage: (value: boolean) => void
13
  onUseTiling: (value: boolean) => void
14
  onFilterOutliers: (value: boolean) => void
15
  onRecluster: () => void
@@ -70,11 +68,9 @@ export function SettingsPanel({
70
  lang,
71
  open,
72
  groupCount,
73
- enhanceImage,
74
  useTiling,
75
  filterOutliers,
76
  onGroupCount,
77
- onEnhanceImage,
78
  onUseTiling,
79
  onFilterOutliers,
80
  onRecluster,
@@ -124,12 +120,6 @@ export function SettingsPanel({
124
  {t(lang, 'settings')}
125
  </p>
126
  <div className="overflow-hidden rounded-2xl bg-white/6 ring-1 ring-white/8">
127
- <Toggle
128
- checked={enhanceImage}
129
- onChange={onEnhanceImage}
130
- label={t(lang, 'enhanceImage')}
131
- />
132
- <Separator />
133
  <Toggle
134
  checked={useTiling}
135
  onChange={onUseTiling}
 
5
  lang: Lang
6
  open: boolean
7
  groupCount: number | 'auto'
 
8
  useTiling: boolean
9
  filterOutliers: boolean
10
  onGroupCount: (value: number | 'auto') => void
 
11
  onUseTiling: (value: boolean) => void
12
  onFilterOutliers: (value: boolean) => void
13
  onRecluster: () => void
 
68
  lang,
69
  open,
70
  groupCount,
 
71
  useTiling,
72
  filterOutliers,
73
  onGroupCount,
 
74
  onUseTiling,
75
  onFilterOutliers,
76
  onRecluster,
 
120
  {t(lang, 'settings')}
121
  </p>
122
  <div className="overflow-hidden rounded-2xl bg-white/6 ring-1 ring-white/8">
 
 
 
 
 
 
123
  <Toggle
124
  checked={useTiling}
125
  onChange={onUseTiling}
frontend/src/components/StepPreview.tsx CHANGED
@@ -10,7 +10,6 @@ interface Props {
10
  busy: boolean
11
  modelReady: boolean
12
  groupCount: number | 'auto'
13
- enhanceImage: boolean
14
  useTiling: boolean
15
  filterOutliers: boolean
16
  onBack: () => void
@@ -18,7 +17,6 @@ interface Props {
18
  onGallery: () => void
19
  onCount: () => void
20
  onGroupCount: (v: number | 'auto') => void
21
- onEnhanceImage: (v: boolean) => void
22
  onUseTiling: (v: boolean) => void
23
  onFilterOutliers: (v: boolean) => void
24
  onRecluster: () => void
@@ -31,7 +29,6 @@ export function StepPreview({
31
  busy,
32
  modelReady,
33
  groupCount,
34
- enhanceImage,
35
  useTiling,
36
  filterOutliers,
37
  onBack,
@@ -39,7 +36,6 @@ export function StepPreview({
39
  onGallery,
40
  onCount,
41
  onGroupCount,
42
- onEnhanceImage,
43
  onUseTiling,
44
  onFilterOutliers,
45
  onRecluster,
@@ -99,11 +95,9 @@ export function StepPreview({
99
  lang={lang}
100
  open={true}
101
  groupCount={groupCount}
102
- enhanceImage={enhanceImage}
103
  useTiling={useTiling}
104
  filterOutliers={filterOutliers}
105
  onGroupCount={onGroupCount}
106
- onEnhanceImage={onEnhanceImage}
107
  onUseTiling={onUseTiling}
108
  onFilterOutliers={onFilterOutliers}
109
  onRecluster={onRecluster}
 
10
  busy: boolean
11
  modelReady: boolean
12
  groupCount: number | 'auto'
 
13
  useTiling: boolean
14
  filterOutliers: boolean
15
  onBack: () => void
 
17
  onGallery: () => void
18
  onCount: () => void
19
  onGroupCount: (v: number | 'auto') => void
 
20
  onUseTiling: (v: boolean) => void
21
  onFilterOutliers: (v: boolean) => void
22
  onRecluster: () => void
 
29
  busy,
30
  modelReady,
31
  groupCount,
 
32
  useTiling,
33
  filterOutliers,
34
  onBack,
 
36
  onGallery,
37
  onCount,
38
  onGroupCount,
 
39
  onUseTiling,
40
  onFilterOutliers,
41
  onRecluster,
 
95
  lang={lang}
96
  open={true}
97
  groupCount={groupCount}
 
98
  useTiling={useTiling}
99
  filterOutliers={filterOutliers}
100
  onGroupCount={onGroupCount}
 
101
  onUseTiling={onUseTiling}
102
  onFilterOutliers={onFilterOutliers}
103
  onRecluster={onRecluster}