fury-gl / fury

FURY - Free Unified Rendering in pYthon.
https://fury.gl
Other
241 stars 181 forks source link

add one condition in `repeat_primitive` to handle direction [-1, 0, 0], issue #770 #771

Closed Clarkszw closed 1 year ago

Clarkszw commented 1 year ago

Fix the issue #770.

The cause is directions = np.array([1, 0 ,0 ]), which is a (3, ) 1 dimension array. It is ok for repeat_primitive() to use 1d array, it will be processed to np.ndarray in the function. But for VTK method, directions parameter has to be np.ndarry(N,3)

Issue 1 can be resolved by modify the directions to directions = np.array([[1, 0, 0]]) as a (1,3) ndarray.

For Issue 2, I have add a condition to cover the case directions = [-1, 0, 0]

image

Code to reproduce:

from fury import window, actor
import numpy as np

scene = window.Scene()
showm = window.ShowManager(scene,size=(1024, 720), reset_camera=False)
showm.initialize()

centers = np.array([[0, 0, 0]])
directions = np.array([[1, 0 ,0 ]])
colors_primitive = np.array([1,0,0])
colors_no_primitive = np.array([0,1,0])

for i in range(35):

    centers = centers + np.array([[1.2, 0, 0]])

    theta_rad = np.deg2rad(10)
    rotation_z = np.array([[np.cos(theta_rad), -np.sin(theta_rad), 0],
                           [np.sin(theta_rad),  np.cos(theta_rad), 0],
                           [0,  0, 1]])

    directions = np.dot(rotation_z, directions.T).T

    arrow_primitive = actor.arrow(centers, directions, colors_primitive, repeat_primitive=True)

    centers_2 = centers + np.array([[0, 1.2, 0]])

    arrow_no_primitive = actor.arrow(centers_2, directions, colors_no_primitive, repeat_primitive=False)

    scene.add(arrow_primitive,arrow_no_primitive)

showm.start()
Clarkszw commented 1 year ago

unit test for directions [-1, 0, 0], [0, -1, 0] and [0, 0, -1] added