Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions examples/src/dzi/dziView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,26 +16,10 @@ import { Vec2, type vec2 } from '@alleninstitute/vis-geometry';
type Props = {
id: string;
dzi: DziImage;
svgOverlay: HTMLImageElement;
svgOverlay?: HTMLImageElement;
wheel: (e: React.WheelEvent<HTMLCanvasElement>) => void;
} & DziRenderSettings;

function buildCompositor(svg: HTMLImageElement, settings: DziRenderSettings) {
return (ctx: CanvasRenderingContext2D, image: ImageData) => {
const { width, height } = svg;
const { camera } = settings;
const svgSize: vec2 = [width, height];
const start = Vec2.mul(camera.view.minCorner, svgSize);
const wh = Vec2.sub(Vec2.mul(camera.view.maxCorner, svgSize), start);
const [sx, sy] = start;
const [sw, sh] = wh;
// first, draw the results from webGL
ctx.putImageData(image, 0, 0);
// then add our svg overlay
ctx.drawImage(svg, sx, sy, sw, sh, 0, 0, ctx.canvas.width, ctx.canvas.height);
};
}

export function DziView(props: Props) {
const { svgOverlay, camera, dzi, wheel, id } = props;
const server = useContext(renderServerContext);
Expand Down Expand Up @@ -69,6 +53,22 @@ export function DziView(props: Props) {
}, [server]);

useEffect(() => {

const compose = (ctx: CanvasRenderingContext2D, image: ImageData) => {
// first, draw the results from webGL
ctx.putImageData(image, 0, 0);

if (svgOverlay) { // then add our svg overlay
const { width, height } = svgOverlay;
const svgSize: vec2 = [width, height];
const start = Vec2.mul(cam.view.minCorner, svgSize);
const wh = Vec2.sub(Vec2.mul(cam.view.maxCorner, svgSize), start);
const [sx, sy] = start;
const [sw, sh] = wh;
ctx.drawImage(svgOverlay, sx, sy, sw, sh, 0, 0, ctx.canvas.width, ctx.canvas.height);
}
};

if (server && renderer.current && cnvs.current) {
const renderMyData: RenderFrameFn<DziImage, DziTile> = (target, cache, callback) => {
if (renderer.current) {
Expand All @@ -77,7 +77,6 @@ export function DziView(props: Props) {
}
return null;
};
const compose = buildCompositor(svgOverlay, { camera: cam });
server.beginRendering(
renderMyData,
(e) => {
Expand All @@ -98,6 +97,7 @@ export function DziView(props: Props) {
);
}
}, [server, renderer.current, cnvs.current, cam]);

return (
<canvas
id={id}
Expand Down