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
NF: adding primitive stars, 3D stars, rhombi. #170
Changes from all commits
f2faa07
cf93bee
fef0bae
24ca40b
88bf418
c990dfd
90806ad
795551e
b0dc9ed
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,7 +33,7 @@ def faces_from_sphere_vertices(vertices): | |
""" | ||
hull = ConvexHull(vertices, qhull_options='Qbb Qc') | ||
faces = np.ascontiguousarray(hull.simplices) | ||
if len(vertices) < 2**16: | ||
if len(vertices) < 2 ** 16: | ||
return np.asarray(faces, np.uint16) | ||
else: | ||
return faces | ||
|
@@ -117,18 +117,19 @@ def repeat_primitive(vertices, faces, centers, directions=(1, 0, 0), | |
Expanded triangles that composed our shape to duplicate | ||
big_colors : ndarray | ||
Expanded colors applied to all vertices/faces | ||
big_centers : ndarray | ||
Expanded centers for all vertices/faces | ||
|
||
""" | ||
# duplicated vertices if needed | ||
if not have_tiled_verts: | ||
vertices = np.tile(vertices, (centers.shape[0], 1)) | ||
big_vertices = vertices | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you explain why do you remove |
||
# Get unit shape | ||
unit_verts_size = vertices.shape[0] // centers.shape[0] | ||
unit_triangles_size = faces.shape[0] | ||
|
||
big_centers = np.repeat(centers, unit_verts_size, axis=0) | ||
# apply centers position | ||
big_vertices = vertices + big_centers | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same questions as above, I don't understand why you add this part? Please, can you explain ? |
||
# scale them | ||
if isinstance(scale, (list, tuple, np.ndarray)): | ||
scale = np.repeat(scale, unit_verts_size, axis=0) | ||
|
@@ -137,16 +138,16 @@ def repeat_primitive(vertices, faces, centers, directions=(1, 0, 0), | |
|
||
# update triangles | ||
big_triangles = np.array(np.tile(faces, | ||
(centers.shape[0], 1)), | ||
(centers.shape[0], 1)), | ||
dtype=np.int32) | ||
big_triangles += np.repeat(np.arange(0, centers.shape[0] * | ||
unit_verts_size, step=unit_verts_size), | ||
unit_verts_size, step=unit_verts_size), | ||
unit_triangles_size, | ||
axis=0).reshape((big_triangles.shape[0], 1)) | ||
|
||
def normalize_input(arr, arr_name=''): | ||
if isinstance(arr, (tuple, list, np.ndarray)) and len(arr) == 3 and \ | ||
not all(isinstance(i, (list, tuple, np.ndarray)) for i in arr): | ||
not all(isinstance(i, (list, tuple, np.ndarray)) for i in arr): | ||
return np.array([arr] * centers.shape[0]) | ||
elif isinstance(arr, np.ndarray) and len(arr) == 1: | ||
return np.repeat(arr, centers.shape[0], axis=0) | ||
|
@@ -163,20 +164,18 @@ def normalize_input(arr, arr_name=''): | |
|
||
# update orientations | ||
directions = normalize_input(directions, 'directions') | ||
big_vertices -= big_centers | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same questions as above? |
||
for pts, dirs in enumerate(directions): | ||
ai, aj, ak = transform.Rotation.from_rotvec(np.pi/2 * dirs). \ | ||
ai, aj, ak = transform.Rotation.from_rotvec(np.pi / 2 * dirs). \ | ||
as_euler('zyx') | ||
rotation_matrix = euler_matrix(ai, aj, ak) | ||
big_vertices[pts * unit_verts_size: (pts+1) * unit_verts_size] = \ | ||
big_vertices[pts * unit_verts_size: (pts + 1) * unit_verts_size] = \ | ||
np.dot(rotation_matrix[:3, :3], | ||
big_vertices[pts * unit_verts_size: | ||
(pts+1) * unit_verts_size].T).T | ||
|
||
# apply centers position | ||
big_centers = np.repeat(centers, unit_verts_size, axis=0) | ||
(pts + 1) * unit_verts_size].T).T | ||
big_vertices += big_centers | ||
|
||
return big_vertices, big_triangles, big_colors, big_centers | ||
return big_vertices, big_triangles, big_colors | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do you remove |
||
|
||
|
||
def prim_square(): | ||
|
@@ -313,6 +312,7 @@ def prim_superquadric(roundness=(1, 1), sphere_name='symmetric362'): | |
True | ||
|
||
""" | ||
|
||
def _fexp(x, p): | ||
"""Return a different kind of exponentiation.""" | ||
return np.sign(x) * (np.abs(x) ** p) | ||
|
@@ -329,3 +329,170 @@ def _fexp(x, p): | |
vertices = np.ascontiguousarray(xyz) | ||
|
||
return vertices, sphere_triangles | ||
|
||
|
||
def prim_rhombicuboctahedron(): | ||
"""Return vertices and triangle for rhombicuboctahedron geometry | ||
|
||
Parameters | ||
---------- | ||
|
||
Returns | ||
------- | ||
my_vertices: ndarray | ||
vertices coords that composed our rhombicuboctahedron | ||
my_triangles: ndarray | ||
Triangles that composed our rhombicuboctahedron | ||
""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing an empty line |
||
my_vertices = np.array([[-2, 4, 2], | ||
[-4, 2, 2], | ||
[-4, -2, 2], | ||
[-2, -4, 2], | ||
[2, -4, 2], | ||
[4, -2, 2], | ||
[4, 2, 2], | ||
[2, 4, 2], | ||
[-2, 2, 4], | ||
[-2, -2, 4], | ||
[2, -2, 4], | ||
[2, 2, 4], | ||
[-2, 4, -2], | ||
[-4, 2, -2], | ||
[-4, -2, -2], | ||
[-2, -4, -2], | ||
[2, -4, -2], | ||
[4, -2, -2], | ||
[4, 2, -2], | ||
[2, 4, -2], | ||
[-2, 2, -4], | ||
[-2, -2, -4], | ||
[2, -2, -4], | ||
[2, 2, -4]]) | ||
|
||
my_triangles = np.array([[0, 1, 8], | ||
[1, 2, 9], | ||
[1, 8, 9], | ||
[2, 3, 9], | ||
[3, 9, 10], | ||
[3, 4, 10], | ||
[4, 10, 5], | ||
[5, 11, 10], | ||
[5, 6, 11], | ||
[6, 7, 11], | ||
[7, 8, 11], | ||
[7, 8, 0], | ||
[8, 9, 10], | ||
[8, 10, 11], | ||
[12, 13, 20], | ||
[13, 14, 21], | ||
[13, 20, 21], | ||
[14, 15, 21], | ||
[15, 21, 22], | ||
[15, 16, 22], | ||
[16, 22, 17], | ||
[17, 22, 23], | ||
[17, 23, 18], | ||
[18, 19, 23], | ||
[19, 20, 23], | ||
[19, 20, 12], | ||
[20, 21, 22], | ||
[20, 22, 23], | ||
[7, 18, 19], | ||
[6, 7, 18], | ||
[6, 17, 18], | ||
[5, 6, 17], | ||
[4, 5, 16], | ||
[5, 16, 17], | ||
[0, 1, 12], | ||
[1, 12, 13], | ||
[1, 2, 13], | ||
[2, 13, 14], | ||
[2, 3, 14], | ||
[3, 14, 15], | ||
[0, 7, 12], | ||
[7, 12, 19], | ||
[3, 15, 16], | ||
[3, 4, 16], | ||
], dtype='i8') | ||
return my_vertices, my_triangles | ||
|
||
|
||
def prim_star(dim=2): | ||
"""Return vertices and triangle for star geometry | ||
|
||
Parameters | ||
---------- | ||
dim: int | ||
Represents the dimension of the wanted star | ||
|
||
Returns | ||
------- | ||
vertices: ndarray | ||
vertices coords that composed our star | ||
triangles: ndarray | ||
Triangles that composed our star | ||
|
||
""" | ||
if dim == 2: | ||
vert = np.array([[-2.0, -3.0, 0.0], | ||
[0.0, -2.0, 0.0], | ||
[3.0, -3.0, 0.0], | ||
[2.0, -1.0, 0.0], | ||
[3.0, 1.0, 0.0], | ||
[1.0, 1.0, 0.0], | ||
[0.0, 3.0, 0.0], | ||
[-1.0, 1.0, 0.0], | ||
[-3.0, 1.0, 0.0], | ||
[-2.0, -1.0, 0.0]]) | ||
|
||
triangles = np.array([[1, 9, 0], | ||
[1, 2, 3], | ||
[3, 4, 5], | ||
[5, 6, 7], | ||
[7, 8, 9], | ||
[1, 9, 3], | ||
[3, 7, 9], | ||
[3, 5, 7]], dtype='i8') | ||
|
||
if dim == 3: | ||
vert = np.array([[-3.0, -3.0, 0.0], | ||
[0.0, -2, 0.0], | ||
[3.0, -3.0, 0.0], | ||
[2.0, -1.0, 0.0], | ||
[3.0, 1.0, 0.0], | ||
[1.0, 1.0, 0.0], | ||
[0, 3.0, 0.0], | ||
[-1.0, 1.0, 0.0], | ||
[-3.0, 1.0, 0.0], | ||
[-2.0, -1.0, 0.0], | ||
[2.0, 1.5, 1.0], | ||
[2.0, 1.5, -1.0]]) | ||
triangles = np.array([[1, 9, 0], | ||
[1, 2, 3], | ||
[3, 4, 5], | ||
[5, 6, 7], | ||
[7, 8, 9], | ||
[1, 9, 3], | ||
[3, 7, 9], | ||
[3, 5, 7], | ||
[1, 0, 10], | ||
[0, 9, 10], | ||
[10, 9, 8], | ||
[7, 8, 10], | ||
[6, 7, 10], | ||
[5, 6, 10], | ||
[5, 10, 4], | ||
[10, 3, 4], | ||
[3, 10, 2], | ||
[10, 1, 2], | ||
[1, 0, 11], | ||
[0, 9, 11], | ||
[11, 9, 8], | ||
[7, 8, 10], | ||
[6, 7, 11], | ||
[5, 6, 11], | ||
[5, 10, 4], | ||
[11, 3, 4], | ||
[3, 11, 2], | ||
[11, 1, 2]], dtype='i8') | ||
return vert, triangles |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,18 +2,24 @@ | |
import numpy.testing as npt | ||
import fury.primitive as fp | ||
|
||
|
||
def test_vertices_primitives(): | ||
l_primitives = [(fp.prim_square, (4, 3)), | ||
(fp.prim_box, (8, 3))] | ||
l_primitives = [(fp.prim_square, (4, 3), -.5, .5, 0), | ||
(fp.prim_box, (8, 3), -.5, .5, 0), | ||
(fp.prim_star, (10, 3), -3, 3, -0.06666666666666667), | ||
(fp.prim_rhombicuboctahedron, (24, 3), -4, 4, 0)] | ||
|
||
for func, shape in l_primitives: | ||
for func, shape, min, max, mean in l_primitives: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
vertices, _ = func() | ||
|
||
npt.assert_equal(vertices.shape, shape) | ||
npt.assert_equal(np.mean(vertices), 0) | ||
npt.assert_equal(vertices.min(), -.5) | ||
npt.assert_equal(vertices.max(), 0.5) | ||
npt.assert_equal(np.mean(vertices), mean) | ||
npt.assert_equal(vertices.min(), min) | ||
npt.assert_equal(vertices.max(), max) | ||
|
||
vertices, _ = fp.prim_star(3) | ||
npt.assert_equal(vertices.shape, (12, 3)) | ||
npt.assert_equal(np.mean(vertices), 0.1111111111111111) | ||
npt.assert_equal(vertices.min(), -3) | ||
npt.assert_equal(vertices.max(), 3) | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. empty line to remove |
||
def test_triangles_primitives(): | ||
|
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 explain why you remove this docstring ?