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

Added primitives count to the the Actor's polydata #617

Merged
merged 24 commits into from Jul 16, 2022

Conversation

m-agour
Copy link
Contributor

@m-agour m-agour commented Jul 1, 2022

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

Copy link
Contributor

@filipinascimento filipinascimento left a 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
Copy link
Contributor

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

@m-agour
Copy link
Contributor Author

m-agour commented Jul 4, 2022

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.

Thanks, @filipinascimento for your review. After today's meeting, I will check if the error is caused by this PR or something else.
Yes, the plan is to use what's done in this PR to do some operations on a single actor's primitives on both the GPU side (vertex shader maybe with the help of vertex-index attribute (not sure if this is a good solution)) and the CPU side (memory views as you mentioned).

Copy link
Contributor

@ganimtron-10 ganimtron-10 left a 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
Copy link
Contributor

Choose a reason for hiding this comment

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

,optional

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))
Copy link
Contributor

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

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)
Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor

@guaje guaje left a 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/tests/test_actors.py Show resolved Hide resolved
fury/tests/test_actors.py Outdated Show resolved Hide resolved
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)
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

fury/utils.py Outdated Show resolved Hide resolved
fury/utils.py Outdated Show resolved Hide resolved
@pep8speaks
Copy link

pep8speaks commented Jul 6, 2022

Hello @m-agour! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:

There are currently no PEP 8 issues detected in this Pull Request. Cheers! 🍻

Comment last updated at 2022-07-15 23:25:36 UTC

@m-agour m-agour requested a review from guaje July 6, 2022 18:36
@codecov
Copy link

codecov bot commented Jul 6, 2022

Codecov Report

Merging #617 (4907bd2) into master (63b87a8) will decrease coverage by 0.08%.
The diff coverage is 0.00%.

❗ Current head 4907bd2 differs from pull request most recent head f17f880. Consider uploading reports for the commit f17f880 to get more accurate results

Impacted file tree graph

@@            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     
Impacted Files Coverage Δ
fury/actor.py 0.00% <0.00%> (ø)
fury/ui/tests/test_elements_callback.py 0.00% <0.00%> (ø)
fury/utils.py 0.00% <0.00%> (ø)
fury/window.py 0.00% <0.00%> (ø)
fury/fury/tests/test_window.py 86.37% <0.00%> (-7.36%) ⬇️
fury/fury/data/fetcher.py 50.42% <0.00%> (-0.92%) ⬇️
fury/decorators.py 0.00% <0.00%> (ø)
fury/ui/elements.py 0.00% <0.00%> (ø)
fury/fury/decorators.py 100.00% <0.00%> (ø)
fury/ui/tests/test_elements.py 0.00% <0.00%> (ø)
... and 8 more

Copy link
Contributor

@guaje guaje left a 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_utils.py Outdated Show resolved Hide resolved
fury/tests/test_utils.py Outdated Show resolved Hide resolved
fury/utils.py Outdated Show resolved Hide resolved
fury/utils.py Outdated Show resolved Hide resolved
fury/utils.py Show resolved Hide resolved
fury/tests/test_actors.py Outdated Show resolved Hide resolved
fury/tests/test_actors.py Outdated Show resolved Hide resolved
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)
Copy link
Contributor

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?

Copy link
Contributor Author

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.

fury/tests/test_actors.py Outdated Show resolved Hide resolved
fury/tests/test_actors.py Outdated Show resolved Hide resolved
@m-agour
Copy link
Contributor Author

m-agour commented Jul 7, 2022

@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.

Hi, @guaje, thanks for rereviewing this PR, I made some of the changes and yes you are right this test can use some optimization.
I will restructure it tomorrow to use a for loop instead.

@skoudoro
Copy link
Contributor

Hi @m-agour,

What is the status of this PR?

@m-agour
Copy link
Contributor Author

m-agour commented Jul 13, 2022

Hi @m-agour,

What is the status of this PR?

Hi @skoudoro ,
I think it needs a final review after my last commits.

Copy link
Contributor

@guaje guaje left a 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.

fury/tests/test_utils.py Outdated Show resolved Hide resolved
fury/tests/test_utils.py Outdated Show resolved Hide resolved
fury/tests/test_actors.py Outdated Show resolved Hide resolved
@guaje
Copy link
Contributor

guaje commented Jul 15, 2022

LGTM. If there are no more comments, I'll merge this PR.

Anything else to add @filipinascimento, @skoudoro, @xtanion, @ganimtron-10?

Copy link
Contributor

@skoudoro skoudoro left a comment

Choose a reason for hiding this comment

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

Hi @m-agour,

it looks great! Apart from the small comments below, +1 for merging.

Thank you for this great review also @guaje. After tomorrow, Feel free to merge it.

[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],
Copy link
Contributor

Choose a reason for hiding this comment

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

actor.dot instead

Copy link
Contributor

Choose a reason for hiding this comment

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

the plural is deprecated.

@guaje
Copy link
Contributor

guaje commented Jul 16, 2022

@m-agour Good job! Merging.

@guaje guaje merged commit b89e526 into fury-gl:master Jul 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants