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
Added primitives count to the the Actor's polydata #617
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR is simple, but really important to anything that requires changing or interacting with individual elements of a multi entity actor.
It looks good to me. The tests are failing for other reasons.
Maybe for another PR, it would be interesting to have some auxiliary functions to directly access the memory view of positions, colors and other attributes of the independent entities.
fury/utils.py
Outdated
@@ -690,7 +719,8 @@ def get_actor_from_primitive(vertices, triangles, colors=None, | |||
culling of polygons based on orientation of normal with respect to | |||
camera. If backface culling is True, polygons facing away from camera | |||
are not drawn. Default: True | |||
|
|||
prim_count: bool | |||
primitives count inside the actor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe something like: primitives count to be associated with the actor
Thanks, @filipinascimento for your review. After today's meeting, I will check if the error is caused by this PR or something else. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @m-agour ,
Good Work. All the methods were well documented.
I have mentioned a few comments, PTAL.
Thanks!
fury/utils.py
Outdated
@@ -690,7 +719,8 @@ def get_actor_from_primitive(vertices, triangles, colors=None, | |||
culling of polygons based on orientation of normal with respect to | |||
camera. If backface culling is True, polygons facing away from camera | |||
are not drawn. Default: True | |||
|
|||
prim_count: int |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
,optional
fury/tests/test_actors.py
Outdated
centers = np.array([[1, 1, 1], [2, 2, 2]]) | ||
box_actor = actor.box(centers) | ||
npt.assert_equal(get_primitives_count_from_actor(box_actor), len(centers)) | ||
box_actor = actor.sphere(centers, (1, 0, 0)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe sphere_actor
or sphere
fury/tests/test_actors.py
Outdated
npt.assert_equal(get_primitives_count_from_actor(box_actor), len(centers)) | ||
box_actor = actor.sphere(centers, (1, 0, 0)) | ||
npt.assert_equal(get_primitives_count_from_actor(box_actor), len(centers)) | ||
box_actor = actor.sphere(centers, (1, 0, 0), use_primitive=True) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
or above name with prim_
prefix to differentiate the actors
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, @ganimtron-10 for your review! Helpful as always.
This reverts commit d940fe6.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@m-agour This is a much-needed feature. Thanks for this PR.
I have added some comments, see below.
fury/utils.py
Outdated
@@ -715,6 +745,7 @@ def get_actor_from_primitive(vertices, triangles, colors=None, | |||
|
|||
current_actor = get_actor_from_polydata(pd) | |||
current_actor.GetProperty().SetBackfaceCulling(backface_culling) | |||
add_primitives_count_to_actor(current_actor, prim_count) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You might see in the utils.py
file that we have both the get/set_polydata_property
(e.g., get_polydata_normals and set_polydata_normals) and the property_from/to_actor
(e.g., normals_from_actor and normals_to_actor). The reason for this is that the polydata functions are meant to be used for tasks like actor creations since at some point you'll have access to the polydata before it goes to the mapper. While the actor functions are for specific use cases, they generally require getting the mapper to get the polydata to get the desired attribute finally. This process is inefficient. Therefore, I would recommend adding the respective get/set_polydata_primitives_count
and using them here since you can access the polydata here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hello @guaje, thanks for your review. I made all the changes you requested I believe.
I also noticed this PR was not applicable on some actors while doing the tests. so I had them added.
I hope I didn't miss anything.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that has happened on several occasions. That was the main reason I asked you to test all the supported actors. In the past, we have assumed that some functions are supposed to work equally on all the actors, yet unfortunately, that's not the case since we have different methods to create them.
Codecov Report
@@ Coverage Diff @@
## master #617 +/- ##
==========================================
- Coverage 51.84% 51.76% -0.09%
==========================================
Files 105 105
Lines 22337 22941 +604
Branches 2460 2532 +72
==========================================
+ Hits 11581 11875 +294
- Misses 10381 10685 +304
- Partials 375 381 +6
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@m-agour Thanks for adding the missing tests.
I have added the following comments based on the latest update. Additionally, I noticed you added primitives_count
support to the square actor but there is no test for it. Last, but not least important, take a look at this test. It could help you to improve your tests.
fury/tests/test_actors.py
Outdated
sphere_actor = actor.sphere(centers, colors) | ||
npt.assert_equal(get_actor_primitives_count(sphere_actor), len(centers)) | ||
|
||
prim_sphere_actor = actor.sphere(centers, colors, use_primitive=False) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't use_primitive
= False by default?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but I thought this might get changed at any time (use_primitive=True
by default). so it's better to explicitly set it to keep the tests valid.
Hi, @guaje, thanks for rereviewing this PR, I made some of the changes and yes you are right this test can use some optimization. |
Hi @m-agour, What is the status of this PR? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Just some renaming for 2 functions left.
LGTM. If there are no more comments, I'll merge this PR. Anything else to add @filipinascimento, @skoudoro, @xtanion, @ganimtron-10? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fury/tests/test_actors.py
Outdated
[actor.cone, {**args_3, 'use_primitive': True}, cen_c], | ||
[actor.arrow, {**args_3, 'repeat_primitive': False}, cen_c], | ||
[actor.arrow, {**args_3, 'repeat_primitive': True}, cen_c], | ||
[actor.dots, {'points': centers}, cen_c], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actor.dot
instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the plural is deprecated.
@m-agour Good job! Merging. |
As @filipinascimento, @guaje, and I was trying to find an approach to only apply the keyframe animation on a partial subset of the actor's primitives not all of them, we found that there is no currently implemented way to get the primitives count of a single actor.
In this PR, the primitive's count is saved inside the polydata of the actor.
This can be used to distinguish the vertices of different primitives