fury-gl / fury

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

Directions of arrow actor do not change in `repeat_primitive = False` method (VTK) #770

Closed Clarkszw closed 1 year ago

Clarkszw commented 1 year ago

Description

There are two issues present in the picture below: Note: red arrow is repeat_primitive = True, green arrow is repeat_primitive = False

  1. Directions of arrow actor do not change when applying no_repeat_primitive (repeat_primitive = False) method (VTK)
  2. When direction is [-1, 0, 0], the repeat_primitive (repeat_primitive = True) does not return the arrow actor.
image

below is the code:

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 ])
heights = 1
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, 
                           heights=heights, repeat_primitive=True)

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

    scene.add(arrow_primitive,arrow_no_primitive)

showm.start()
skoudoro commented 1 year ago

Thank you for this issue and analyse.

Clearly, we have to spend time to understand what is the rotation difference between primitive and vtk source. This will fix the issue of many actors

Clarkszw commented 1 year ago

I am investigating it now, interesting to refresh some mathematic concept in rotation ;)

Clarkszw commented 1 year ago

The cause is directions = np.array([1, 0 ,0 ]) 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]])

For Issue 2, I have add a condition to cover the case directions = [-1, 0, 0], I will make a pull request for it.

skoudoro commented 1 year ago

closed by #771