Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Fix 3D bounding box alignment for orthographic projections #4422

Closed
wants to merge 5 commits into from
Closed
Changes from 1 commit
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
35 changes: 20 additions & 15 deletions app/packages/looker/src/worker/threed-label-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@ const inferredParamsCache: Record<
OrthogrpahicProjectionMetadata
> = {};

const remap = (
value: number,
fromLow: number,
fromHigh: number,
toLow: number,
toHigh: number
) => {
return toLow + ((value - fromLow) * (toHigh - toLow)) / (fromHigh - fromLow);
};

/**
* Use label attributes to infer width, height, and bounds.
*/
Expand Down Expand Up @@ -108,7 +118,8 @@ const PainterFactory3D = (
* Impute bounding box parameters.
*/
Detection: (label: DetectionLabel) => {
const { min_bound, max_bound, normal } = orthographicProjectionParams;
const { min_bound, max_bound, normal, height, width } =
orthographicProjectionParams;
const [xmin, ymin, zmin] = min_bound;
const [xmax, ymax, zmax] = max_bound;

Expand Down Expand Up @@ -136,38 +147,32 @@ const PainterFactory3D = (
// project on xy plane
projectionPlane = "xy";
}

const { projectedCorners } = getProjectedCorners(box, projectionPlane);

const xRange = xmax - xmin;
const yRange = ymax - ymin;
const zRange = zmax - zmin;

const newProjectedCorners = projectedCorners.map(([x, y]) => {
let px, py;

// todo: need to account for negative / positive normals
// adjust normalization for different projection planes
switch (projectionPlane) {
case "xy":
px = (x - xmin) / xRange;
py = (ymax - y) / yRange;
px = remap(x, xmin, xmax, 0, 1);
py = remap(y, ymin, ymax, 1, 0); // is this right?
break;
case "xz":
px = (x - xmin) / xRange;
py = (zmax - y) / zRange;
px = remap(x, xmin, xmax, 0, 1);
ritch marked this conversation as resolved.
Show resolved Hide resolved
py = remap(y, ymin, ymax, 1, 0);
break;
case "yz":
px = (y - ymin) / yRange;
py = (zmax - x) / zRange;
px = remap(x, ymin, ymax, 1, 0);
py = remap(y, xmin, xmax, 1, 0); // is this right?
break;
}

return [px, py];
});

const convexHullIndices = ch(newProjectedCorners);

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

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