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

improve 3d bbox projection logic #4420

Merged
merged 10 commits into from
May 24, 2024
Merged

improve 3d bbox projection logic #4420

merged 10 commits into from
May 24, 2024

Conversation

sashankaryal
Copy link
Contributor

@sashankaryal sashankaryal commented May 24, 2024

What changes are proposed in this pull request?

Project 3d bounding box to 2d plane, and fill the convex hull of the resulting point set. Still needs refinement.

Summary by CodeRabbit

  • New Features

    • Added new 3D dataset "Quickstart 3D" with detailed documentation and example usage.
    • Introduced Quickstart3DDataset class for handling 3D datasets with meshes, point clouds, and oriented bounding boxes.
  • Enhancements

    • Updated orthographic projection metadata to include a normal field.
    • Improved 3D bounding box handling with new utility functions for rotation and projection.
    • Enhanced rendering logic to use convex hulls for more accurate visual representation.
  • Bug Fixes

    • Adjusted scaling factor calculations for different projection planes.
  • Documentation

    • Added a user guide section for the new "Quickstart 3D" dataset.

Copy link
Contributor

coderabbitai bot commented May 24, 2024

Important

Review Skipped

Auto reviews are disabled on base/target branches other than the default branch. Please add the base/target branch pattern to the list of additional branches to be reviewed in the settings.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The recent changes introduce support for 3D datasets and projections in the Looker package. Key updates include adding a convexHull property to the DetectionLabel interface, enhancing 3D and 2D projection utilities, and incorporating a normal field in the OrthographicProjectionMetadata type. Additionally, a new 3D dataset, "Quickstart 3D," is documented and implemented, with corresponding updates in test files to ensure the new functionalities are well-covered.

Changes

Files & Paths Change Summaries
app/packages/looker/src/overlays/detection.ts Added convexHull property to DetectionLabel and updated rendering logic to draw convex hulls.
app/packages/looker/src/state.ts Updated OrthographicProjectionMetadata to include a normal field with three numbers.
app/packages/looker/src/worker/label-3d-projection-utils.test.ts
app/packages/looker/src/worker/label-3d-projection-utils.ts
Added utility functions and types for 3D point rotation and 2D projection.
app/packages/looker/src/worker/threed-label-processor.ts Enhanced functions to handle 3D bounding boxes and projections, added imports and new logic for convex hull computation.
docs/source/user_guide/dataset_zoo/datasets.rst Added documentation for the new "Quickstart 3D" dataset with details and example usage.
fiftyone/utils/utils3d.py Updated OrthographicProjectionMetadata class to include a normal attribute.
fiftyone/zoo/datasets/base.py Introduced Quickstart3DDataset class for managing the new 3D dataset.
tests/unittests/utils3d_tests.py Modified tests to include assertions for the normal field in OrthographicProjectionMetadata.

🐇
In the world of Looker, 3D thrives,
With convex hulls and projections alive.
Quickstart 3D joins the fray,
Bounding boxes now in a new way.
Orthographic views with normals, how grand,
Our datasets and tests, perfectly planned.
🎉


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.

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 a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @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.

@sashankaryal sashankaryal changed the base branch from release/v0.24.0 to quickstart-3d May 24, 2024 00:35
@sashankaryal sashankaryal self-assigned this May 24, 2024
@sashankaryal sashankaryal requested a review from a team May 24, 2024 00:39
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: 5

Outside diff range and nitpick comments (2)
fiftyone/utils/utils3d.py (1)

904-904: Clarify default behavior for normal parameter.

The assignment normal=projection_normal or [0, 0, 1] uses a logical OR to provide a default value for the normal parameter. While this is a common pattern in Python, it might be clearer to use an explicit check like if projection_normal is None for setting default values, especially for readability and explicitness in critical parameters like this.

fiftyone/zoo/datasets/base.py (1)

3209-3219: Ensure properties are documented for clarity.

While the properties name, tags, and supported_splits are implemented correctly, adding a brief docstring to each can enhance the readability and maintainability of the code. This helps new developers understand the purpose of these properties at a glance.

Review Details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits Files that changed from the base of the PR and between ee0d85c and 7235ab5.
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 (6 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)
Files skipped from review due to trivial changes (1)
  • docs/source/user_guide/dataset_zoo/datasets.rst
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 (37)
app/packages/looker/src/overlays/detection.ts (8)

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


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


293-302: Prefer for...of instead of forEach.


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


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


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


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


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

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

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


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


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


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


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


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


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


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


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


10-10: All these imports are only used as types.

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

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

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

220-220: Declare variables separately


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


274-276: Prefer for...of instead of forEach.


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


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


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


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


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


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


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


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


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


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


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


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


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


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


Import statements could be sorted:

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/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/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/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 (14)
app/packages/looker/src/worker/label-3d-projection-utils.test.ts (1)

4-56: The test suite for rotatePoint is well-structured and covers rotations around different axes effectively.

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

1-2: The type definitions for Vec3 and Vec2 are correctly specified.


4-15: The type definitions for BoundingBox3D and BoundingBox2D are well-documented and correctly structured.


17-44: The rotatePoint function correctly implements the 3D rotation using rotation matrices. Good use of mathematical functions for clarity.


46-55: The projectTo2D function is well-implemented with clear handling of different projection planes.


57-103: The getProjectedCorners function correctly computes the 2D projections of the corners of a 3D bounding box, following the appropriate transformations and projections.

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

24-24: The addition of the convexHull property to the DetectionLabel interface is correctly typed and well-documented.


233-254: The fillRectFor3d method in the DetectionOverlay class effectively uses the convex hull to render the 3D bounding box. Good handling of canvas state changes.

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

Line range hint 34-86: The getScalingFactorForLabel function is well-implemented with efficient use of caching and correct logic for determining scaling factors based on the projection plane.


183-243: The PainterFactory3D function correctly handles the projection and drawing of 3D labels, using the convex hull to determine the outline of the projected label.

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

68-70: The updates to the OrthographicProjectionMetadata type are correctly implemented, adding necessary fields for 3D projection handling.

tests/unittests/utils3d_tests.py (2)

288-288: Ensure the normal attribute is correctly initialized and used.

This change aligns with the PR's objective to enhance 3D data handling by including a normal vector in the projection metadata, which is crucial for correct 3D to 2D projection.


308-308: Validate the normal field in unit tests.

The addition of the normal field to the OrthographicProjectionMetadata class is correctly tested here, ensuring that the field is properly serialized and deserialized. This is crucial for maintaining data integrity across operations.

fiftyone/zoo/datasets/base.py (1)

3221-3237: Refactor exception handling in _download_and_prepare method to specify exception types.

- except:
+ except Exception as e:
+     logger.error("An error occurred: %s", str(e))

Using a bare except: clause can catch unexpected events such as keyboard interrupts, and system exits, besides the regular exceptions. This is generally not advisable unless you have a specific reason to catch all exceptions. Specifying the exception type can help in handling only those exceptions that are expected and relevant to the context.

Likely invalid or redundant comment.

fiftyone/utils/utils3d.py Outdated Show resolved Hide resolved
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.

LGTM

@brimoor brimoor merged commit 59163ed into quickstart-3d May 24, 2024
5 checks passed
@brimoor brimoor deleted the fix/ortho-normal branch May 24, 2024 15:18
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.

3 participants