- implemented isolated colouring depending on camera

This commit is contained in:
2025-11-27 11:43:10 +00:00
parent 1ada8d0966
commit f7dbde4511
4 changed files with 35 additions and 20 deletions

View File

@@ -1,7 +1,12 @@
import type { CameraFeedAction, CameraFeedState } from "../../types/types"; import type { CameraFeedAction, CameraFeedState, PaintedCell } from "../../types/types";
export const initialState: CameraFeedState = { export const initialState: CameraFeedState = {
cameraFeedID: "A", cameraFeedID: "A",
paintedCells: {
A: new Map<string, PaintedCell>(),
B: new Map<string, PaintedCell>(),
C: new Map<string, PaintedCell>(),
},
}; };
export function reducer(state: CameraFeedState, action: CameraFeedAction) { export function reducer(state: CameraFeedState, action: CameraFeedAction) {

View File

@@ -7,6 +7,8 @@ type CameraPanelProps = {
const CameraPanel = ({ tabIndex }: CameraPanelProps) => { const CameraPanel = ({ tabIndex }: CameraPanelProps) => {
const { dispatch } = useCameraFeedContext(); const { dispatch } = useCameraFeedContext();
useEffect(() => {
const mapIndextoCameraId = () => { const mapIndextoCameraId = () => {
switch (tabIndex) { switch (tabIndex) {
case 1: case 1:
@@ -20,11 +22,10 @@ const CameraPanel = ({ tabIndex }: CameraPanelProps) => {
} }
}; };
useEffect(() => {
const cameraId = mapIndextoCameraId(); const cameraId = mapIndextoCameraId();
console.log(cameraId);
dispatch({ type: "SET_CAMERA_FEED", payload: cameraId }); dispatch({ type: "SET_CAMERA_FEED", payload: cameraId });
}, [tabIndex]); }, [dispatch, tabIndex]);
return <div>CameraPanel</div>; return <div>CameraPanel</div>;
}; };

View File

@@ -4,6 +4,7 @@ import type { KonvaEventObject } from "konva/lib/Node";
import { useCreateVideoSnapshot } from "../../hooks/useGetvideoSnapshots"; import { useCreateVideoSnapshot } from "../../hooks/useGetvideoSnapshots";
import type { PaintedCell, Region } from "../../../../types/types"; import type { PaintedCell, Region } from "../../../../types/types";
import Card from "../../../../ui/Card"; import Card from "../../../../ui/Card";
import { useCameraFeedContext } from "../../../../app/context/CameraFeedContext";
const rows = 40; const rows = 40;
const cols = 40; const cols = 40;
@@ -17,7 +18,10 @@ type VideoFeedGridPainterProps = {
paintedCells: RefObject<Map<string, PaintedCell>>; paintedCells: RefObject<Map<string, PaintedCell>>;
}; };
const VideoFeedGridPainter = ({ regions, selectedRegionIndex, mode, paintedCells }: VideoFeedGridPainterProps) => { const VideoFeedGridPainter = ({ regions, selectedRegionIndex, mode }: VideoFeedGridPainterProps) => {
const { state, dispatch } = useCameraFeedContext();
const cameraFeedID = state.cameraFeedID;
const paintedCells = state.paintedCells[cameraFeedID];
const { latestBitmapRef, isloading } = useCreateVideoSnapshot(); const { latestBitmapRef, isloading } = useCreateVideoSnapshot();
const [stageSize, setStageSize] = useState({ width: 740, height: 460 }); const [stageSize, setStageSize] = useState({ width: 740, height: 460 });
const isDrawingRef = useRef(false); const isDrawingRef = useRef(false);
@@ -47,7 +51,7 @@ const VideoFeedGridPainter = ({ regions, selectedRegionIndex, mode, paintedCells
const key = `${row}-${col}`; const key = `${row}-${col}`;
const currentColour = regions[selectedRegionIndex].brushColour; const currentColour = regions[selectedRegionIndex].brushColour;
const map = paintedCells.current; const map = paintedCells;
const existing = map.get(key); const existing = map.get(key);
if (mode === "eraser") { if (mode === "eraser") {
@@ -121,7 +125,7 @@ const VideoFeedGridPainter = ({ regions, selectedRegionIndex, mode, paintedCells
<Layer ref={paintLayerRef} opacity={0.6}> <Layer ref={paintLayerRef} opacity={0.6}>
<Shape <Shape
sceneFunc={(ctx, shape) => { sceneFunc={(ctx, shape) => {
const cells = paintedCells.current; const cells = paintedCells;
cells.forEach((cell, key) => { cells.forEach((cell, key) => {
const [rowStr, colStr] = key.split("-"); const [rowStr, colStr] = key.split("-");
const row = Number(rowStr); const row = Number(rowStr);

View File

@@ -97,10 +97,15 @@ export type OptionalBOF2LaneIDs = {
}; };
export type CameraFeedState = { export type CameraFeedState = {
cameraFeedID: "A" | "B" | "C" | null; cameraFeedID: "A" | "B" | "C";
paintedCells: {
A: Map<string, PaintedCell>;
B: Map<string, PaintedCell>;
C: Map<string, PaintedCell>;
};
}; };
export type CameraFeedAction = { export type CameraFeedAction = {
type: string; type: string;
payload: "A" | "B" | "C" | null; payload: "A" | "B" | "C";
}; };