diff --git a/app/packages/looker/src/overlays/detection.ts b/app/packages/looker/src/overlays/detection.ts index e7d6406b29..89ca092be7 100644 --- a/app/packages/looker/src/overlays/detection.ts +++ b/app/packages/looker/src/overlays/detection.ts @@ -21,6 +21,7 @@ export interface DetectionLabel extends RegularLabel { dimensions?: [number, number, number]; location?: [number, number, number]; rotation?: [number, number, number]; + convexHull?: Coordinates[]; } export default class DetectionOverlay< diff --git a/app/packages/looker/src/worker/label-3d-projection-utils.test.ts b/app/packages/looker/src/worker/label-3d-projection-utils.test.ts index e73f758f6f..6f60895d96 100644 --- a/app/packages/looker/src/worker/label-3d-projection-utils.test.ts +++ b/app/packages/looker/src/worker/label-3d-projection-utils.test.ts @@ -1,11 +1,5 @@ import { describe, expect, it } from "vitest"; -import { - BoundingBox3D, - Vec3, - getBoundingBox2D, - projectTo2D, - rotatePoint, -} from "./label-3d-projection-utils"; +import { Vec3, projectTo2D, rotatePoint } from "./label-3d-projection-utils"; describe("rotatePoint", () => { it("should correctly rotate a point around the origin - y axis", () => { @@ -80,56 +74,3 @@ describe("projectTo2D", () => { expect(projectedPoint).toEqual([2, 3]); }); }); - -describe.skip("getBoundingBox2D", () => { - it("should project a 3D bounding box to a 2D plane (xy) with no rotation", () => { - const box3D: BoundingBox3D = { - dimensions: [2, 3, 4], - location: [1, 2, 3], - rotation: [0, 0, 0], - }; - - const projectedBox = getBoundingBox2D(box3D, "xy"); - - expect(projectedBox).toEqual({ - tlx: 1, - tly: 2, - width: 2, - height: 3, - }); - }); - - it("should project a 3D bounding box to a 2D plane (xy) with no rotation arobnd origin", () => { - const box: BoundingBox3D = { - dimensions: [2, 1, 3], - location: [0, 0, 0], - rotation: [0, 0, 0], - }; - - const boundingBox = getBoundingBox2D(box, "xz"); - - expect(boundingBox).toEqual({ - tlx: 0, - tly: 0, - width: 2, - height: 3, - }); - }); - - it("should project a rotated 3D bounding box to a 2D plane (xy)", () => { - const box: BoundingBox3D = { - dimensions: [2, 1, 3], - location: [0, 0, 0], - rotation: [Math.PI / 2, 0, 0], // 90 degree rotation on X axis - }; - - const boundingBox = getBoundingBox2D(box, "xy"); - - expect(boundingBox).toEqual({ - tlx: 0, - tly: 0, - width: 3, - height: 2, - }); - }); -}); diff --git a/app/packages/looker/src/worker/label-3d-projection-utils.ts b/app/packages/looker/src/worker/label-3d-projection-utils.ts index 1c7db4ce2b..4630be4b01 100644 --- a/app/packages/looker/src/worker/label-3d-projection-utils.ts +++ b/app/packages/looker/src/worker/label-3d-projection-utils.ts @@ -54,7 +54,7 @@ export const projectTo2D = (point: Vec3, plane: "xz" | "xy" | "yz"): Vec2 => { } }; -export const getBoundingBox2D = ( +export const getProjectedCorners = ( box: BoundingBox3D, plane: "xz" | "xy" | "yz" ) => { diff --git a/app/packages/looker/src/worker/threed-label-processor.ts b/app/packages/looker/src/worker/threed-label-processor.ts index d44ab84877..42e2063f8a 100644 --- a/app/packages/looker/src/worker/threed-label-processor.ts +++ b/app/packages/looker/src/worker/threed-label-processor.ts @@ -3,7 +3,10 @@ import ch from "monotone-convex-hull-2d"; import { POINTCLOUD_OVERLAY_PADDING } from "../constants"; import { DetectionLabel } from "../overlays/detection"; import { OrthogrpahicProjectionMetadata, Sample } from "../state"; -import { BoundingBox3D, getBoundingBox2D } from "./label-3d-projection-utils"; +import { + BoundingBox3D, + getProjectedCorners, +} from "./label-3d-projection-utils"; import { mapId } from "./shared"; type DetectionsLabel = { @@ -206,12 +209,30 @@ const PainterFactory3D = ( projectionPlane = "xy"; } - const { projectedCorners } = getBoundingBox2D(box, projectionPlane); + const { projectedCorners } = getProjectedCorners(box, projectionPlane); + + const xRange = xmax - xmin; + const yRange = ymax - ymin; + const zRange = zmax - zmin; - // map projected corners const newProjectedCorners = projectedCorners.map(([x, y]) => { - const px = (x - xmin) / (xmax - xmin); - const py = (ymax - y) / (ymax - ymin); + let px, py; + + // todo: need to account for negative / positive normals + switch (projectionPlane) { + case "xy": + px = (x - xmin) / xRange; + py = (ymax - y) / yRange; + break; + case "xz": + px = (x - xmin) / xRange; + py = (zmax - y) / zRange; + break; + case "yz": + px = (y - ymin) / yRange; + py = (zmax - x) / zRange; + break; + } return [px, py]; }); @@ -219,8 +240,6 @@ const PainterFactory3D = ( const convexHull = convexHullIndices.map((i) => newProjectedCorners[i]); - // sort convex hull points in clockwise order - label.convexHull = convexHull; }, });