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

Refinement of various scene functions #1385

Merged
merged 10 commits into from
Aug 22, 2024
Merged

Refinement of various scene functions #1385

merged 10 commits into from
Aug 22, 2024

Conversation

tomvanmele
Copy link
Member

A few backwards compatible tweaks to the scene functionality, especially refinement of how things are cleared from the viz context...

What type of change is this?

  • Bug fix in a backwards-compatible manner.
  • New feature in a backwards-compatible manner.
  • Breaking change: bug fix or new feature that involve incompatible API changes.
  • Other (e.g. doc update, configuration, etc)

Checklist

Put an x in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code.

  • I added a line to the CHANGELOG.md file in the Unreleased section under the most fitting heading (e.g. Added, Changed, Removed).
  • I ran all tests on my computer and it's all green (i.e. invoke test).
  • I ran lint on my computer and there are no errors (i.e. invoke lint).
  • I added new functions/classes and made them available on a second-level import, e.g. compas.datastructures.Mesh.
  • I have added tests that prove my fix is effective or that my feature works.
  • I have added necessary documentation (if appropriate)

Copy link

codecov bot commented Aug 22, 2024

Codecov Report

Attention: Patch coverage is 52.94118% with 8 lines in your changes missing coverage. Please review.

Project coverage is 60.24%. Comparing base (82af17e) to head (6310194).
Report is 11 commits behind head on main.

Files Patch % Lines
src/compas/scene/scene.py 50.00% 8 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1385      +/-   ##
==========================================
+ Coverage   60.21%   60.24%   +0.02%     
==========================================
  Files         207      207              
  Lines       22248    22244       -4     
==========================================
+ Hits        13397    13401       +4     
+ Misses       8851     8843       -8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@gonzalocasas gonzalocasas left a comment

Choose a reason for hiding this comment

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

There's a big chunk of commented out code in the mesh object, is that replaced by anything or just removed functionality?

Did you have the chance to verify this change also for the Grasshopper scene objects?

@tomvanmele
Copy link
Member Author

the commented out part is (mostly) related to labels, which i think we should handle independently from the individual types of objects in order to avoid repetition. have left it there as a reminder...

@tomvanmele
Copy link
Member Author

haven't checked GH, but the default behaviour of all functionality remains the same. so i don't expect any problems...

@tomvanmele
Copy link
Member Author

the commented out part is (mostly) related to labels, which i think we should handle independently from the individual types of objects in order to avoid repetition. have left it there as a reminder...

in any case, the removed code paths were not (obviously) accessible nor documented so i assume there is no real issue.

Copy link
Member

@gonzalocasas gonzalocasas left a comment

Choose a reason for hiding this comment

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

I added some inline comments, but the biggest prob right now is that GH mesh object doesn't work at all (I guess it needs the same refactoring regarding vertex_xyz).
The other issue is that the removal of draw_vertexlabels, draw_edgelabels, draw_facelabels, draw_vertexnormals, draw_facenormals is not so undocumented as mentioned. We use them pretty much every single time in workshops and intro classes to compas. I don't think it can just go away.

Comment on lines 119 to 131
def clear_context(self, guids=None):
# type: (list | None) -> None
"""Clear all objects from the visualisation context."""
clear(guids)

clear()
def clear(self, clear_scene=True, clear_context=True):
# type: (bool, bool) -> None
"""Clear all objects inside the scene.

def clear_objects(self):
# type: () -> None
"""Clear all objects inside the scene."""
Parameters
----------
context : bool, optional
Clear all objects from the context as well.
Copy link
Member

Choose a reason for hiding this comment

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

This could indeed have a simple test to cover it, because the clear/clear_context is already not clear enough by the naming, so, at least adding a test would ensure that this is not broken in the future by accident.

@@ -215,7 +151,7 @@ def draw(self):
disjoint=self.disjoint,
)

# geometry.Transform(transformation_to_rhino(self.worldtransformation))
geometry.Transform(transformation_to_rhino(self.worldtransformation))
Copy link
Member

Choose a reason for hiding this comment

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

This is weird, do you know why it was commented out and why it's needed now?

Copy link
Member Author

Choose a reason for hiding this comment

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

scene objects can have a transformation. before it was applied through the vertex caching. now it is done explicitly here...

self._guids_vertices = guids
self._guid_vertex = dict(zip(guids, vertices))

self._guids += guids
Copy link
Member

Choose a reason for hiding this comment

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

This causes an error if the scene has not been drawn at least once because self._guids is None. Maybe should be initialized on __init__

Copy link
Member Author

Choose a reason for hiding this comment

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

ha weird maybe i forgot to push this

Copy link
Member

Choose a reason for hiding this comment

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

if you have a scene.draw() before trying something like scene_object.draw_faces() it works, but I guess it's a valid case to just draw the faces before drawing the full scene:

import compas
from compas.datastructures import Mesh
from compas.scene import Scene
from compas.colors import Color


# Load a mesh from a sample OBJ file
mesh = Mesh.from_obj(compas.get("tubemesh.obj"))

scene = Scene()
sp = scene.add(mesh)

sp.draw_faces()  # this line fails if draw() is after
# drawing scene after faces causes the exception
# scene.draw()

Copy link
Member Author

Choose a reason for hiding this comment

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

shoud be fixed now

@tomvanmele
Copy link
Member Author

I added some inline comments, but the biggest prob right now is that GH mesh object doesn't work at all (I guess it needs the same refactoring regarding vertex_xyz). The other issue is that the removal of draw_vertexlabels, draw_edgelabels, draw_facelabels, draw_vertexnormals, draw_facenormals is not so undocumented as mentioned. We use them pretty much every single time in workshops and intro classes to compas. I don't think it can just go away.

ok. i can put those back. it is actually not crucial for the PR

@tomvanmele
Copy link
Member Author

will review and push new soon

@Licini
Copy link
Contributor

Licini commented Aug 22, 2024

LGTM! but will leave @gonzalocasas to say final yes : )

Copy link
Member

@gonzalocasas gonzalocasas left a comment

Choose a reason for hiding this comment

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

LGTM! One last request though: if the draw_vertexnormals and draw_facenormals will remain commented out, please add their removal to the changelog

@tomvanmele tomvanmele merged commit f3f1fda into main Aug 22, 2024
16 of 17 checks passed
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