Skip to content

Commit

Permalink
comments
Browse files Browse the repository at this point in the history
  • Loading branch information
sashankaryal committed May 24, 2024
1 parent 057b56d commit 7235ab5
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 68 deletions.
1 change: 1 addition & 0 deletions app/packages/looker/src/overlays/detection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<
Expand Down
61 changes: 1 addition & 60 deletions app/packages/looker/src/worker/label-3d-projection-utils.test.ts
Original file line number Diff line number Diff line change
@@ -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", () => {
Expand Down Expand Up @@ -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,
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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"
) => {
Expand Down
33 changes: 26 additions & 7 deletions app/packages/looker/src/worker/threed-label-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -206,21 +209,37 @@ 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];
});

const convexHullIndices = ch(newProjectedCorners);

const convexHull = convexHullIndices.map((i) => newProjectedCorners[i]);

// sort convex hull points in clockwise order

label.convexHull = convexHull;
},
});
Expand Down

0 comments on commit 7235ab5

Please sign in to comment.