From c141f31916bbfc6a7786f99e5f7212eba4a0c3e6 Mon Sep 17 00:00:00 2001 From: Robin Roy Date: Sat, 16 Mar 2024 01:25:32 +0530 Subject: [PATCH] Added center coordinate parameter, used util.py helper function to simplify code, modified the tests for the coordinate change --- fury/actor.py | 47 ++++++++++++++++++++++----------------- fury/tests/test_actors.py | 5 ++++- 2 files changed, 31 insertions(+), 21 deletions(-) diff --git a/fury/actor.py b/fury/actor.py index 3f6c93623..44402eef3 100644 --- a/fury/actor.py +++ b/fury/actor.py @@ -75,6 +75,7 @@ get_actor_from_primitive, lines_to_vtk_polydata, numpy_to_vtk_colors, + numpy_to_vtk_image_data, repeat_sources, rgb_to_vtk, set_input, @@ -3960,7 +3961,17 @@ def uncertainty_cone( class TexturedCube: """Class to work with textured cube.""" - def __init__(self, negx, negy, negz, posx, posy, posz): + def __init__(self, + negx, + negy, + negz, + posx, + posy, + posz, + center_x: int = 0, + center_y: int = 0, + center_z: int = 0, + ): """Initializes a TexturedCube object. Parameters @@ -3977,6 +3988,12 @@ def __init__(self, negx, negy, negz, posx, posy, posz): Input 2D RGB or RGBA array. Dtype should be uint8. posz : ndarray Input 2D RGB or RGBA array. Dtype should be uint8. + center_x : int, optional + X-Coordinate of the cube. + center_y : int, optional + Y-Coordinate of the cube. + center_z : int, optional + Z-Coordinate of the cube. |----| | +Y | @@ -3991,12 +4008,12 @@ def __init__(self, negx, negy, negz, posx, posy, posz): self.planes = [PlaneSource() for _ in range(6)] self.plane_centers = [ - (-0.5, 0.5, 0.5), - (0, 0, 0.5), - (0, 0.5, 0), - (0.5, 0.5, 0.5), - (0, 1, 0.5), - (0, 0.5, 1) + (-0.5 + center_x, 0.5 + center_y, 0.5 + center_z), + (0 + center_x, 0 + center_y, 0.5 + center_z), + (0 + center_x, 0.5 + center_y, 0 + center_z), + (0.5 + center_x, 0.5 + center_y, 0.5 + center_z), + (0 + center_x, 1 + center_y, 0.5 + center_z), + (0 + center_x, 0.5 + center_y, 1 + center_z) ] self.plane_normals = [ @@ -4017,20 +4034,10 @@ def __init__(self, negx, negy, negz, posx, posy, posz): plane.SetNormal(*normal) self.image_grids = [negx, negy, negz, posx, posy, posz] - self.image_data_objs = [ImageData() for _ in range(6)] - for grid, image_data_obj in zip( - self.image_grids, - self.image_data_objs - ): - image_data_obj.SetDimensions(grid.shape[1], grid.shape[0], 1) - numpy_flip = np.flip(grid.swapaxes(0, 1), axis=1) - numpy_flip = numpy_flip.reshape((-1, 3), order='F') - vtkarr = numpy_support.numpy_to_vtk(numpy_flip) - vtkarr.SetName('Image') - - image_data_obj.GetPointData().AddArray(vtkarr) - image_data_obj.GetPointData().SetActiveScalars('Image') + self.image_data_objs = [ + numpy_to_vtk_image_data(grid) for grid in self.image_grids + ] self.texture_objects = [Texture() for _ in range(6)] diff --git a/fury/tests/test_actors.py b/fury/tests/test_actors.py index c04d0f60b..673b1dfad 100644 --- a/fury/tests/test_actors.py +++ b/fury/tests/test_actors.py @@ -1901,7 +1901,10 @@ def test_texturedcube(interactive=False): arr_green, arr_blue, arr_yellow, - arr_aqua) + arr_aqua, + 1, + 2, + 3) cube_actor = cube.get_actor()