path change
This commit is contained in:
@@ -15,6 +15,8 @@ import { DeleteConfirmModal } from "../components/annotate/DeleteConfirmModal";
|
||||
import { drawOverlay, colorForClass } from "../components/extract/overlay";
|
||||
import type { Settings } from "../types";
|
||||
|
||||
const DEFAULT_CLASS_ID = 0;
|
||||
|
||||
interface Props {
|
||||
username: string;
|
||||
settings: Settings | null;
|
||||
@@ -30,10 +32,10 @@ type Tool = "select" | "bbox" | "polygon";
|
||||
type InProgress =
|
||||
| { type: "bbox"; start: [number, number]; end: [number, number] }
|
||||
| {
|
||||
type: "polygon";
|
||||
points: [number, number][];
|
||||
cursor: [number, number] | null;
|
||||
};
|
||||
type: "polygon";
|
||||
points: [number, number][];
|
||||
cursor: [number, number] | null;
|
||||
};
|
||||
|
||||
type BboxHandle = "body" | "tl" | "tr" | "bl" | "br" | "t" | "b" | "l" | "r";
|
||||
|
||||
@@ -63,7 +65,7 @@ function uuid(): string {
|
||||
try {
|
||||
const c = (globalThis as unknown as { crypto?: { randomUUID?: () => string } }).crypto;
|
||||
if (c && typeof c.randomUUID === "function") return c.randomUUID();
|
||||
} catch {}
|
||||
} catch { }
|
||||
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, (ch) => {
|
||||
const r = (Math.random() * 16) | 0;
|
||||
const v = ch === "x" ? r : (r & 0x3) | 0x8;
|
||||
@@ -392,15 +394,15 @@ export function AnnotateMode({ username, settings }: Props) {
|
||||
if (cancelled) return;
|
||||
setAnn(
|
||||
loaded ??
|
||||
(dims
|
||||
? {
|
||||
version: 1,
|
||||
image: selectedImagePath.split("/").pop() ?? "",
|
||||
width: dims.w,
|
||||
height: dims.h,
|
||||
annotations: [],
|
||||
}
|
||||
: null)
|
||||
(dims
|
||||
? {
|
||||
version: 1,
|
||||
image: selectedImagePath.split("/").pop() ?? "",
|
||||
width: dims.w,
|
||||
height: dims.h,
|
||||
annotations: [],
|
||||
}
|
||||
: null)
|
||||
);
|
||||
})
|
||||
.catch((e) => {
|
||||
@@ -420,7 +422,7 @@ export function AnnotateMode({ username, settings }: Props) {
|
||||
// Hold a ref to the latest drawCanvas so the image-change effect can call
|
||||
// it without subscribing to its identity (which flips on every `drawing` /
|
||||
// `ann` / `overlayVisible` change and would reset state mid-interaction).
|
||||
const drawCanvasRef = useRef<() => void>(() => {});
|
||||
const drawCanvasRef = useRef<() => void>(() => { });
|
||||
useEffect(() => {
|
||||
drawCanvasRef.current = drawCanvas;
|
||||
}, [drawCanvas]);
|
||||
@@ -745,12 +747,12 @@ export function AnnotateMode({ username, settings }: Props) {
|
||||
annotations: ann.annotations.map((a) =>
|
||||
a.id === selectedAnnId
|
||||
? {
|
||||
...a,
|
||||
class_id: cid,
|
||||
class_name: className,
|
||||
author: username,
|
||||
updated_at: now,
|
||||
}
|
||||
...a,
|
||||
class_id: cid,
|
||||
class_name: className,
|
||||
author: username,
|
||||
updated_at: now,
|
||||
}
|
||||
: a
|
||||
),
|
||||
};
|
||||
@@ -761,7 +763,7 @@ export function AnnotateMode({ username, settings }: Props) {
|
||||
return (
|
||||
classesRef.current[classId] ??
|
||||
classes[classId] ??
|
||||
`class_${classId}`
|
||||
"Object"
|
||||
);
|
||||
}
|
||||
|
||||
@@ -940,10 +942,12 @@ export function AnnotateMode({ username, settings }: Props) {
|
||||
setSelectedAnnId(null);
|
||||
return;
|
||||
}
|
||||
if (activeClassId == null) {
|
||||
setStatusMsg("Pick a class on the right first");
|
||||
return;
|
||||
}
|
||||
// if (activeClassId == null) {
|
||||
// setStatusMsg("Pick a class on the right first");
|
||||
// return;
|
||||
// }
|
||||
const classId = activeClassId ?? DEFAULT_CLASS_ID;
|
||||
|
||||
e.stopPropagation(); // don't let the pan handler see this
|
||||
const p = canvasToImageCoords(e.clientX, e.clientY);
|
||||
if (!p) return;
|
||||
@@ -1343,8 +1347,8 @@ export function AnnotateMode({ username, settings }: Props) {
|
||||
tool === "bbox" || tool === "polygon"
|
||||
? "crosshair"
|
||||
: zoom > 1
|
||||
? "grab"
|
||||
: "default";
|
||||
? "grab"
|
||||
: "default";
|
||||
|
||||
return (
|
||||
<div className={`annotate-mode${frameInfoHidden ? " frame-info-hidden" : ""}`}>
|
||||
@@ -1524,8 +1528,8 @@ export function AnnotateMode({ username, settings }: Props) {
|
||||
pending.kind === "new-bbox"
|
||||
? "new-bbox"
|
||||
: pending.kind === "new-polygon"
|
||||
? "new-polygon"
|
||||
: "reclass"
|
||||
? "new-polygon"
|
||||
: "reclass"
|
||||
}
|
||||
onConfirm={(cid) => {
|
||||
commitPending(cid);
|
||||
@@ -1773,9 +1777,9 @@ function drawBboxHandles(
|
||||
const [x, y, w, h] = bbox;
|
||||
const r = Math.max(5, 5 * screenToImage);
|
||||
const pts: [number, number][] = [
|
||||
[x, y], [x + w / 2, y], [x + w, y],
|
||||
[x, y + h / 2], [x + w, y + h / 2],
|
||||
[x, y + h], [x + w / 2, y + h], [x + w, y + h],
|
||||
[x, y], [x + w / 2, y], [x + w, y],
|
||||
[x, y + h / 2], [x + w, y + h / 2],
|
||||
[x, y + h], [x + w / 2, y + h], [x + w, y + h],
|
||||
];
|
||||
ctx.save();
|
||||
ctx.setLineDash([]);
|
||||
@@ -1810,16 +1814,16 @@ function annotationsToShapes(annotations: Annotation[]): CocoShape[] {
|
||||
return annotations.map((a) =>
|
||||
a.type === "bbox"
|
||||
? {
|
||||
type: "bbox",
|
||||
class_id: a.class_id,
|
||||
class_name: a.class_name,
|
||||
bbox: a.bbox,
|
||||
}
|
||||
type: "bbox",
|
||||
class_id: a.class_id,
|
||||
class_name: a.class_name,
|
||||
bbox: a.bbox,
|
||||
}
|
||||
: {
|
||||
type: "polygon",
|
||||
class_id: a.class_id,
|
||||
class_name: a.class_name,
|
||||
points: a.points,
|
||||
}
|
||||
type: "polygon",
|
||||
class_id: a.class_id,
|
||||
class_name: a.class_name,
|
||||
points: a.points,
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user