Skip to content

Commit

Permalink
fix(app): render bounding boxes on media panel without points (#3158)
Browse files Browse the repository at this point in the history
* WB-16623 coercing empty point to default, targeting camera on bounding box when point cloud empty

* code style cleanup
  • Loading branch information
brianlund-wandb authored Dec 10, 2024
1 parent a14edbe commit c19fe6b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
14 changes: 14 additions & 0 deletions weave-js/src/common/util/SdkPointCloudToBabylon.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
DEFAULT_POINT_COLOR,
getFilteringOptionsForPointCloud,
getVertexCompatiblePositionsAndColors,
loadPointCloud,
MAX_BOUNDING_BOX_LABELS_FOR_DISPLAY,
MaxAlphaValue,
} from './SdkPointCloudToBabylon';
Expand Down Expand Up @@ -174,3 +175,16 @@ describe('getFilteringOptionsForPointCloud', () => {
expect(newClassIdToLabel.get(49)).toEqual('label49');
});
});
describe('loadPointCloud', () => {
it('appropriate defaults set when loading point cloud from file', () => {
const fileContents = JSON.stringify({
boxes: [],
points: [[]],
type: 'lidar/beta',
vectors: [],
});
const babylonPointCloud = loadPointCloud(fileContents);
expect(babylonPointCloud.points).toHaveLength(1);
expect(babylonPointCloud.points[0].position).toEqual([0, 0, 0]);
});
});
2 changes: 1 addition & 1 deletion weave-js/src/common/util/SdkPointCloudToBabylon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ export const handlePoints = (object3D: Object3DScene): ScenePoint[] => {
// Draw Points
return truncatedPoints.map(point => {
const [x, y, z, r, g, b] = point;
const position: Position = [x, y, z];
const position: Position = [x ?? 0, y ?? 0, z ?? 0];
const category = r;

if (r !== undefined && g !== undefined && b !== undefined) {
Expand Down
13 changes: 11 additions & 2 deletions weave-js/src/common/util/render_babylon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,15 @@ const pointCloudScene = (
// Apply vertexData to custom mesh
vertexData.applyToMesh(pcMesh);

// A file without any points defined still includes a single, empty "point".
// In order to play nice with Babylon, we position this empty point at 0,0,0.
// Hence, a pointCloud with a single point at 0,0,0 is likely empty.
const isEmpty =
pointCloud.points.length === 1 &&
pointCloud.points[0].position[0] === 0 &&
pointCloud.points[0].position[1] === 0 &&
pointCloud.points[0].position[2] === 0;

camera.parent = pcMesh;

const pcMaterial = new Babylon.StandardMaterial('mat', scene);
Expand Down Expand Up @@ -472,8 +481,8 @@ const pointCloudScene = (
new Vector3(edges.length * 2, edges.length * 2, edges.length * 2)
);

// If we are iterating over camera, target a box
if (index === meta?.cameraIndex) {
// If we are iterating over camera or the cloud is empty, target a box
if (index === meta?.cameraIndex || (index === 0 && isEmpty)) {
camera.position = center.add(new Vector3(0, 0, 1000));
camera.target = center;
camera.zoomOn([lines]);
Expand Down

0 comments on commit c19fe6b

Please sign in to comment.