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
Add primitive and actor for pentagonal prism with test #474
Conversation
Hello @mehabhalodiya! Thanks for updating this PR. We checked the lines you've touched for PEP 8 issues, and found:
Comment last updated at 2021-09-03 09:52:14 UTC |
fury/tests/test_primitive.py
Outdated
onec = (five - 1) / 4.0 | ||
twoc = (five + 1) / 4.0 | ||
sone = (math.sqrt(10 + (2 * five))) / 4.0 | ||
stwo = (math.sqrt(10 - (2 * five))) / 4.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.
Hi @mehabhalodiya . Thanks for the PR.
More descriptive variable names will be better 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.
Can you suggest me some descriptive variable names?
I am asking because everywhere it's like (u, v), (c1, s1), etc.
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.
Please address the centering query that Serge has raised, if the prism is centered properly, I'll let you know some better variable names.
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 @mehabhalodiya,
Thank you so much for doing that!
Can you add a screenshot of this actor on your PR. When you add a screenshot, please, add also the actor.axes()
. Your pentagonal prism should be centered in (0,0,0) which is not currently the case. Adding the xyz axes will help you to see it.
Otherwise, see below some of my comments.
Thank you
fury/actor.py
Outdated
---------- | ||
centers : ndarray, shape (N, 3) | ||
Pentagonal prism positions | ||
directions : ndarray, shape (N, 3) |
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.
ndarray, shape (N, 3), optional
fury/actor.py
Outdated
Pentagonal prism positions | ||
directions : ndarray, shape (N, 3) | ||
The orientation vector of the pentagonal prism. | ||
colors : ndarray (N,3) or (N, 4) or tuple (3,) or tuple (4,) |
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/primitive.py
Outdated
@@ -626,6 +626,55 @@ def prim_triangularprism(): | |||
return vertices, triangles | |||
|
|||
|
|||
def prim_pentagonalprism(): | |||
"""Return vertices and triangle for an pentagonal prism. |
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.
typo: triangles
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.
typo: a instead of "an"
fury/primitive.py
Outdated
vertices = np.array([[-twoc, stwo, -1], | ||
[onec, sone, -1], | ||
[1, 0, -1], | ||
[onec, -sone, -1], | ||
[-twoc, -stwo, -1], | ||
[-twoc, stwo, 1], | ||
[onec, sone, 1], | ||
[1, 0, 1], | ||
[onec, -sone, 1], | ||
[-twoc, -stwo, 1]]) |
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.
are you sure that your coordinates are centered with (0,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.
Same comment as @SunTzunami, use more descriptive variable names.
fury/tests/test_primitive.py
Outdated
sone = (math.sqrt(10 + (2 * five))) / 4.0 | ||
stwo = (math.sqrt(10 - (2 * five))) / 4.0 | ||
npt.assert_equal(vertices.shape, shape) | ||
npt.assert_equal(np.mean(vertices), 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.
this test is failing because your primitive is not centered.
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.
Can you please help me to get it centered?
How can I do?
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.
Please, provide a screenshot of your actor with axes actor and then, we can have an idea and help you
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.
Done!
Updated! Please have a look @skoudoro @SunTzunami
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.
Please provide a better visual where the axes are visible, see this for reference.
fury/tests/test_primitive.py
Outdated
sone = (math.sqrt(10 + (2 * five))) / 4.0 | ||
stwo = (math.sqrt(10 - (2 * five))) / 4.0 | ||
npt.assert_equal(vertices.shape, shape) | ||
npt.assert_equal(np.mean(vertices), 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.
this test is failing because your primitive is not centered.
Thanks @SunTzunami for helping! Could you help @devmessias and @antrikshmisri? thank you in advance |
I updated the primitive:
@skoudoro @SunTzunami Requesting you to have a look! Let me know if it's alright, so that I can push the changes requested. |
Good job @mehabhalodiya, it looks much better! I did not try it yet, I will do it later but just make sure that your primitive is contained in the unit axes (actor.axes(scales=1)) and it will be perfect. your PR is close to be done |
fury/tests/test_primitive.py
Outdated
# Testing the default vertices of the primitive pentagonal prism. | ||
vertices, _ = fp.prim_pentagonalprism() | ||
shape = (10, 3) | ||
five = (float('{:.7f}'.format(math.sqrt(5)))) |
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. you should use round
instead of casting the number into a string and converting back into a float number
>>> import math
>>> (float('{:.7f}'.format(math.sqrt(5))))
2.236068
>>> round(math.sqrt(5), 7)
2.236068
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.
I believe the following test is more suitable. In addition, this will work.
def test_vertices_primitives_pentagonalprism():
# Testing the default vertices of the primitive pentagonal prism.
vertices, _ = fp.prim_pentagonalprism()
lower_face = vertices[:, 0:2][0:5, ]
upper_face = vertices[:, 0:2][5:10, ]
centroid_upper = np.mean(upper_face, 0)
centroid_lower = np.mean(lower_face, 0)
shape = (10, 3)
npt.assert_equal(vertices.shape, shape)
# This test will check whether the z-axis vertex dispersion is correct
npt.assert_almost_equal(np.mean(vertices[:, 2]), 0)
#check if the centroid of the upper face is at the origin
npt.assert_almost_equal(centroid_upper, np.array([0, 0]))
# check if the centroid of the lower face is at the origin
npt.assert_almost_equal(centroid_lower, np.array([0, 0]))
fury/primitive.py
Outdated
""" | ||
# Local variable to represent the square root of five rounded | ||
# to 7 decimal places | ||
five = float('{:.7f}'.format(math.sqrt(5))) |
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 comment about round method
Hi. you should use round instead of casting the number into a string and converting back into a float number
>>> import math
>>> (float('{:.7f}'.format(math.sqrt(5))))
2.236068
>>> round(math.sqrt(5), 7)
2.236068
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.
Are any special reason for rounding sqrt(5)? If not you should remove this and use just five = math.sqrt(5)
fury/primitive.py
Outdated
""" | ||
# Local variable to represent the square root of five rounded | ||
# to 7 decimal places | ||
five = float('{:.7f}'.format(math.sqrt(5))) |
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.
Are any special reason for rounding sqrt(5)? If not you should remove this and use just five = math.sqrt(5)
fury/tests/test_primitive.py
Outdated
# Testing the default vertices of the primitive pentagonal prism. | ||
vertices, _ = fp.prim_pentagonalprism() | ||
shape = (10, 3) | ||
five = (float('{:.7f}'.format(math.sqrt(5)))) |
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.
I believe the following test is more suitable. In addition, this will work.
def test_vertices_primitives_pentagonalprism():
# Testing the default vertices of the primitive pentagonal prism.
vertices, _ = fp.prim_pentagonalprism()
lower_face = vertices[:, 0:2][0:5, ]
upper_face = vertices[:, 0:2][5:10, ]
centroid_upper = np.mean(upper_face, 0)
centroid_lower = np.mean(lower_face, 0)
shape = (10, 3)
npt.assert_equal(vertices.shape, shape)
# This test will check whether the z-axis vertex dispersion is correct
npt.assert_almost_equal(np.mean(vertices[:, 2]), 0)
#check if the centroid of the upper face is at the origin
npt.assert_almost_equal(centroid_upper, np.array([0, 0]))
# check if the centroid of the lower face is at the origin
npt.assert_almost_equal(centroid_lower, np.array([0, 0]))
Hey @skoudoro, I have updated, PTAL. Thanks! |
Codecov Report
@@ Coverage Diff @@
## master #474 +/- ##
==========================================
+ Coverage 88.41% 88.96% +0.54%
==========================================
Files 31 33 +2
Lines 6519 7070 +551
Branches 782 832 +50
==========================================
+ Hits 5764 6290 +526
- Misses 535 547 +12
- Partials 220 233 +13
|
@mehabhalodiya please make the following changes (refer to the image below):
|
I don't know if H=L is mandatory. Maybe is better H to be a parameter. |
@SunTzunami How it's possible to pass two axes through edges? |
@mehabhalodiya Read my comment once again, I mentioned that the edge must pass through the y axis (in your case, it's passing through the x-axis), manipulate the coordinates in the primitive to ensure that it passes through the y-axis. |
fury/actor.py
Outdated
>>> dirs = np.random.rand(3, 3) | ||
>>> colors = np.random.rand(3, 3) | ||
>>> scales = np.random.rand(3, 1) | ||
>>> actor = actor.pentagonalprism(centers, dirs, colors, scales) |
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 should avoid to overwrite an import. In your case you have the same name for actor, which is a module from FURY, and the pentagonalprism. I think the following is better
from fury import window, actor
....
actor_pentagonal = actor.pentagonalprism(centers, dirs, colors, scales)
scene.add(actor_pentagonal)
@devmessias |
Scale just scales all the vertices. Using H as a parameter you can have things like that. But is just a matter of choice. In addition is not so hard to add this on actor.py def pentagonalprism(
centers, directions=(1, 0, 0), colors=(1, 0, 0), scales=1, height=1):
....
verts, faces = fp.prim_pentagonalprism(height) on primitives.py def prim_pentagonalprism(height=1.0):
....
vertices[:,2] = height*vertices[:,2]
triangles = np.array([[9, 5, 4],...
``` |
Makes sense. |
@SunTzunami @devmessias I have updated! Have a look:
Let me know if it's alright now! |
Hi @mehabhalodiya ! The figure looks pretty similar to what was required. Thank you for the update. I had one doubt: Have you set H=L (i.e. height of the prism = length of the side)? Otherwise it looks good to me. |
@SunTzunami PTAL! |
Hi @mehabhalodiya, thanks for addressing my suggestions. I see that you have fixed the example in the docstring and now H is a parameter. This PR looks good to me. |
Can anyone please let me know how to make: "The edges of rectangle = The edges of regular pentagon"? I have tried doing:
But looks like it's not working from my side! |
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.
I don't know if H=L is mandatory. Maybe is better H to be a parameter.
H=L does not need to be mandatory @SunTzunami.
I'm not sure if H should be added as a parameter as H (i.e. height) can be manipulated by using scales parameter of the actor. I'm insisting on keeping H = L as all other prisms have H = L.
I agree with @SunTzunami. No need to have H as parameter. scales
does the job. Otherwise, can you clarifies what will be the differences between H
and scales
? Let's keep it simple.
Hi @mehabhalodiya,
Thank you for this good job and apologies for the late reply. Your PR is in a good shape and no need to add more complex. See below for some comments and it will be ready to go
fury/actor.py
Outdated
@@ -1719,6 +1719,48 @@ def triangularprism(centers, directions=(1, 0, 0), colors=(1, 0, 0), | |||
return tri_actor | |||
|
|||
|
|||
def pentagonalprism(centers, directions=(1, 0, 0), colors=(1, 0, 0), | |||
scales=1, height=1): |
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 can remove height
, let's keep it simple
fury/primitive.py
Outdated
@@ -626,6 +626,55 @@ def prim_triangularprism(): | |||
return vertices, triangles | |||
|
|||
|
|||
def prim_pentagonalprism(height=1.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.
you can remove height
fury/primitive.py
Outdated
[0, -1/2, 1.84], | ||
[-sone/2, -onec/2, 1.84], | ||
[-stwo/2, twoc/2, 1.84]]) | ||
vertices[:, 2] = height*vertices[:, 2] |
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.
pep8: Can you add spaces between multiplication here. Thank you!
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.
If I am removing height
then how can I add vertices[:, 2] = height * vertices[:, 2]
line?
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.
Should I consider removing vertices[:, 2] = height*vertices[:, 2]
line?
def test_vertices_primitives_pentagonalprism(): | ||
# Testing the default vertices of the primitive pentagonal prism. | ||
vertices, _ = fp.prim_pentagonalprism() | ||
lower_face = vertices[:, 0:2][0:5, ] | ||
upper_face = vertices[:, 0:2][5:10, ] | ||
centroid_upper = np.mean(upper_face, 0) | ||
centroid_lower = np.mean(lower_face, 0) | ||
shape = (10, 3) | ||
npt.assert_equal(vertices.shape, shape) | ||
# This test will check whether the z-axis vertex dispersion is correct | ||
npt.assert_almost_equal(np.mean(vertices[:, 2]), 0) | ||
# check if the centroid of the upper face is at the origin | ||
npt.assert_almost_equal(centroid_upper, np.array([0, 0])) | ||
# check if the centroid of the lower face is at the origin | ||
npt.assert_almost_equal(centroid_lower, np.array([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.
great!
Hey @skoudoro , all the proposed changes have been added. PTAL. |
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.
Thank you for the quick update @mehabhalodiya!
Looks good! See below the last comment before merging
fury/primitive.py
Outdated
vertices = np.array([[stwo/2, twoc/2, -1.84], | ||
[sone/2, -onec/2, -1.84], | ||
[0, -1/2, -1.84], | ||
[-sone/2, -onec/2, -1.84], | ||
[-stwo/2, twoc/2, -1.84], | ||
[stwo/2, twoc/2, 1.84], | ||
[sone/2, -onec/2, 1.84], | ||
[0, -1/2, 1.84], | ||
[-sone/2, -onec/2, 1.84], | ||
[-stwo/2, twoc/2, 1.84]]) |
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.
instead of 1.84
on z-axes, can you use 0.5
. You might need to update the tests accordingly.
Hey @skoudoro , minor change of z-axes coordinates have been added. PTAL. |
Great! Thank you for this work and for this new actor! Thanks also to @SunTzunami and @devmessias for the nice and complete review. merging! |
I made a primitive for pentagonal prism and created an actor for the same.
Added tests for actor and primitive too.
Preview: