Skip to content

Commit

Permalink
Merge pull request #5195 from voxel51/fix/3d-bad-labels
Browse files Browse the repository at this point in the history
add guards for missing location/dimensions while rendering 3d bounding boxes
  • Loading branch information
sashankaryal authored Nov 27, 2024
2 parents 738b128 + 85e2265 commit 34961bb
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
6 changes: 5 additions & 1 deletion app/packages/looker-3d/src/labels/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,11 @@ export const ThreeDLabels = ({ sampleMap }: ThreeDLabelsProps) => {
const newPolylineOverlays = [];

for (const overlay of rawOverlays) {
if (overlay._cls === "Detection") {
if (
overlay._cls === "Detection" &&
overlay.dimensions &&
overlay.location
) {
newCuboidOverlays.push(
<Cuboid
key={`cuboid-${overlay.id ?? overlay._id}-${overlay.sampleId}`}
Expand Down
2 changes: 1 addition & 1 deletion app/packages/looker/src/overlays/detection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ export default class DetectionOverlay<
this.label.mask && this.drawMask(ctx, state);
!state.config.thumbnail && this.drawLabelText(ctx, state);

if (this.is3D) {
if (this.is3D && this.label.dimensions && this.label.location) {
this.fillRectFor3d(ctx, state, this.getColor(state));
} else {
this.strokeRect(ctx, state, this.getColor(state));
Expand Down
6 changes: 5 additions & 1 deletion app/packages/looker/src/worker/threed-label-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ const getInferredParamsForUndefinedProjection = (

if (cls === DETECTIONS) {
for (const detection of label.detections as DetectionLabel[]) {
if (!detection.location || !detection.dimensions) {
continue;
}

const [x, y] = detection.location;
const [lx, ly] = detection.dimensions;

Expand All @@ -55,7 +59,7 @@ const getInferredParamsForUndefinedProjection = (
minY = Math.min(minY, y - ly / 2);
maxY = Math.max(maxY, y + ly / 2);
}
} else if (cls === "Detection") {
} else if (cls === "Detection" && label.location && label.dimensions) {
const [x, y] = label.location as DetectionLabel["location"];
const [lx, ly] = label.dimensions as DetectionLabel["dimensions"];

Expand Down

0 comments on commit 34961bb

Please sign in to comment.