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

TriangleMeshReceptacles and RearrangeGenerator Improvements #1108

Merged
merged 31 commits into from
Mar 15, 2023

Conversation

aclegg3
Copy link
Contributor

@aclegg3 aclegg3 commented Feb 1, 2023

Motivation and Context

New features include:

  • TriangleMeshReceptacle class - area weighted uniform sampling of 3D positions from an arbitrary triangle mesh surface. Can be loaded from .PLY format.
  • Sampling efficiency improvement: Added option to remove unstable objects instead of throwing away the episode if minimum number of objects for each sample can still be satisfied.
  • Improved reporting of sampling statistics and timings for RearrangeGenerator.
  • Added debug images of unstable objects to improve receptacle/scene debugging.
  • triangle sampling and "point in triangle" test added to geometry_utils and tested

Changes include:

  • Receptacle debugging visualization now uses DebugLineRender instead of attaching wire-frames to objects.
  • bugfix: max number of sample attempts were not reset after successful pairing.
  • bugfix: save file paths for DebugVisualizer were not always propagated correctly.
  • new and improved docstrings and typing

How Has This Been Tested

Added unit tests specifically for parsing and sampling from AABBReceptacles and TriangleMeshReceptacles.
Must be tested against habitat-sim PR 1994 with modified test assets.

Types of changes

Docs change / refactoring / dependency upgrade
Bug fix (non-breaking change which fixes an issue)
New feature (non-breaking change which adds functionality)

Checklist

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have completed my CLA (see CONTRIBUTING)
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@facebook-github-bot facebook-github-bot added the CLA Signed Do not delete this pull request or issue due to inactivity. label Feb 1, 2023
Comment on lines 194 to 195
git fetch --all
git checkout receptacle-test-assets
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Testing only: this will be removed before merge.

), "Must be a triangle mesh."

# zero-copy reference to importer datastructures
mesh_data: Tuple[List[mn.Vector3], List[int]] = (
Copy link
Contributor

Choose a reason for hiding this comment

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

If you'd want to be exact with the typing annotation, the actual type is cr.containers.StridedArrayView1D, not a List, but right now I don't have the [] "templating" implemented so saying cr.StridedArrayView1D[mn.Vector3] would probably cause Python to complain.... and without it it's maybe too nondescriptive (like np.ndarray is). I'll investigate what can be done on that front (implementing __getitem__ on the typeclass? huh).

dblr.draw_transformed_line(
verts[edge], verts[(edge + 1) % 3], color
)
dblr.pop_transform()
Copy link
Contributor

Choose a reason for hiding this comment

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

Just FYI, the dedicated tool for drawing wireframes (without having to manually compose them out of line segments) is the MeshVisualizer shader. I think it was used somewhere in the C++ viewer already, but no idea how easy is it to make it available here.

In case the shader would be available, you'd keep the original MeshData (instead of taking just views on positions and indices from it) and draw it directly with the shader.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cool suggestion, I think this would be a cool way to do some debugging visualization in the future. Construct MeshData for the debug mesh and then register it for the MeshVisualizer shader.
Is this exposed to python in some way that it could draw on top of an existing framebuffer or would it need to be built into the Habitat rendering pipeline on the C++ side?

Copy link
Contributor

Choose a reason for hiding this comment

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

The shader isn't exposed at the moment (but I could do that easily), and yes that would work as long as you either have the framebuffer currently bound or have a way to access & bind it for drawing.

On the other hand, such direct approach would be very incompatible with the batch renderer ... so for easier porting in the future it's probably best to just leave it as-is 😅 The debug line drawing will have to get ported to the batch renderer in any case, and I could then maybe expand it to handle also wireframe meshes somehow.

Copy link
Contributor

@vincentpierre vincentpierre left a comment

Choose a reason for hiding this comment

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

Looks great. Left some comments, but I do not have much to say about the overall change.

Comment on lines 498 to 500
# NOTE: We don't support mesh merging or multi-mesh parsing currently
if importer.mesh_count > 1:
raise NotImplementedError("TODO: multi-mesh receptacle support.")
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
# NOTE: We don't support mesh merging or multi-mesh parsing currently
if importer.mesh_count > 1:
raise NotImplementedError("TODO: multi-mesh receptacle support.")
# TODO: We don't support mesh merging or multi-mesh parsing currently
if importer.mesh_count > 1:
raise NotImplementedError("Importing multi-mesh receptacles (mesh merging or multi-mesh parsing) is not supported. ")

Copy link
Contributor

Choose a reason for hiding this comment

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

I could expose MeshTools::concatenate() and SceneTools::flattenMeshHierarchy() for doing this if you want.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think folks are hoping to eventually have multiple separate meshes in a single file which we'll split out here.
Generally happy to see more Magnum mesh tools in python though. 🙂

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Update: I think we want to store separate receptacle meshes as glTF nodes. So here we'll load the glTF file and iterate over all meshes in the scene, creating a TriangleMeshReceptacle for each one.

@aclegg3 aclegg3 requested a review from vincentpierre March 11, 2023 19:11
@aclegg3
Copy link
Contributor Author

aclegg3 commented Mar 11, 2023

Looks great. Left some comments, but I do not have much to say about the overall change.

Thanks, I've addressed your comments and resolved those not containing additional discussion.

Copy link
Contributor

@vincentpierre vincentpierre left a comment

Choose a reason for hiding this comment

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

LGTM, I would prefer another approval from @mosra if possible.

@@ -0,0 +1,54 @@
---
Copy link
Contributor

Choose a reason for hiding this comment

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

Where is this file used? I could not found a test that was using it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is for users to test generation on their scenes with all receptacles defined without needing to define another custom generator config. I can remove it from this PR if that isn't a good enough reason to include it.

@aclegg3 aclegg3 requested a review from mosra March 13, 2023 21:45
@aclegg3 aclegg3 merged commit 0ef0de2 into main Mar 15, 2023
@aclegg3 aclegg3 deleted the rearrange-gen-improvements branch March 15, 2023 16:36
@0mdc 0mdc mentioned this pull request Mar 16, 2023
5 tasks
JHurricane96 pushed a commit to JHurricane96/habitat-lab that referenced this pull request May 4, 2023
…research#1108)

* updates to rearrange episode generation to support mesh receptacles and improved debugging

* docstrings and typing for DebugVisualizer util

* mesh receptacle debug_draw with global transforms

* add some tests for sampling accuracy

* bugfix - use default_sensor_uid instead of hardcoded "rgb" in DebugVisualizer

* adjust debug peek target to bb center to better capture objects not centered at COM

* add debug circles to the peek API

* add peek_scene variant for easliy getting images of a full scene or stage.
JHurricane96 added a commit that referenced this pull request May 11, 2023
* TriangleMeshReceptacles and RearrangeGenerator Improvements (#1108)

* updates to rearrange episode generation to support mesh receptacles and improved debugging

* docstrings and typing for DebugVisualizer util

* mesh receptacle debug_draw with global transforms

* add some tests for sampling accuracy

* bugfix - use default_sensor_uid instead of hardcoded "rgb" in DebugVisualizer

* adjust debug peek target to bb center to better capture objects not centered at COM

* add debug circles to the peek API

* add peek_scene variant for easliy getting images of a full scene or stage.

* RearrangeGenerator cleanup and unstable object culling (#1248)

* fix unstable object culling compatibility with target sampling and change default to use this feature

* add comments and typing

* fix bug where only the first of a target sampler's object samplers was used

* Add support for glTF multi-receptacle assets (#1249)

* add support for glTF multi-receptacle assets with each sub-mesh instantiating a unique Receptacle.

* update receptacle names in test for new code

* refactor to use Meshdata internally

* convert triangle-like primitives to triangles.

* refactor to use Receptacle unique_name for sample filtering. Add support for filter files configured in scene instance config user_defined fields.

* refactor snapping functionality to improve stability by estimating consistency of support surface from bb corners projected in gravity direction

* Update habitat-lab/habitat/sims/habitat_simulator/sim_utilities.py

Co-authored-by: Aaron Gokaslan <[email protected]>

* turn off additional stability culling for now

* bugfix

* fix margin issues

* Add TODO comment

* Misc changes to work with merge

* Add missing import

* Fix target sampling bug

* Remove unneeded code

* Add changes to test previously missed

---------

Co-authored-by: Alexander Clegg <[email protected]>
Co-authored-by: Aaron Gokaslan <[email protected]>
dannymcy pushed a commit to dannymcy/habitat-lab that referenced this pull request Jul 8, 2024
…research#1108)

* updates to rearrange episode generation to support mesh receptacles and improved debugging

* docstrings and typing for DebugVisualizer util

* mesh receptacle debug_draw with global transforms

* add some tests for sampling accuracy

* bugfix - use default_sensor_uid instead of hardcoded "rgb" in DebugVisualizer

* adjust debug peek target to bb center to better capture objects not centered at COM

* add debug circles to the peek API

* add peek_scene variant for easliy getting images of a full scene or stage.
HHYHRHY pushed a commit to SgtVincent/EMOS that referenced this pull request Aug 31, 2024
…research#1108)

* updates to rearrange episode generation to support mesh receptacles and improved debugging

* docstrings and typing for DebugVisualizer util

* mesh receptacle debug_draw with global transforms

* add some tests for sampling accuracy

* bugfix - use default_sensor_uid instead of hardcoded "rgb" in DebugVisualizer

* adjust debug peek target to bb center to better capture objects not centered at COM

* add debug circles to the peek API

* add peek_scene variant for easliy getting images of a full scene or stage.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CLA Signed Do not delete this pull request or issue due to inactivity.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants