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

Fix 3D bounding box alignment for orthographic projections #4422

Draft
wants to merge 5 commits into
base: develop
Choose a base branch
from

Conversation

ritch
Copy link
Contributor

@ritch ritch commented May 24, 2024

To reproduce the issue use the following:

import fiftyone as fo
import fiftyone.zoo as foz
import fiftyone.utils.utils3d as fou3d

dataset = foz.load_zoo_dataset("quickstart-3d")

fou3d.compute_orthographic_projection_images(
    dataset,
    (-1, 512),
    projection_normal=(0,-1,0),
    output_dir="/tmp/quickstart-3d-proj",
    shading_mode="height",
    overwrite=True,
)

session = fo.launch_app(dataset)

Prior to this PR you should see the following:

image

After the changes in this PR you should see the projected bounding boxes align properly for the same example.

image

Summary by CodeRabbit

  • New Features

    • Introduced 3D dataset "Quickstart 3D" with example usage in the user guide.
    • Added new class Quickstart3DDataset for handling 3D datasets, including methods for downloading and preparing the dataset.
  • Enhancements

    • Updated DetectionLabel interface to include convexHull property.
    • Enhanced OrthographicProjectionMetadata with a normal field for better 3D projection handling.
  • Bug Fixes

    • Improved test coverage for 3D projection functionalities, ensuring accurate handling of the normal field.
  • Documentation

    • Added detailed documentation for the "Quickstart 3D" dataset in the user guide.

@ritch ritch changed the base branch from develop to release/v0.24.0 May 24, 2024 17:54
Copy link
Contributor

coderabbitai bot commented May 24, 2024

Warning

Rate Limit Exceeded

@brimoor has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 19 minutes and 54 seconds before requesting another review.

How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.
Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.
Please see our FAQ for further information.

Commits Files that changed from the base of the PR and between e983f0e and 0a8fc23.

Walkthrough

The recent updates introduce significant enhancements to the Looker package, particularly in 3D data handling. Key changes include adding a convexHull property to the DetectionLabel interface, enhancing 3D projection utilities, and updating orthographic projection metadata to include a normal vector. Additionally, a new "Quickstart 3D" dataset is documented and integrated, and relevant unit tests are updated to reflect these changes.

Changes

Files & Directories Change Summary
.../detection.ts Added convexHull property to DetectionLabel interface; removed rotation logic and added drawing for convex hull.
.../state.ts Updated OrthographicProjectionMetadata to include a normal vector.
.../worker/label-3d-projection-utils.test.ts Added test cases for projectTo2D function.
.../worker/label-3d-projection-utils.ts Added utility functions and types for 3D to 2D projection and bounding boxes.
.../worker/threed-label-processor.ts Introduced clamp and remap functions; updated PainterFactory3D to handle different projection planes.
docs/source/user_guide/dataset_zoo/datasets.rst Added a new section for "Quickstart 3D" dataset with details and example usage.
fiftyone/utils/utils3d.py Updated OrthographicProjectionMetadata to include normal field; modified _parse_point_cloud to initialize normal field.
fiftyone/zoo/datasets/base.py Added Quickstart3DDataset class with methods for dataset handling; updated dataset registry.
tests/unittests/utils3d_tests.py Modified tests to include assertions for normal field in OrthographicProjectionMetadata.

🎉
In the land of code, where data's 3D,
Convex hulls and projections, oh what a spree!
With datasets new and bounding boxes bright,
Orthographic views now take flight.
A rabbit's cheer for changes so grand,
In Looker's world, enhancements stand.
🐇✨


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to full the review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@ritch ritch changed the base branch from release/v0.24.0 to quickstart-3d May 24, 2024 17:54
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 7

Outside diff range and nitpick comments (1)
app/packages/looker/src/worker/threed-label-processor.ts (1)

Line range hint 218-220: Prefer using for...of instead of forEach for better performance and readability.

- label[cls.toLocaleLowerCase()].forEach((label: ThreeDLabel) => {
+ for (const labelItem of label[cls.toLocaleLowerCase()]) {
Review Details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits Files that changed from the base of the PR and between ee0d85c and 8ed2213.
Files ignored due to path filters (2)
  • app/packages/looker/package.json is excluded by !**/*.json
  • app/yarn.lock is excluded by !**/*.lock, !**/*.lock
Files selected for processing (9)
  • app/packages/looker/src/overlays/detection.ts (2 hunks)
  • app/packages/looker/src/state.ts (1 hunks)
  • app/packages/looker/src/worker/label-3d-projection-utils.test.ts (1 hunks)
  • app/packages/looker/src/worker/label-3d-projection-utils.ts (1 hunks)
  • app/packages/looker/src/worker/threed-label-processor.ts (5 hunks)
  • docs/source/user_guide/dataset_zoo/datasets.rst (1 hunks)
  • fiftyone/utils/utils3d.py (3 hunks)
  • fiftyone/zoo/datasets/base.py (2 hunks)
  • tests/unittests/utils3d_tests.py (2 hunks)
Additional Context Used
Ruff (6)
fiftyone/zoo/datasets/base.py (6)

636-636: Do not use bare except


643-643: Do not use bare except


3359-3359: Do not use bare except


3367-3367: Do not use bare except


3375-3375: Do not use bare except


3382-3382: Do not use bare except

Biome (36)
app/packages/looker/src/overlays/detection.ts (8)

195-195: The assignment should not be in an expression.


204-204: The assignment should not be in an expression.


292-301: Prefer for...of instead of forEach.


6-7: All these imports are only used as types.


7-8: All these imports are only used as types.


9-10: Some named imports are only used as types.


194-194: isNaN is unsafe. It attempts a type coercion. Use Number.isNaN instead.


201-201: isNaN is unsafe. It attempts a type coercion. Use Number.isNaN instead.

app/packages/looker/src/state.ts (10)

120-120: Unexpected any. Specify a different type.


129-129: This enum declaration contains members that are implicitly initialized.


187-187: Unexpected any. Specify a different type.


322-322: Unexpected any. Specify a different type.


411-411: Unexpected any. Specify a different type.


493-493: Unexpected any. Specify a different type.


4-5: All these imports are only used as types.


5-6: All these imports are only used as types.


6-7: All these imports are only used as types.


8-9: All these imports are only used as types.

app/packages/looker/src/worker/label-3d-projection-utils.test.ts (1)

1-2: Some named imports are only used as types.

app/packages/looker/src/worker/threed-label-processor.ts (17)

161-161: Declare variables separately


161-161: This variable implicitly has the any type.


218-220: Prefer for...of instead of forEach.


1-1: Some named imports are only used as types.


3-4: All these imports are only used as types.


4-5: All these imports are only used as types.


5-9: Some named imports are only used as types.


51-51: Use Number.Infinity instead of the equivalent global.


52-52: Use Number.Infinity instead of the equivalent global.


53-53: Use Number.Infinity instead of the equivalent global.


54-54: Use Number.Infinity instead of the equivalent global.


84-84: Use Number.Infinity instead of the equivalent global.


85-85: Use Number.Infinity instead of the equivalent global.


88-88: Use Number.Infinity instead of the equivalent global.


91-91: Use Number.Infinity instead of the equivalent global.


97-97: Use Number.Infinity instead of the equivalent global.


100-100: Use Number.Infinity instead of the equivalent global.

Path-based Instructions (5)
app/packages/looker/src/worker/label-3d-projection-utils.test.ts (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

app/packages/looker/src/worker/label-3d-projection-utils.ts (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

app/packages/looker/src/worker/threed-label-processor.ts (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

app/packages/looker/src/overlays/detection.ts (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

app/packages/looker/src/state.ts (1)

Pattern **/*.{ts,tsx}: Review the Typescript and React code for conformity with best practices in React, Recoil, Graphql, and Typescript. Highlight any deviations.

Additional comments not posted (8)
app/packages/looker/src/worker/label-3d-projection-utils.ts (2)

26-35: The projectTo2D function is well-implemented for projecting points onto specified planes.


37-85: The getProjectedCorners function correctly calculates the transformed and projected corners of a 3D bounding box.

app/packages/looker/src/worker/threed-label-processor.ts (1)

26-38: The clamp and remap functions are correctly implemented for their respective purposes.

app/packages/looker/src/overlays/detection.ts (2)

24-24: Adding convexHull as an optional property to DetectionLabel aligns with the PR's focus on 3D bounding box enhancements.


233-254: The method fillRectFor3d correctly handles drawing the convex hull for 3D bounding boxes. Ensure the alpha transparency settings are as intended.

Verification successful

The alpha transparency settings in the fillRectFor3d method appear to be consistent with the intended behavior. The method sets ctx.globalAlpha to state.options.alpha * 0.3 for filling the convex hull with some transparency.

  • app/packages/looker/src/overlays/detection.ts: Verified the alpha transparency settings in the fillRectFor3d method.
Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the alpha transparency settings in the `fillRectFor3d` method.

# Test: Search for the usage of `fillRectFor3d`. Expect: Consistent alpha settings across different uses.
rg --type typescript $'fillRectFor3d'

Length of output: 71



Script:

#!/bin/bash
# Description: Verify the alpha transparency settings in the `fillRectFor3d` method.

# Test: Search for the usage of `fillRectFor3d`. Expect: Consistent alpha settings across different uses.
rg --type ts 'fillRectFor3d'

Length of output: 205



Script:

#!/bin/bash
# Description: Extract lines around the usage of `fillRectFor3d` to verify alpha transparency settings.

# Extract lines around the usage of `fillRectFor3d` in `app/packages/looker/src/overlays/detection.ts`.
rg --type ts -A 5 -B 5 'fillRectFor3d' app/packages/looker/src/overlays/detection.ts

Length of output: 751

app/packages/looker/src/state.ts (1)

68-70: The updated OrthographicProjectionMetadata type now includes 3D bounds and a normal vector, enhancing its utility for 3D projections.

tests/unittests/utils3d_tests.py (1)

Line range hint 288-308: The test case test_orthographic_projection_metadata_field correctly asserts the fields of OrthographicProjectionMetadata.

docs/source/user_guide/dataset_zoo/datasets.rst (1)

3453-3502: The addition of the "Quickstart 3D" dataset section provides a concise overview of the dataset's contents, including 3D meshes and point clouds. The details are well-organized, offering clear information on the dataset's size, tags, and the absence of splits, which is typical for quickstart datasets. The example usage is correctly formatted and provides straightforward instructions for loading and viewing the dataset in FiftyOne, enhancing the usability of the documentation for users.

@ritch ritch force-pushed the fix/orth-normals-with-bounds branch from 8ed2213 to f62cf0f Compare May 24, 2024 18:13
@ritch
Copy link
Contributor Author

ritch commented May 24, 2024

Note: I think there will still be issues with different projection normals. Other projections should be tested before merging this.

@ritch ritch force-pushed the fix/orth-normals-with-bounds branch 2 times, most recently from 3b890a9 to a2f8936 Compare May 24, 2024 18:23
@ritch ritch force-pushed the fix/orth-normals-with-bounds branch from a2f8936 to 4be6314 Compare May 24, 2024 18:24
@brimoor brimoor force-pushed the fix/orth-normals-with-bounds branch 2 times, most recently from 5b351ec to f7f1ed4 Compare May 24, 2024 22:58
@ritch ritch force-pushed the fix/orth-normals-with-bounds branch from f7f1ed4 to 2c04e79 Compare May 24, 2024 23:26
Copy link
Contributor

@brimoor brimoor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ritch I tested after your latest force push and I'm not seeing any improvement over #4406.

Example 1 works on both branches, but the boxes in the grid for examples 2 and 3 are misaligned on both branches.

import fiftyone as fo
import fiftyone.zoo as foz
import fiftyone.utils.utils3d as fou3d

dataset = foz.load_zoo_dataset("quickstart-3d")

# Example 1: boxes are aligned 
fou3d.compute_orthographic_projection_images(
    dataset,
    (-1, 512),
    bounds=((-50,-50,-50), (50,50,50)),
    projection_normal=(0,-1,0),
    output_dir="/tmp/quickstart-3d-proj",
    shading_mode="height",
)

session = fo.launch_app(dataset)

# Example 2: boxes are NOT aligned
fou3d.compute_orthographic_projection_images(
    dataset,
    (-1, 512),
    projection_normal=(0,-1,0),
    output_dir="/tmp/quickstart-3d-proj",
    shading_mode="height",
)

session = fo.launch_app(dataset)

# Example 3: boxes are NOT aligned
fou3d.compute_orthographic_projection_images(
    dataset,
    (-1, 512),
    padding=0.25,
    projection_normal=(0,-1,0),
    output_dir="/tmp/quickstart-3d-proj",
    shading_mode="height",
)

session = fo.launch_app(dataset)

};

export const getProjectionPlaneForNormal = (normal: Vec3): ProjectionPlane => {
const [nx, ny, nz] = normal ?? [0, 0, 1];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI- I added ?? [0, 0, 1] here for backwards compatibility. OrthographicProjectionMetadata did not have a normal field in prior releases so we need to default here.

Base automatically changed from quickstart-3d to release/v0.24.0 May 28, 2024 13:07
@ritch
Copy link
Contributor Author

ritch commented May 28, 2024

tested after your latest force push and I'm not seeing any improvement over

Yes I refactored the code to add more tests and its back to the way it was before (as you noticed). I think there is some issue outside of these changes.

I tried a simpler set of bounds (min_z=0, max_z=20) and the bottom of the image didn't align with the bottom of the model, which makes me think there's an issue in the image creation.

const py = remap(y, ymin, ymax, 0, 1);
const pz = remap(z, zmin, zmax, 0, 1);

console.log({ z, zmin, zmax, pz });
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

@ritch ritch marked this pull request as draft May 28, 2024 15:43
@brimoor brimoor changed the base branch from release/v0.24.0 to develop May 29, 2024 20:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants