diff --git a/inspector/public/huginn-curvature.png b/inspector/public/huginn-curvature.png new file mode 100644 index 0000000..55eb1e6 Binary files /dev/null and b/inspector/public/huginn-curvature.png differ diff --git a/inspector/public/huginn-flow.png b/inspector/public/huginn-flow.png new file mode 100644 index 0000000..0cbdd99 Binary files /dev/null and b/inspector/public/huginn-flow.png differ diff --git a/inspector/public/huginn-groundtruth-alpha.png b/inspector/public/huginn-groundtruth-alpha.png new file mode 100644 index 0000000..09193ae Binary files /dev/null and b/inspector/public/huginn-groundtruth-alpha.png differ diff --git a/inspector/public/huginn-normal.png b/inspector/public/huginn-normal.png new file mode 100644 index 0000000..23ef5e0 Binary files /dev/null and b/inspector/public/huginn-normal.png differ diff --git a/inspector/src/HuginnFieldCanvas.tsx b/inspector/src/HuginnFieldCanvas.tsx index 89fbdc8..4c4a958 100644 --- a/inspector/src/HuginnFieldCanvas.tsx +++ b/inspector/src/HuginnFieldCanvas.tsx @@ -20,6 +20,11 @@ type FieldSample = { rgba: Uint8ClampedArray; luma: Float32Array; alpha: Float32Array; + analysis: Float32Array; + flowX: Float32Array; + flowY: Float32Array; + normalX: Float32Array; + normalY: Float32Array; }; type PyramidLevel = { @@ -32,12 +37,19 @@ type PyramidLevel = { curve: Float32Array; }; -const FIELD_SIZE = 64; +const FIELD_SIZE = 256; const MAX_DEPTH = 6; -const MIN_BRUSH_SIZE = 2; -const ENERGY_SPLIT_THRESHOLD = 0.045; +const MIN_BRUSH_SIZE = 4; +const ENERGY_SPLIT_THRESHOLD = 0.038; -export function HuginnFieldCanvas({ imageUrl }: { imageUrl: string }) { +type HuginnFieldCanvasProps = { + imageUrl: string; + curvatureUrl?: string; + flowUrl?: string; + normalUrl?: string; +}; + +export function HuginnFieldCanvas({ imageUrl, curvatureUrl, flowUrl, normalUrl }: HuginnFieldCanvasProps) { const canvasRef = useRef(null); useEffect(() => { @@ -47,28 +59,29 @@ export function HuginnFieldCanvas({ imageUrl }: { imageUrl: string }) { } let cancelled = false; - const image = new Image(); - image.decoding = "async"; - image.src = imageUrl; - const render = async () => { try { - await image.decode(); + const [image, curvatureImage, flowImage, normalImage] = await Promise.all([ + loadImage(imageUrl), + curvatureUrl ? loadImage(curvatureUrl) : Promise.resolve(undefined), + flowUrl ? loadImage(flowUrl) : Promise.resolve(undefined), + normalUrl ? loadImage(normalUrl) : Promise.resolve(undefined), + ]); + if (cancelled) { + return; + } + + const sample = sampleImage(image, curvatureImage, flowImage, normalImage); + const pyramid = buildCurvaturePyramid(sample); + const brushes = buildBrushes(sample, pyramid); + const observer = new ResizeObserver(() => drawField(canvas, brushes, sample)); + observer.observe(canvas); + drawField(canvas, brushes, sample); + + return () => observer.disconnect(); } catch { return; } - if (cancelled) { - return; - } - - const sample = sampleImage(image); - const pyramid = buildCurvaturePyramid(sample); - const brushes = buildBrushes(sample, pyramid); - const observer = new ResizeObserver(() => drawField(canvas, brushes, sample)); - observer.observe(canvas); - drawField(canvas, brushes, sample); - - return () => observer.disconnect(); }; let cleanup: (() => void) | undefined; @@ -80,12 +93,56 @@ export function HuginnFieldCanvas({ imageUrl }: { imageUrl: string }) { cancelled = true; cleanup?.(); }; - }, [imageUrl]); + }, [curvatureUrl, flowUrl, imageUrl, normalUrl]); return