diff --git a/fury/actor.py b/fury/actor.py index 01ff0ba6b..346373bc9 100644 --- a/fury/actor.py +++ b/fury/actor.py @@ -15,6 +15,7 @@ tensor_ellipsoid, ) from fury.colormap import colormap_lookup_table +from fury.decorators import warn_on_args_to_kwargs from fury.deprecator import deprecate_with_version, deprecated_params from fury.io import load_image from fury.lib import ( @@ -88,8 +89,10 @@ ) +@warn_on_args_to_kwargs() def slicer( data, + *, affine=None, value_range=None, opacity=1.0, @@ -265,7 +268,8 @@ def display_extent(self, x1, x2, y1, y2, z1, z2): # line = np.array([[xmin, ymin, zmin]]) # self.outline_actor = actor.line() - def display(self, x=None, y=None, z=None): + @warn_on_args_to_kwargs() + def display(self, *, x=None, y=None, z=None): if x is None and y is None and z is None: self.display_extent(ex1, ex2, ey1, ey2, ez2 // 2, ez2 // 2) if x is not None: @@ -350,7 +354,8 @@ def shallow_copy(self): return image_actor -def surface(vertices, faces=None, colors=None, smooth=None, subdivision=3): +@warn_on_args_to_kwargs() +def surface(vertices, *, faces=None, colors=None, smooth=None, subdivision=3): """Generate a surface actor from an array of vertices. The color and smoothness of the surface can be customized by specifying @@ -427,7 +432,8 @@ def surface(vertices, faces=None, colors=None, smooth=None, subdivision=3): return surface_actor -def contour_from_roi(data, affine=None, color=None, opacity=1): +@warn_on_args_to_kwargs() +def contour_from_roi(data, *, affine=None, color=None, opacity=1): """Generate surface actor from a binary ROI. The color and opacity of the surface can be customized. @@ -546,7 +552,8 @@ def contour_from_roi(data, affine=None, color=None, opacity=1): return skin_actor -def contour_from_label(data, affine=None, color=None): +@warn_on_args_to_kwargs() +def contour_from_label(data, *, affine=None, color=None): """Generate surface actor from a labeled Array. The color and opacity of individual surfaces can be customized. @@ -591,15 +598,17 @@ def contour_from_label(data, affine=None, color=None): for i, roi_id in enumerate(unique_roi_id): roi_data = np.isin(data, roi_id).astype(int) roi_surface = contour_from_roi( - roi_data, affine, color=color[i], opacity=opacity[i] + roi_data, affine=affine, color=color[i], opacity=opacity[i] ) unique_roi_surfaces.AddPart(roi_surface) return unique_roi_surfaces +@warn_on_args_to_kwargs() def streamtube( lines, + *, colors=None, opacity=1, linewidth=0.1, @@ -667,7 +676,7 @@ def streamtube( >>> scene = window.Scene() >>> lines = [np.random.rand(10, 3), np.random.rand(20, 3)] >>> colors = np.random.rand(2, 3) - >>> c = actor.streamtube(lines, colors) + >>> c = actor.streamtube(lines, colores=colors) >>> scene.add(c) >>> #window.show(scene) @@ -765,8 +774,10 @@ def streamtube( return actor +@warn_on_args_to_kwargs() def line( lines, + *, colors=None, opacity=1, linewidth=1, @@ -837,7 +848,7 @@ def line( >>> scene = window.Scene() >>> lines = [np.random.rand(10, 3), np.random.rand(20, 3)] >>> colors = np.random.rand(2, 3) - >>> c = actor.line(lines, colors) + >>> c = actor.line(lines, colors=colors) >>> scene.add(c) >>> #window.show(scene) @@ -887,7 +898,8 @@ def line( if depth_cue: - def callback(_caller, _event, calldata=None): + @warn_on_args_to_kwargs() + def callback(_caller, _event, *, calldata=None): program = calldata if program is not None: program.SetUniformf("linewidth", linewidth) @@ -901,7 +913,8 @@ def callback(_caller, _event, calldata=None): return actor -def scalar_bar(lookup_table=None, title=" "): +@warn_on_args_to_kwargs() +def scalar_bar(*, lookup_table=None, title=" "): """Default scalar bar actor for a given colormap (colorbar). Parameters @@ -932,8 +945,14 @@ def scalar_bar(lookup_table=None, title=" "): return scalar_bar +@warn_on_args_to_kwargs() def axes( - scale=(1, 1, 1), colorx=(1, 0, 0), colory=(0, 1, 0), colorz=(0, 0, 1), opacity=1 + *, + scale=(1, 1, 1), + colorx=(1, 0, 0), + colory=(0, 1, 0), + colorz=(0, 0, 1), + opacity=1, ): """Create an actor with the coordinate's system axes where red = x, green = y, blue = z. @@ -961,12 +980,14 @@ def axes( colors = np.array([colorx + (opacity,), colory + (opacity,), colorz + (opacity,)]) scales = np.asarray(scale) - arrow_actor = arrow(centers, dirs, colors, scales, repeat_primitive=False) + arrow_actor = arrow(centers, dirs, colors, scales=scales, repeat_primitive=False) return arrow_actor +@warn_on_args_to_kwargs() def odf_slicer( odfs, + *, affine=None, mask=None, sphere=None, @@ -1083,7 +1104,8 @@ def _makeNd(array, ndim): return array.reshape(new_shape) -def _roll_evals(evals, axis=-1): +@warn_on_args_to_kwargs() +def _roll_evals(evals, *, axis=-1): """Check evals shape. Helper function to check that the evals provided to functions calculating @@ -1112,7 +1134,8 @@ def _roll_evals(evals, axis=-1): return evals -def _fa(evals, axis=-1): +@warn_on_args_to_kwargs() +def _fa(evals, *, axis=-1): r"""Return Fractional anisotropy (FA) of a diffusion tensor. Parameters @@ -1138,7 +1161,7 @@ def _fa(evals, axis=-1): \lambda_2^2+\lambda_3^2}} """ - evals = _roll_evals(evals, axis) + evals = _roll_evals(evals, axis=axis) # Make sure not to get nans all_zero = (evals == 0).all(axis=0) ev1, ev2, ev3 = evals @@ -1183,9 +1206,11 @@ def _color_fa(fa, evecs): return np.abs(evecs[..., 0]) * np.clip(fa, 0, 1)[..., None] +@warn_on_args_to_kwargs() def tensor_slicer( evals, evecs, + *, affine=None, mask=None, sphere=None, @@ -1261,7 +1286,8 @@ def display_extent(self, x1, x2, y1, y2, z1, z2): ) self.SetMapper(self.mapper) - def display(self, x=None, y=None, z=None): + @warn_on_args_to_kwargs() + def display(self, *, x=None, y=None, z=None): if x is None and y is None and z is None: self.display_extent( 0, @@ -1288,9 +1314,11 @@ def display(self, x=None, y=None, z=None): return tensor_actor +@warn_on_args_to_kwargs() def _tensor_slicer_mapper( evals, evecs, + *, affine=None, mask=None, sphere=None, @@ -1394,8 +1422,10 @@ def _tensor_slicer_mapper( return mapper +@warn_on_args_to_kwargs() def peak_slicer( peaks_dirs, + *, peaks_values=None, mask=None, affine=None, @@ -1515,7 +1545,8 @@ def display_extent(self, x1, x2, y1, y2, z1, z2): self.SetProperty(self.line.GetProperty()) self.SetMapper(self.line.GetMapper()) - def display(self, x=None, y=None, z=None): + @warn_on_args_to_kwargs() + def display(self, *, x=None, y=None, z=None): if x is None and y is None and z is None: self.display_extent( 0, @@ -1542,8 +1573,10 @@ def display(self, x=None, y=None, z=None): return peak_actor +@warn_on_args_to_kwargs() def peak( peaks_dirs, + *, peaks_values=None, mask=None, affine=None, @@ -1657,7 +1690,8 @@ def peak( ) -def dot(points, colors=None, opacity=None, dot_size=5): +@warn_on_args_to_kwargs() +def dot(points, *, colors=None, opacity=None, dot_size=5): """Create one or more 3d points. Parameters @@ -1739,7 +1773,8 @@ def dot(points, colors=None, opacity=None, dot_size=5): )(dot) -def point(points, colors, point_radius=0.1, phi=8, theta=8, opacity=1.0): +@warn_on_args_to_kwargs() +def point(points, colors, *, point_radius=0.1, phi=8, theta=8, opacity=1.0): """Visualize points as sphere glyphs. Parameters @@ -1783,9 +1818,11 @@ def point(points, colors, point_radius=0.1, phi=8, theta=8, opacity=1.0): ) +@warn_on_args_to_kwargs() def sphere( centers, colors, + *, radii=1.0, phi=16, theta=16, @@ -1874,10 +1911,12 @@ def sphere( return sphere_actor +@warn_on_args_to_kwargs() def cylinder( centers, directions, colors, + *, radius=0.05, heights=1, capped=False, @@ -1981,10 +2020,12 @@ def cylinder( return cylinder_actor +@warn_on_args_to_kwargs() def disk( centers, directions, colors, + *, rinner=0.3, router=0.7, cresolution=6, @@ -2058,7 +2099,8 @@ def disk( return disk_actor -def square(centers, directions=(1, 0, 0), colors=(1, 0, 0), scales=1): +@warn_on_args_to_kwargs() +def square(centers, *, directions=(1, 0, 0), colors=(1, 0, 0), scales=1): """Visualize one or many squares with different features. Parameters @@ -2082,7 +2124,7 @@ def square(centers, directions=(1, 0, 0), colors=(1, 0, 0), scales=1): >>> scene = window.Scene() >>> centers = np.random.rand(5, 3) >>> dirs = np.random.rand(5, 3) - >>> sq_actor = actor.square(centers, dirs) + >>> sq_actor = actor.square(centers, directions=dirs) >>> scene.add(sq_actor) >>> # window.show(scene) @@ -2106,7 +2148,8 @@ def square(centers, directions=(1, 0, 0), colors=(1, 0, 0), scales=1): return sq_actor -def rectangle(centers, directions=(1, 0, 0), colors=(1, 0, 0), scales=(1, 2, 0)): +@warn_on_args_to_kwargs() +def rectangle(centers, *, directions=(1, 0, 0), colors=(1, 0, 0), scales=(1, 2, 0)): """Visualize one or many rectangles with different features. Parameters @@ -2134,7 +2177,7 @@ def rectangle(centers, directions=(1, 0, 0), colors=(1, 0, 0), scales=(1, 2, 0)) >>> scene = window.Scene() >>> centers = np.random.rand(5, 3) >>> dirs = np.random.rand(5, 3) - >>> rect_actor = actor.rectangle(centers, dirs) + >>> rect_actor = actor.rectangle(centers, directions=dirs) >>> scene.add(rect_actor) >>> # window.show(scene) @@ -2142,8 +2185,9 @@ def rectangle(centers, directions=(1, 0, 0), colors=(1, 0, 0), scales=(1, 2, 0)) return square(centers=centers, directions=directions, colors=colors, scales=scales) +@warn_on_args_to_kwargs() @deprecated_params(["size", "heights"], ["scales", "scales"], since="0.6", until="0.8") -def box(centers, directions=(1, 0, 0), colors=(1, 0, 0), scales=(1, 2, 3)): +def box(centers, *, directions=(1, 0, 0), colors=(1, 0, 0), scales=(1, 2, 3)): """Visualize one or many boxes with different features. Parameters @@ -2167,7 +2211,7 @@ def box(centers, directions=(1, 0, 0), colors=(1, 0, 0), scales=(1, 2, 3)): >>> scene = window.Scene() >>> centers = np.random.rand(5, 3) >>> dirs = np.random.rand(5, 3) - >>> box_actor = actor.box(centers, dirs, (1, 1, 1)) + >>> box_actor = actor.box(centers, directions=dirs, colors=(1, 1, 1)) >>> scene.add(box_actor) >>> # window.show(scene) @@ -2190,8 +2234,9 @@ def box(centers, directions=(1, 0, 0), colors=(1, 0, 0), scales=(1, 2, 3)): return box_actor +@warn_on_args_to_kwargs() @deprecated_params("heights", "scales", since="0.6", until="0.8") -def cube(centers, directions=(1, 0, 0), colors=(1, 0, 0), scales=1): +def cube(centers, *, directions=(1, 0, 0), colors=(1, 0, 0), scales=1): """Visualize one or many cubes with different features. Parameters @@ -2215,7 +2260,7 @@ def cube(centers, directions=(1, 0, 0), colors=(1, 0, 0), scales=1): >>> scene = window.Scene() >>> centers = np.random.rand(5, 3) >>> dirs = np.random.rand(5, 3) - >>> cube_actor = actor.cube(centers, dirs) + >>> cube_actor = actor.cube(centers, directions=dirs) >>> scene.add(cube_actor) >>> # window.show(scene) @@ -2223,10 +2268,12 @@ def cube(centers, directions=(1, 0, 0), colors=(1, 0, 0), scales=1): return box(centers=centers, directions=directions, colors=colors, scales=scales) +@warn_on_args_to_kwargs() def arrow( centers, directions, colors, + *, heights=1.0, resolution=10, tip_length=0.35, @@ -2275,7 +2322,7 @@ def arrow( >>> centers = np.random.rand(5, 3) >>> directions = np.random.rand(5, 3) >>> heights = np.random.rand(5) - >>> arrow_actor = actor.arrow(centers, directions, (1, 1, 1), heights) + >>> arrow_actor = actor.arrow(centers, directions, (1, 1, 1), heights=heights) >>> scene.add(arrow_actor) >>> # window.show(scene) @@ -2318,10 +2365,12 @@ def arrow( return arrow_actor +@warn_on_args_to_kwargs() def cone( centers, directions, colors, + *, heights=1.0, resolution=10, vertices=None, @@ -2362,7 +2411,7 @@ def cone( >>> centers = np.random.rand(5, 3) >>> directions = np.random.rand(5, 3) >>> heights = np.random.rand(5) - >>> cone_actor = actor.cone(centers, directions, (1, 1, 1), heights) + >>> cone_actor = actor.cone(centers, directions, (1, 1, 1), heights=heights) >>> scene.add(cone_actor) >>> # window.show(scene) @@ -2400,7 +2449,8 @@ def cone( return cone_actor -def triangularprism(centers, directions=(1, 0, 0), colors=(1, 0, 0), scales=1): +@warn_on_args_to_kwargs() +def triangularprism(centers, *, directions=(1, 0, 0), colors=(1, 0, 0), scales=1): """Visualize one or many regular triangular prisms with different features. Parameters @@ -2426,11 +2476,11 @@ def triangularprism(centers, directions=(1, 0, 0), colors=(1, 0, 0), scales=1): >>> dirs = np.random.rand(3, 3) >>> colors = np.random.rand(3, 3) >>> scales = np.random.rand(3, 1) - >>> actor = actor.triangularprism(centers, dirs, colors, scales) + >>> actor = actor.triangularprism(centers, directions=dirs, colors=colors, scales=scales) >>> scene.add(actor) >>> # window.show(scene) - """ + """ # noqa: E501 verts, faces = fp.prim_triangularprism() res = fp.repeat_primitive( verts, @@ -2448,7 +2498,8 @@ def triangularprism(centers, directions=(1, 0, 0), colors=(1, 0, 0), scales=1): return tprism_actor -def rhombicuboctahedron(centers, directions=(1, 0, 0), colors=(1, 0, 0), scales=1): +@warn_on_args_to_kwargs() +def rhombicuboctahedron(centers, *, directions=(1, 0, 0), colors=(1, 0, 0), scales=1): """Visualize one or many rhombicuboctahedron with different features. Parameters @@ -2474,11 +2525,11 @@ def rhombicuboctahedron(centers, directions=(1, 0, 0), colors=(1, 0, 0), scales= >>> dirs = np.random.rand(3, 3) >>> colors = np.random.rand(3, 3) >>> scales = np.random.rand(3, 1) - >>> actor = actor.rhombicuboctahedron(centers, dirs, colors, scales) + >>> actor = actor.rhombicuboctahedron(centers, directions=dirs, colors=colors, scales=scales) >>> scene.add(actor) >>> # window.show(scene) - """ + """ # noqa: E501 verts, faces = fp.prim_rhombicuboctahedron() res = fp.repeat_primitive( verts, @@ -2496,7 +2547,8 @@ def rhombicuboctahedron(centers, directions=(1, 0, 0), colors=(1, 0, 0), scales= return rcoh_actor -def pentagonalprism(centers, directions=(1, 0, 0), colors=(1, 0, 0), scales=1): +@warn_on_args_to_kwargs() +def pentagonalprism(centers, *, directions=(1, 0, 0), colors=(1, 0, 0), scales=1): """Visualize one or many pentagonal prisms with different features. Parameters @@ -2523,11 +2575,11 @@ def pentagonalprism(centers, directions=(1, 0, 0), colors=(1, 0, 0), scales=1): >>> dirs = np.random.rand(3, 3) >>> colors = np.random.rand(3, 3) >>> scales = np.random.rand(3, 1) - >>> actor_pentagonal = actor.pentagonalprism(centers, dirs, colors, scales) + >>> actor_pentagonal = actor.pentagonalprism(centers, directions=dirs, colors=colors, scales=scales) >>> scene.add(actor_pentagonal) >>> # window.show(scene) - """ + """ # noqa: E501 verts, faces = fp.prim_pentagonalprism() res = fp.repeat_primitive( verts, @@ -2546,7 +2598,8 @@ def pentagonalprism(centers, directions=(1, 0, 0), colors=(1, 0, 0), scales=1): return pent_actor -def octagonalprism(centers, directions=(1, 0, 0), colors=(1, 0, 0), scales=1): +@warn_on_args_to_kwargs() +def octagonalprism(centers, *, directions=(1, 0, 0), colors=(1, 0, 0), scales=1): """Visualize one or many octagonal prisms with different features. Parameters @@ -2572,11 +2625,11 @@ def octagonalprism(centers, directions=(1, 0, 0), colors=(1, 0, 0), scales=1): >>> dirs = np.random.rand(3, 3) >>> colors = np.random.rand(3, 3) >>> scales = np.random.rand(3, 1) - >>> actor = actor.octagonalprism(centers, dirs, colors, scales) + >>> actor = actor.octagonalprism(centers, directions=dirs, colors=colors, scales=scales) >>> scene.add(actor) >>> # window.show(scene) - """ + """ # noqa: E501 verts, faces = fp.prim_octagonalprism() res = fp.repeat_primitive( verts, @@ -2595,7 +2648,8 @@ def octagonalprism(centers, directions=(1, 0, 0), colors=(1, 0, 0), scales=1): return oct_actor -def frustum(centers, directions=(1, 0, 0), colors=(0, 1, 0), scales=1): +@warn_on_args_to_kwargs() +def frustum(centers, *, directions=(1, 0, 0), colors=(0, 1, 0), scales=1): """Visualize one or many frustum pyramids with different features. Parameters @@ -2621,7 +2675,7 @@ def frustum(centers, directions=(1, 0, 0), colors=(0, 1, 0), scales=1): >>> dirs = np.random.rand(4, 3) >>> colors = np.random.rand(4, 3) >>> scales = np.random.rand(4, 1) - >>> actor = actor.frustum(centers, dirs, colors, scales) + >>> actor = actor.frustum(centers, directions=dirs, colors=colors, scales=scales) >>> scene.add(actor) >>> # window.show(scene) @@ -2644,8 +2698,9 @@ def frustum(centers, directions=(1, 0, 0), colors=(0, 1, 0), scales=1): return frustum_actor +@warn_on_args_to_kwargs() def superquadric( - centers, roundness=(1, 1), directions=(1, 0, 0), colors=(1, 0, 0), scales=1 + centers, *, roundness=(1, 1), directions=(1, 0, 0), colors=(1, 0, 0), scales=1 ): """Visualize one or many superquadrics with different features. @@ -2715,8 +2770,10 @@ def have_2_dimensions(arr): return spq_actor +@warn_on_args_to_kwargs() def billboard( centers, + *, colors=(0, 1, 0), scales=1, vs_dec=None, @@ -2864,7 +2921,9 @@ def billboard( return bb_actor +@warn_on_args_to_kwargs() def vector_text( + *, text="Origin", pos=(0, 0, 0), scale=(0.2, 0.2, 0.2), @@ -2970,8 +3029,10 @@ def add_to_scene(scene): )(vector_text) +@warn_on_args_to_kwargs() def text_3d( text, + *, position=(0, 0, 0), color=(1, 1, 1), font_size=12, @@ -3019,7 +3080,8 @@ def font_size(self, size): self.GetTextProperty().SetFontSize(24) text_actor.SetScale((1.0 / 24.0 * size,) * 3) - def font_family(self, _family="Arial"): + @warn_on_args_to_kwargs() + def font_family(self, *, _family="Arial"): self.GetTextProperty().SetFontFamilyToArial() def justification(self, justification): @@ -3046,7 +3108,8 @@ def vertical_justification(self, justification): "Unknown vertical justification: '{}'".format(justification) ) - def font_style(self, bold=False, italic=False, shadow=False): + @warn_on_args_to_kwargs() + def font_style(self, *, bold=False, italic=False, shadow=False): tprop = self.GetTextProperty() if bold: tprop.BoldOn() @@ -3074,8 +3137,8 @@ def get_position(self): text_actor.message(text) text_actor.font_size(font_size) text_actor.set_position(position) - text_actor.font_family(font_family) - text_actor.font_style(bold, italic, shadow) + text_actor.font_family(_family=font_family) + text_actor.font_style(bold=bold, italic=italic, shadow=shadow) text_actor.color(color) text_actor.justification(justification) text_actor.vertical_justification(vertical_justification) @@ -3101,7 +3164,8 @@ class Container: """ - def __init__(self, layout=None): + @warn_on_args_to_kwargs() + def __init__(self, *, layout=None): """Parameters ---------- layout : ``fury.layout.Layout`` object @@ -3234,8 +3298,10 @@ def __len__(self): return len(self._items) +@warn_on_args_to_kwargs() def grid( actors, + *, captions=None, caption_offset=(0, -100, 0), cell_padding=0, @@ -3316,7 +3382,8 @@ def grid( return grid -def figure(pic, interpolation="nearest"): +@warn_on_args_to_kwargs() +def figure(pic, *, interpolation="nearest"): """Return a figure as an image actor. Parameters @@ -3362,7 +3429,8 @@ def figure(pic, interpolation="nearest"): return image_actor -def texture(rgb, interp=True): +@warn_on_args_to_kwargs() +def texture(rgb, *, interp=True): """Map an RGB or RGBA texture on a plane. Parameters @@ -3441,7 +3509,8 @@ def texture_update(texture_actor, arr): grid.GetPointData().SetScalars(vtkarr) -def _textured_sphere_source(theta=60, phi=60): +@warn_on_args_to_kwargs() +def _textured_sphere_source(*, theta=60, phi=60): """Use vtkTexturedSphereSource to set the theta and phi. Parameters @@ -3463,7 +3532,8 @@ def _textured_sphere_source(theta=60, phi=60): return tss -def texture_on_sphere(rgb, theta=60, phi=60, interpolate=True): +@warn_on_args_to_kwargs() +def texture_on_sphere(rgb, *, theta=60, phi=60, interpolate=True): """Map an RGB or RGBA texture on a sphere. Parameters @@ -3499,7 +3569,8 @@ def texture_on_sphere(rgb, theta=60, phi=60, interpolate=True): return earthActor -def texture_2d(rgb, interp=False): +@warn_on_args_to_kwargs() +def texture_2d(rgb, *, interp=False): """Create 2D texture from array. Parameters @@ -3565,7 +3636,10 @@ def texture_2d(rgb, interp=False): return act -def sdf(centers, directions=(1, 0, 0), colors=(1, 0, 0), primitives="torus", scales=1): +@warn_on_args_to_kwargs() +def sdf( + centers, *, directions=(1, 0, 0), colors=(1, 0, 0), primitives="torus", scales=1 +): """Create a SDF primitive based actor. Parameters @@ -3646,8 +3720,10 @@ def sdf(centers, directions=(1, 0, 0), colors=(1, 0, 0), primitives="torus", sca return box_actor +@warn_on_args_to_kwargs() def markers( centers, + *, colors=(0, 1, 0), scales=1, marker="3d", @@ -3785,7 +3861,12 @@ def markers( attribute_to_actor(sq_actor, list_of_markers, "marker") def callback( - _caller, _event, calldata=None, uniform_type="f", uniform_name=None, value=None + _caller, + _event, + calldata=None, + uniform_type="f", + uniform_name=None, + value=None, ): program = calldata if program is not None: @@ -3824,7 +3905,16 @@ def callback( return sq_actor -def ellipsoid(centers, axes, lengths, colors=(1, 0, 0), scales=1.0, opacity=1.0): +@warn_on_args_to_kwargs() +def ellipsoid( + centers, + axes, + lengths, + *, + colors=(1, 0, 0), + scales=1.0, + opacity=1.0, +): """VTK actor for visualizing ellipsoids. Parameters @@ -3889,7 +3979,17 @@ def ellipsoid(centers, axes, lengths, colors=(1, 0, 0), scales=1.0, opacity=1.0) return tensor_ellipsoid(centers, axes, lengths, colors, scales, opacity) -def uncertainty_cone(evals, evecs, signal, sigma, b_matrix, scales=0.6, opacity=1.0): +@warn_on_args_to_kwargs() +def uncertainty_cone( + evals, + evecs, + signal, + sigma, + b_matrix, + *, + scales=0.6, + opacity=1.0, +): """VTK actor for visualizing the cone of uncertainty representing the variance of the main direction of diffusion. diff --git a/fury/decorators.py b/fury/decorators.py index 8acfe2d2f..cf538c98d 100644 --- a/fury/decorators.py +++ b/fury/decorators.py @@ -50,7 +50,7 @@ def doctest_skip_parser(func): return func -def warn_on_args_to_kwargs(from_version=None, until_version=None): +def warn_on_args_to_kwargs(from_version="0.1.O", until_version="0.11.0"): """Decorator to enforce keyword-only arguments. This decorator enforces that all arguments after the first one are @@ -143,7 +143,7 @@ def wrapper(*args, **kwargs): params_len = len(params) try: return func(*args, **kwargs) - except TypeError: + except TypeError as e: # if the version of fury is greater than until_version, an error should # be displayed to indicate that this way of calling the function func # was supported by from_version until_version but not by the current @@ -152,13 +152,7 @@ def wrapper(*args, **kwargs): from fury import __version__ as FURY_VERSION if version.parse(FURY_VERSION) > version.parse(until_version): - raise RuntimeError( - f"Calling the {func.__name__} function in this way " - f"was supported from {from_version} up to {until_version}, " - f"but not in the current version of FURY {FURY_VERSION}. " - f"Here's how you must call the Function {func.__name__}: " - f"{func.__name__}({func_params_sample})" - ) from None + raise TypeError(e) from e if ARG_DEFAULT: missing_kwargs += ARG_DEFAULT diff --git a/fury/shaders/tests/test_base.py b/fury/shaders/tests/test_base.py index 7fc7f3438..14c518c59 100644 --- a/fury/shaders/tests/test_base.py +++ b/fury/shaders/tests/test_base.py @@ -191,7 +191,7 @@ def test_add_shader_callback(): scene = window.Scene() scene.add(cube) - showm = window.ShowManager(scene) + showm = window.ShowManager(scene=scene) class Timer: idx = 0.0 diff --git a/fury/tests/test_actors.py b/fury/tests/test_actors.py index 55af97f39..b76fec299 100644 --- a/fury/tests/test_actors.py +++ b/fury/tests/test_actors.py @@ -48,8 +48,8 @@ def test_slicer(verbose=False): scene = window.Scene() data = 255 * np.random.rand(50, 50, 50) affine = np.eye(4) - slicer = actor.slicer(data, affine, value_range=[data.min(), data.max()]) - slicer.display(None, None, 25) + slicer = actor.slicer(data, affine=affine, value_range=[data.min(), data.max()]) + slicer.display(x=None, y=None, z=25) scene.add(slicer) scene.reset_camera() @@ -57,7 +57,7 @@ def test_slicer(verbose=False): # window.show(scene) # copy pixels in numpy array directly - arr = window.snapshot(scene, "test_slicer.png", offscreen=True) + arr = window.snapshot(scene, fname="test_slicer.png", offscreen=True) if verbose: print(arr.sum()) @@ -80,14 +80,22 @@ def test_slicer(verbose=False): # save pixels in png file not a numpy array with InTemporaryDirectory() as tmpdir: fname = os.path.join(tmpdir, "slice.png") - window.snapshot(scene, fname, offscreen=True) + window.snapshot(scene, fname=fname, offscreen=True) report = window.analyze_snapshot(fname, find_objects=True) npt.assert_equal(report.objects, 1) # Test Errors data_4d = 255 * np.random.rand(50, 50, 50, 50) - npt.assert_raises(ValueError, actor.slicer, data_4d) - npt.assert_raises(ValueError, actor.slicer, np.ones(10)) + npt.assert_raises( + ValueError, + actor.slicer, + data_4d, + ) + npt.assert_raises( + ValueError, + actor.slicer, + np.ones(10), + ) scene.clear() @@ -114,9 +122,9 @@ def test_slicer(verbose=False): scene.clear() slicer_lut = actor.slicer(data, lookup_colormap=lut) - slicer_lut.display(10, None, None) - slicer_lut.display(None, 10, None) - slicer_lut.display(None, None, 10) + slicer_lut.display(x=10, y=None, z=None) + slicer_lut.display(x=None, y=10, z=None) + slicer_lut.display(x=None, y=None, z=10) slicer_lut.opacity(0.5) slicer_lut.tolerance(0.03) @@ -125,7 +133,7 @@ def test_slicer(verbose=False): npt.assert_equal(slicer_lut2.picker.GetTolerance(), 0.03) slicer_lut2.opacity(1) slicer_lut2.tolerance(0.025) - slicer_lut2.display(None, None, 10) + slicer_lut2.display(x=None, y=None, z=10) scene.add(slicer_lut2) scene.reset_clipping_range() @@ -138,8 +146,8 @@ def test_slicer(verbose=False): data = 255 * np.random.rand(50, 50, 50) affine = np.diag([1, 3, 2, 1]) - slicer = actor.slicer(data, affine, interpolation="nearest") - slicer.display(None, None, 25) + slicer = actor.slicer(data, affine=affine, interpolation="nearest") + slicer.display(x=None, y=None, z=25) scene.add(slicer) scene.reset_camera() @@ -187,7 +195,7 @@ def test_surface(): ) scene.add(surface_actor) # window.show(scene, size=(600, 600), reset_camera=False) - arr = window.snapshot(scene, "test_surface.png", offscreen=True) + arr = window.snapshot(scene, fname="test_surface.png", offscreen=True) report = window.analyze_snapshot(arr, find_objects=True) npt.assert_equal(report.objects, 1) @@ -200,7 +208,7 @@ def test_contour_from_roi(interactive=False): data[25, 20:30, 25] = 1.0 affine = np.eye(4) surface = actor.contour_from_roi( - data, affine, color=np.array([1, 0, 1]), opacity=0.5 + data, affine=affine, color=np.array([1, 0, 1]), opacity=0.5 ) scene.add(surface) @@ -219,7 +227,7 @@ def test_contour_from_roi(interactive=False): data2[35:40, 25, 25] = 1.0 affine = np.eye(4) surface2 = actor.contour_from_roi( - data2, affine, color=np.array([0, 1, 1]), opacity=0.5 + data2, affine=affine, color=np.array([0, 1, 1]), opacity=0.5 ) scene2.add(surface2) @@ -228,8 +236,8 @@ def test_contour_from_roi(interactive=False): if interactive: window.show(scene2) - arr = window.snapshot(scene, "test_surface.png", offscreen=True) - arr2 = window.snapshot(scene2, "test_surface2.png", offscreen=True) + arr = window.snapshot(scene, fname="test_surface.png", offscreen=True) + arr2 = window.snapshot(scene2, fname="test_surface2.png", offscreen=True) report = window.analyze_snapshot(arr, find_objects=True) report2 = window.analyze_snapshot(arr2, find_objects=True) @@ -287,10 +295,10 @@ def test_contour_from_label(interactive=False): window.show(scene2) arr = window.snapshot( - scene, "test_surface.png", offscreen=True, order_transparent=False + scene, fname="test_surface.png", offscreen=True, order_transparent=False ) arr2 = window.snapshot( - scene2, "test_surface2.png", offscreen=True, order_transparent=True + scene2, fname="test_surface2.png", offscreen=True, order_transparent=True ) report = window.analyze_snapshot( @@ -312,14 +320,14 @@ def test_streamtube_and_line_actors(): lines = [line1, line2] colors = np.array([[1, 0, 0], [0, 0, 1.0]]) - c = actor.line(lines, colors, linewidth=3) + c = actor.line(lines, colors=colors, linewidth=3) scene.add(c) - c = actor.line(lines, colors, spline_subdiv=5, linewidth=3) + c = actor.line(lines, colors=colors, spline_subdiv=5, linewidth=3) scene.add(c) # create streamtubes of the same lines and shift them a bit - c2 = actor.streamtube(lines, colors, linewidth=0.1) + c2 = actor.streamtube(lines, colors=colors, linewidth=0.1) c2.SetPosition(2, 0, 0) scene.add(c2) @@ -333,7 +341,7 @@ def test_streamtube_and_line_actors(): npt.assert_equal(report.colors_found, [True, True]) # as before with splines - c2 = actor.streamtube(lines, colors, spline_subdiv=5, linewidth=0.1) + c2 = actor.streamtube(lines, colors=colors, spline_subdiv=5, linewidth=0.1) c2.SetPosition(2, 0, 0) scene.add(c2) @@ -346,7 +354,7 @@ def test_streamtube_and_line_actors(): npt.assert_equal(report.objects, 4) npt.assert_equal(report.colors_found, [True, True]) - c3 = actor.line(lines, colors, depth_cue=True, fake_tube=True) + c3 = actor.line(lines, colors=colors, depth_cue=True, fake_tube=True) shader_obj = c3.GetShaderProperty() mapper_code = shader_obj.GetGeometryShaderCode() @@ -355,9 +363,9 @@ def test_streamtube_and_line_actors(): npt.assert_equal(c3.GetProperty().GetRenderLinesAsTubes(), True) - c4 = actor.streamtube(lines, colors, replace_strips=False) + c4 = actor.streamtube(lines, colors=colors, replace_strips=False) - c5 = actor.streamtube(lines, colors, replace_strips=True) + c5 = actor.streamtube(lines, colors=colors, replace_strips=True) strips4 = c4.GetMapper().GetInput().GetStrips().GetData().GetSize() strips5 = c5.GetMapper().GetInput().GetStrips().GetData().GetSize() @@ -398,9 +406,9 @@ def test_bundle_maps(): value_range=(1.0, 1), ) - line = actor.line(bundle, metric, linewidth=0.1, lookup_colormap=lut) + line = actor.line(bundle, colors=metric, linewidth=0.1, lookup_colormap=lut) scene.add(line) - scene.add(actor.scalar_bar(lut, " ")) + scene.add(actor.scalar_bar(lookup_table=lut, title=" ")) report = window.analyze_scene(scene) @@ -413,7 +421,7 @@ def test_bundle_maps(): values = 100 * np.random.rand(nb_points) # values[:nb_points/2] = 0 - line = actor.streamtube(bundle, values, linewidth=0.1, lookup_colormap=lut) + line = actor.streamtube(bundle, colors=values, linewidth=0.1, lookup_colormap=lut) scene.add(line) # window.show(scene) @@ -425,7 +433,7 @@ def test_bundle_maps(): colors = np.random.rand(nb_points, 3) # values[:nb_points/2] = 0 - line = actor.line(bundle, colors, linewidth=2) + line = actor.line(bundle, colors=colors, linewidth=2) scene.add(line) # window.show(scene) @@ -439,8 +447,8 @@ def test_bundle_maps(): # try other input options for colors scene.clear() - actor.line(bundle, (1.0, 0.5, 0)) - actor.line(bundle, np.arange(len(bundle))) + actor.line(bundle, colors=(1.0, 0.5, 0)) + actor.line(bundle, colors=np.arange(len(bundle))) actor.line(bundle) colors = [np.random.rand(*b.shape) for b in bundle] actor.line(bundle, colors=colors) @@ -521,13 +529,13 @@ def test_odf_slicer(interactive=False): # Test that odf_slicer.display works properly scene.clear() scene.add(odf_actor) - scene.add(actor.axes((11, 11, 11))) + scene.add(actor.axes(scale=(11, 11, 11))) for i in range(11): - odf_actor.display(i, None, None) + odf_actor.display(x=i, y=None, z=None) if interactive: window.show(scene) for j in range(11): - odf_actor.display(None, j, None) + odf_actor.display(x=None, y=j, z=None) if interactive: window.show(scene) @@ -607,13 +615,13 @@ def test_peak_slicer(interactive=False): scene = window.Scene() peak_actor = actor.peak_slicer(peak_dirs) scene.add(peak_actor) - scene.add(actor.axes((11, 11, 11))) + scene.add(actor.axes(scale=(11, 11, 11))) if interactive: window.show(scene) scene.clear() scene.add(peak_actor) - scene.add(actor.axes((11, 11, 11))) + scene.add(actor.axes(scale=(11, 11, 11))) for k in range(11): peak_actor.display_extent(0, 10, 0, 10, k, k) @@ -621,13 +629,13 @@ def test_peak_slicer(interactive=False): peak_actor.display_extent(0, 10, j, j, 0, 10) for i in range(11): - peak_actor.display(i, None, None) + peak_actor.display(x=i, y=None, z=None) scene.rm_all() peak_actor_sym = actor.peak_slicer( peak_dirs, - peak_values, + peaks_values=peak_values, mask=None, affine=np.diag([3, 2, 1, 1]), colors=None, @@ -640,7 +648,7 @@ def test_peak_slicer(interactive=False): peak_actor_asym = actor.peak_slicer( peak_dirs, - peak_values, + peaks_values=peak_values, mask=None, affine=np.diag([3, 2, 1, 1]), colors=None, @@ -654,7 +662,7 @@ def test_peak_slicer(interactive=False): scene.add(peak_actor_sym) scene.add(peak_actor_asym) - scene.add(actor.axes((11, 11, 11))) + scene.add(actor.axes(scale=(11, 11, 11))) if interactive: window.show(scene) @@ -892,7 +900,7 @@ def test_points(interactive=False): def test_vector_text(interactive=False): npt.assert_raises(ExpiredDeprecationError, actor.label, "FURY Rocks") - text_actor = actor.vector_text("FURY Rocks", direction=None) + text_actor = actor.vector_text(text="FURY Rocks", direction=None) scene = window.Scene() scene.add(text_actor) @@ -904,35 +912,35 @@ def test_vector_text(interactive=False): if interactive: window.show(scene, reset_camera=False) - text_actor = actor.vector_text("FURY Rocks") + text_actor = actor.vector_text(text="FURY Rocks") npt.assert_equal(scene.GetActors().GetNumberOfItems(), 1) center = np.array(text_actor.GetCenter()) [assert_greater_equal(v, 0) for v in center] - text_actor_centered = actor.vector_text("FURY Rocks", align_center=True) + text_actor_centered = actor.vector_text(text="FURY Rocks", align_center=True) center = np.array(text_actor_centered.GetCenter()) npt.assert_equal(center, np.zeros(3)) - text_actor_rot_1 = actor.vector_text("FURY Rocks", direction=(1, 1, 1)) - text_actor_rot_2 = actor.vector_text("FURY Rocks", direction=(1, 1, 0)) + text_actor_rot_1 = actor.vector_text(text="FURY Rocks", direction=(1, 1, 1)) + text_actor_rot_2 = actor.vector_text(text="FURY Rocks", direction=(1, 1, 0)) center_1 = text_actor_rot_1.GetCenter() center_2 = text_actor_rot_2.GetCenter() assert_not_equal(np.linalg.norm(center_1), np.linalg.norm(center_2)) # test centered - text_centered = actor.vector_text("FURY Rocks", align_center=True) + text_centered = actor.vector_text(text="FURY Rocks", align_center=True) center_3 = text_centered.GetCenter() npt.assert_almost_equal(np.linalg.norm(center_3), 0.0) text_extruded = actor.vector_text( - "FURY Rocks", scale=(0.2, 0.2, 0.2), extrusion=1.123 + text="FURY Rocks", scale=(0.2, 0.2, 0.2), extrusion=1.123 ) z_max = text_extruded.GetBounds()[-1] npt.assert_almost_equal(z_max, 1.123) text_extruded_centered = actor.vector_text( - "FURY Rocks", + text="FURY Rocks", scale=(0.2, 0.2, 0.2), direction=None, align_center=True, @@ -1253,16 +1261,31 @@ def test_container(): def test_grid(_interactive=False): vol1 = np.zeros((100, 100, 100)) vol1[25:75, 25:75, 25:75] = 100 - contour_actor1 = actor.contour_from_roi(vol1, np.eye(4), (1.0, 0, 0), 1.0) + contour_actor1 = actor.contour_from_roi( + vol1, + affine=np.eye(4), + color=(1.0, 0, 0), + opacity=1.0, + ) vol2 = np.zeros((100, 100, 100)) vol2[25:75, 25:75, 25:75] = 100 - contour_actor2 = actor.contour_from_roi(vol2, np.eye(4), (1.0, 0.5, 0), 1.0) + contour_actor2 = actor.contour_from_roi( + vol2, + affine=np.eye(4), + color=(1.0, 0.5, 0), + opacity=1.0, + ) vol3 = np.zeros((100, 100, 100)) vol3[25:75, 25:75, 25:75] = 100 - contour_actor3 = actor.contour_from_roi(vol3, np.eye(4), (1.0, 0.5, 0.5), 1.0) + contour_actor3 = actor.contour_from_roi( + vol3, + affine=np.eye(4), + color=(1.0, 0.5, 0.5), + opacity=1.0, + ) scene = window.Scene() actors = [] @@ -1303,11 +1326,11 @@ def test_grid(_interactive=False): scene.add(container) - scene.projection("orthogonal") + scene.projection(proj_type="orthogonal") counter = itertools.count() - show_m = window.ShowManager(scene) + show_m = window.ShowManager(scene=scene) def timer_callback(_obj, _event): nonlocal counter @@ -1329,7 +1352,7 @@ def timer_callback(_obj, _event): scene.rm_all() counter = itertools.count() - show_m = window.ShowManager(scene) + show_m = window.ShowManager(scene=scene) # show the grid with the captions container = grid( @@ -1461,8 +1484,8 @@ def test_matplotlib_figure(): arr = matplotlib_figure_to_numpy(fig, dpi=500, transparent=True) plt.close("all") - fig_actor = actor.figure(arr, "cubic") - fig_actor2 = actor.figure(arr, "cubic") + fig_actor = actor.figure(arr, interpolation="cubic") + fig_actor2 = actor.figure(arr, interpolation="cubic") scene = window.Scene() scene.background((1, 1, 1.0)) @@ -1473,7 +1496,7 @@ def test_matplotlib_figure(): ax_actor.SetPosition(-50, 500, -800) fig_actor2.SetPosition(500, 800, -400) display = window.snapshot( - scene, "test_mpl.png", order_transparent=False, offscreen=True + scene, fname="test_mpl.png", order_transparent=False, offscreen=True ) _ = window.analyze_snapshot( display, bg_color=(255, 255, 255.0), colors=[(31, 119, 180)], find_objects=False @@ -1643,7 +1666,13 @@ def test_sdf_actor(interactive=False): scales = [1, 2, 3, 4] primitive = ["sphere", "ellipsoid", "torus", "capsule"] - sdf_actor = actor.sdf(centers, directions, colors, primitive, scales) + sdf_actor = actor.sdf( + centers, + directions=directions, + colors=colors, + primitives=primitive, + scales=scales, + ) scene.add(sdf_actor) scene.add(actor.axes()) if interactive: @@ -1656,7 +1685,13 @@ def test_sdf_actor(interactive=False): # Draw 3 spheres as the primitive type is str scene.clear() primitive = "sphere" - sdf_actor = actor.sdf(centers, directions, colors, primitive, scales) + sdf_actor = actor.sdf( + centers, + directions=directions, + colors=colors, + primitives=primitive, + scales=scales, + ) scene.add(sdf_actor) scene.add(actor.axes()) if interactive: @@ -1671,7 +1706,13 @@ def test_sdf_actor(interactive=False): scene.clear() primitive = ["sphere"] with npt.assert_warns(UserWarning): - sdf_actor = actor.sdf(centers, directions, colors, primitive, scales) + sdf_actor = actor.sdf( + centers, + directions=directions, + colors=colors, + primitives=primitive, + scales=scales, + ) scene.add(sdf_actor) scene.add(actor.axes()) @@ -1687,7 +1728,13 @@ def test_sdf_actor(interactive=False): scene.clear() primitive = ["sphere", "ellipsoid"] with npt.assert_warns(UserWarning): - sdf_actor = actor.sdf(centers, directions, colors, primitive, scales) + sdf_actor = actor.sdf( + centers, + directions=directions, + colors=colors, + primitives=primitive, + scales=scales, + ) scene.add(sdf_actor) scene.add(actor.axes()) diff --git a/fury/tests/test_decorators.py b/fury/tests/test_decorators.py index 614591519..bce864373 100644 --- a/fury/tests/test_decorators.py +++ b/fury/tests/test_decorators.py @@ -75,20 +75,3 @@ def func(a, b, *, c, d=4, e=5): npt.assert_raises(TypeError, func, 1, 2, e=10) npt.assert_raises(TypeError, func, 1, 2, d=10) npt.assert_raises(TypeError, func, 1, 3) - npt.assert_raises(TypeError, func, 1) - - -# def test_warn_on_args_to_kwargs_with_versions(): -# @warn_on_args_to_kwargs() -# def func(a, b, *, c, d=4, e=5): -# return a + b + c + d + e - -# npt.assert_equal(func(1, 2, c=3, d=4, e=5), 15) -# npt.assert_equal(func(1, 2, c=3, d=5), 16) -# npt.assert_equal(func(1, 2, c=3), 15) -# with npt.assert_warns(UserWarning): -# npt.assert_equal(func(1, 2, 3, 4, 5), 15) -# with npt.assert_warns(UserWarning): -# npt.assert_equal(func(1, 2, 3, 6), 17) -# with npt.assert_warns(UserWarning): -# npt.assert_equal(func(1, 2, 10), 22) diff --git a/fury/tests/test_gltf.py b/fury/tests/test_gltf.py index 5475c9df1..14e22ad9c 100644 --- a/fury/tests/test_gltf.py +++ b/fury/tests/test_gltf.py @@ -192,7 +192,7 @@ def test_simple_animation(): animation = gltf_obj.main_animation() timeline.add_animation(animation) scene = window.Scene() - showm = window.ShowManager(scene, size=(900, 768)) + showm = window.ShowManager(scene=scene, size=(900, 768)) showm.initialize() scene.add(timeline) @@ -259,7 +259,7 @@ def test_skinning(): npt.assert_equal(len(ibms), 2) scene = window.Scene() - showm = window.ShowManager(scene, size=(900, 768)) + showm = window.ShowManager(scene=scene, size=(900, 768)) showm.initialize() scene.add(timeline) @@ -333,7 +333,7 @@ def test_morphing(): gltf_obj.update_morph(anim_1) scene = window.Scene() - showm = window.ShowManager(scene, size=(900, 768)) + showm = window.ShowManager(scene=scene, size=(900, 768)) showm.initialize() timeline_1 = Timeline() diff --git a/fury/tests/test_interactor.py b/fury/tests/test_interactor.py index 33c6132ce..5608bde62 100644 --- a/fury/tests/test_interactor.py +++ b/fury/tests/test_interactor.py @@ -24,7 +24,10 @@ def test_custom_interactor_style_events(recording=False): # in steps so that the widgets can be added properly interactor_style = interactor.CustomInteractorStyle() show_manager = window.ShowManager( - scene, size=(800, 800), reset_camera=False, interactor_style=interactor_style + scene=scene, + size=(800, 800), + reset_camera=False, + interactor_style=interactor_style, ) # Create a cursor, a circle that will follow the mouse. @@ -56,8 +59,8 @@ def follow_mouse(iren, obj): np.array([[-1, 1, 0.0], [1, 1, 0.0]]), ] colors = np.array([[1.0, 0.0, 0.0], [0.3, 0.7, 0.0]]) - tube1 = actor.streamtube([lines[0]], colors[0]) - tube2 = actor.streamtube([lines[1]], colors[1]) + tube1 = actor.streamtube([lines[0]], colors=colors[0]) + tube2 = actor.streamtube([lines[1]], colors=colors[1]) scene.add(tube1) scene.add(tube2) @@ -157,8 +160,8 @@ def test_double_click_events(recording=False): cube = actor.cube( np.array([(0, 0, 0)]), - np.array([(0.16526678, 0.0186237, 0.01906076)]), - (1, 1, 1), + directions=np.array([(0.16526678, 0.0186237, 0.01906076)]), + colors=(1, 1, 1), scales=3, ) diff --git a/fury/tests/test_layout.py b/fury/tests/test_layout.py index d3b55150c..48f3b0ce3 100644 --- a/fury/tests/test_layout.py +++ b/fury/tests/test_layout.py @@ -46,11 +46,17 @@ def get_default_cubes( cube_first_scale, cube_second_scale = scales cube_first = actor.cube( - cube_first_center, cube_first_direction, cube_first_color, cube_first_scale + cube_first_center, + directions=cube_first_direction, + colors=cube_first_color, + scales=cube_first_scale, ) cube_second = actor.cube( - cube_second_center, cube_second_direction, cube_second_color, cube_second_scale + cube_second_center, + directions=cube_second_direction, + colors=cube_second_color, + scales=cube_second_scale, ) return (cube_first, cube_second) diff --git a/fury/tests/test_molecular.py b/fury/tests/test_molecular.py index 202e1cd83..2a1aa5099 100644 --- a/fury/tests/test_molecular.py +++ b/fury/tests/test_molecular.py @@ -396,7 +396,11 @@ def test_ribbon(interactive=False): is_hetatm=is_hetatm, ) test_actor = mol.ribbon(molecule) - scene.set_camera((28, 113, 74), (34, 106, 70), (-0.37, 0.29, -0.88)) + scene.set_camera( + position=(28, 113, 74), + focal_point=(34, 106, 70), + view_up=(-0.37, 0.29, -0.88), + ) scene.add(test_actor) scene.reset_camera() scene.reset_clipping_range() diff --git a/fury/tests/test_stream.py b/fury/tests/test_stream.py index 5db6a05da..af2cf31b0 100644 --- a/fury/tests/test_stream.py +++ b/fury/tests/test_stream.py @@ -56,7 +56,7 @@ def test(use_raw_array, ms_stream=16): scene = window.Scene() scene.add(actors) showm = window.ShowManager( - scene, + scene=scene, reset_camera=False, size=(width_0, height_0), order_transparent=False, @@ -108,7 +108,7 @@ def test_pillow(): scene = window.Scene() scene.add(actors) showm = window.ShowManager( - scene, + scene=scene, reset_camera=False, size=(width_0, height_0), order_transparent=False, @@ -165,7 +165,7 @@ def test_rtc_video_stream_whitout_cython(loop: asyncio.AbstractEventLoop): scene = window.Scene() scene.add(actors) showm = window.ShowManager( - scene, + scene=scene, reset_camera=False, size=(width_0, height_0), order_transparent=False, @@ -212,7 +212,7 @@ def test(use_raw_array, ms_stream=16): scene = window.Scene() scene.add(actors) showm = window.ShowManager( - scene, + scene=scene, reset_camera=False, size=(width_0, height_0), order_transparent=False, @@ -275,7 +275,7 @@ def test(use_raw_array, ms_stream=16, whithout_iren_start=False): scene = window.Scene() scene.add(actors) showm = window.ShowManager( - scene, + scene=scene, reset_camera=False, size=(width_0, height_0), order_transparent=False, @@ -314,7 +314,7 @@ def test_stream_client_resize(): scene = window.Scene() scene.add(actors) showm = window.ShowManager( - scene, + scene=scene, reset_camera=False, size=(width_0, height_0), order_transparent=False, @@ -360,7 +360,7 @@ async def test(use_raw_array, ms_stream=16): scene = window.Scene() scene.add(actors) showm = window.ShowManager( - scene, + scene=scene, reset_camera=False, size=(width_0, height_0), order_transparent=False, @@ -448,7 +448,7 @@ def test(use_raw_array, ms_stream, whitouth_iren_start): scene = window.Scene() scene.add(actors) - showm = window.ShowManager(scene, size=(width_0, height_0)) + showm = window.ShowManager(scene=scene, size=(width_0, height_0)) stream = FuryStreamClient( showm, use_raw_array=use_raw_array, whithout_iren_start=whitouth_iren_start @@ -734,7 +734,7 @@ def test(use_raw_array): scene = window.Scene() scene.add(actors) showm = window.ShowManager( - scene, + scene=scene, reset_camera=False, size=(width_0, height_0), order_transparent=False, @@ -790,7 +790,7 @@ def test_widget(): scene = window.Scene() scene.add(actors) showm = window.ShowManager( - scene, + scene=scene, reset_camera=False, size=(width_0, height_0), order_transparent=False, diff --git a/fury/tests/test_testing.py b/fury/tests/test_testing.py index 925877846..416531353 100644 --- a/fury/tests/test_testing.py +++ b/fury/tests/test_testing.py @@ -49,7 +49,9 @@ def _add_to_scene(self, _scene): simple_ui = SimplestUI() current_size = (900, 600) scene = window.Scene() - show_manager = window.ShowManager(scene, size=current_size, title="FURY GridUI") + show_manager = window.ShowManager( + scene=scene, size=current_size, title="FURY GridUI" + ) scene.add(simple_ui) event_counter = ft.EventCounter() event_counter.monitor(simple_ui) diff --git a/fury/tests/test_thread.py b/fury/tests/test_thread.py index 35e2ac041..8c26e30d4 100644 --- a/fury/tests/test_thread.py +++ b/fury/tests/test_thread.py @@ -20,7 +20,7 @@ def test_multithreading(): # Preparing the show manager as usual showm = window.ShowManager( - scene, size=(900, 768), reset_camera=False, order_transparent=True + scene=scene, size=(900, 768), reset_camera=False, order_transparent=True ) # showm.initialize() diff --git a/fury/tests/test_window.py b/fury/tests/test_window.py index 87115298e..3c3e11b4e 100644 --- a/fury/tests/test_window.py +++ b/fury/tests/test_window.py @@ -36,26 +36,26 @@ def test_scene(): axes = actor.axes() scene.add(axes) arr = window.snapshot(scene) - report = window.analyze_snapshot(arr, bg_color) + report = window.analyze_snapshot(arr, bg_color=bg_color) npt.assert_equal(report.objects, 1) # Test remove actor function by analyzing a snapshot scene.rm(axes) arr = window.snapshot(scene) - report = window.analyze_snapshot(arr, bg_color) + report = window.analyze_snapshot(arr, bg_color=bg_color) npt.assert_equal(report.objects, 0) # Add actor to scene to test the remove all actors function by analyzing a # snapshot scene.add(axes) arr = window.snapshot(scene) - report = window.analyze_snapshot(arr, bg_color) + report = window.analyze_snapshot(arr, bg_color=bg_color) npt.assert_equal(report.objects, 1) # Test remove all actors function by analyzing a snapshot scene.rm_all() arr = window.snapshot(scene) - report = window.analyze_snapshot(arr, bg_color) + report = window.analyze_snapshot(arr, bg_color=bg_color) npt.assert_equal(report.objects, 0) # Test change background color from scene by analyzing the scene - ren2 = window.Scene(bg_float) + ren2 = window.Scene(background=bg_float) ren2.background((0, 0, 0.0)) report = window.analyze_scene(ren2) npt.assert_equal(report.bg_color, (0, 0, 0)) @@ -130,7 +130,9 @@ def test_active_camera(): direction = scene.camera_direction() position, focal_point, view_up = scene.get_camera() - scene.set_camera((0.0, 0.0, 1.0), (0.0, 0.0, 0), view_up) + scene.set_camera( + position=(0.0, 0.0, 1.0), focal_point=(0.0, 0.0, 0), view_up=view_up + ) position, focal_point, view_up = scene.get_camera() npt.assert_almost_equal(np.dot(direction, position), -1) @@ -168,7 +170,9 @@ def test_active_camera(): report = window.analyze_snapshot(arr, colors=(0, 255, 0)) npt.assert_equal(report.colors_found, [True]) - scene.set_camera((0.0, 0.0, 1.0), (0.0, 0.0, 0), view_up) + scene.set_camera( + position=(0.0, 0.0, 1.0), focal_point=(0.0, 0.0, 0), view_up=view_up + ) # vertical rotation of the camera around the focal point scene.pitch(10) @@ -203,14 +207,14 @@ def test_parallel_projection(): # Put the camera on a angle so that the # camera can show the difference between perspective # and parallel projection - scene.set_camera((1.5, 1.5, 1.5)) + scene.set_camera(position=(1.5, 1.5, 1.5)) scene.GetActiveCamera().Zoom(2) # window.show(scene, reset_camera=True) scene.reset_camera() arr = window.snapshot(scene) - scene.projection("parallel") + scene.projection(proj_type="parallel") # window.show(scene, reset_camera=False) arr2 = window.snapshot(scene) # Because of the parallel projection the two axes @@ -218,7 +222,7 @@ def test_parallel_projection(): # pixels rather than in perspective projection were # the axes being further will be smaller. npt.assert_equal(np.sum(arr2 > 0) > np.sum(arr > 0), True) - scene.projection("perspective") + scene.projection(proj_type="perspective") arr2 = window.snapshot(scene) npt.assert_equal(np.sum(arr2 > 0), np.sum(arr > 0)) @@ -322,7 +326,7 @@ def test_save_screenshot(): scene.add(sphere_actor) window_sz = (400, 400) - show_m = window.ShowManager(scene, size=window_sz) + show_m = window.ShowManager(scene=scene, size=window_sz) with InTemporaryDirectory(): fname = "test.png" @@ -359,7 +363,7 @@ def test_stereo(): np.array([[-1, 1, 0.0], [1, 1, 0.0]]), ] colors = np.array([[1.0, 0.0, 0.0], [0.0, 1.0, 0.0]]) - stream_actor = actor.streamtube(lines, colors, linewidth=0.3, opacity=0.5) + stream_actor = actor.streamtube(lines, colors=colors, linewidth=0.3, opacity=0.5) scene.add(stream_actor) @@ -398,7 +402,7 @@ def test_frame_rate(): scene.add(sphere_actor) showm = window.ShowManager( - scene, size=(900, 768), reset_camera=False, order_transparent=True + scene=scene, size=(900, 768), reset_camera=False, order_transparent=True ) counter = itertools.count() @@ -540,7 +544,7 @@ def test_opengl_state_simple(): scales=0.2, ) showm = window.ShowManager( - scene, size=(900, 768), reset_camera=False, order_transparent=False + scene=scene, size=(900, 768), reset_camera=False, order_transparent=False ) scene.add(actors) @@ -566,7 +570,7 @@ def test_opengl_state_add_remove_and_check(): scales=0.2, ) showm = window.ShowManager( - scene, size=(900, 768), reset_camera=False, order_transparent=False + scene=scene, size=(900, 768), reset_camera=False, order_transparent=False ) scene.add(actor_no_depth_test) diff --git a/fury/ui/tests/test_containers.py b/fury/ui/tests/test_containers.py index 333fb7b44..1c016290d 100644 --- a/fury/ui/tests/test_containers.py +++ b/fury/ui/tests/test_containers.py @@ -22,7 +22,7 @@ def setup_module(): def test_wrong_interactor_style(): panel = ui.Panel2D(size=(300, 150)) dummy_scene = window.Scene() - _ = window.ShowManager(dummy_scene, interactor_style="trackball") + _ = window.ShowManager(scene=dummy_scene, interactor_style="trackball") npt.assert_raises(TypeError, panel.add_to_scene, dummy_scene) @@ -35,17 +35,32 @@ def test_grid_ui1(interactive=False): vol1[25:75, 25:75, 25:75] = 100 colors = distinguishable_colormap(nb_colors=3) - contour_actor1 = actor.contour_from_roi(vol1, np.eye(4), colors[0], 1.0) + contour_actor1 = actor.contour_from_roi( + vol1, + affine=np.eye(4), + color=colors[0], + opacity=1.0, + ) vol2 = np.zeros((100, 100, 100)) vol2[25:75, 25:75, 25:75] = 100 - contour_actor2 = actor.contour_from_roi(vol2, np.eye(4), colors[1], 1.0) + contour_actor2 = actor.contour_from_roi( + vol2, + affine=np.eye(4), + color=colors[1], + opacity=1.0, + ) vol3 = np.zeros((100, 100, 100)) vol3[25:75, 25:75, 25:75] = 100 - contour_actor3 = actor.contour_from_roi(vol3, np.eye(4), colors[2], 1.0) + contour_actor3 = actor.contour_from_roi( + vol3, + affine=np.eye(4), + color=colors[2], + opacity=1.0, + ) scene = window.Scene() actors = [] @@ -88,7 +103,7 @@ def test_grid_ui1(interactive=False): texts.append(text_actor3) counter = itertools.count() - show_m = window.ShowManager(scene) + show_m = window.ShowManager(scene=scene) def timer_callback(_obj, _event): nonlocal show_m, counter @@ -136,17 +151,32 @@ def test_grid_ui2(interactive=False): vol1[25:75, 25:75, 25:75] = 100 colors = distinguishable_colormap(nb_colors=3) - contour_actor1 = actor.contour_from_roi(vol1, np.eye(4), colors[0], 1.0) + contour_actor1 = actor.contour_from_roi( + vol1, + affine=np.eye(4), + color=colors[0], + opacity=1.0, + ) vol2 = np.zeros((100, 100, 100)) vol2[25:75, 25:75, 25:75] = 100 - contour_actor2 = actor.contour_from_roi(vol2, np.eye(4), colors[1], 1.0) + contour_actor2 = actor.contour_from_roi( + vol2, + affine=np.eye(4), + color=colors[1], + opacity=1.0, + ) vol3 = np.zeros((100, 100, 100)) vol3[25:75, 25:75, 25:75] = 100 - contour_actor3 = actor.contour_from_roi(vol3, np.eye(4), colors[2], 1.0) + contour_actor3 = actor.contour_from_roi( + vol3, + affine=np.eye(4), + color=colors[2], + opacity=1.0, + ) scene = window.Scene() actors = [] @@ -198,7 +228,9 @@ def test_grid_ui2(interactive=False): current_size = (900, 600) scene = window.Scene() - show_manager = window.ShowManager(scene, size=current_size, title="FURY GridUI") + show_manager = window.ShowManager( + scene=scene, size=current_size, title="FURY GridUI" + ) grid_ui2 = ui.GridUI( actors=actors, diff --git a/fury/ui/tests/test_elements.py b/fury/ui/tests/test_elements.py index 7df1645b1..2f72949cc 100644 --- a/fury/ui/tests/test_elements.py +++ b/fury/ui/tests/test_elements.py @@ -1171,7 +1171,7 @@ def test_ui_draw_shape(): current_size = (900, 900) scene = window.Scene() show_manager = window.ShowManager( - scene, size=current_size, title="DrawShape UI Example" + scene=scene, size=current_size, title="DrawShape UI Example" ) scene.add(line, circle, quad) diff --git a/fury/ui/tests/test_elements_callback.py b/fury/ui/tests/test_elements_callback.py index a0ebbad9d..4fa62e34b 100644 --- a/fury/ui/tests/test_elements_callback.py +++ b/fury/ui/tests/test_elements_callback.py @@ -51,7 +51,7 @@ def test_frame_rate_and_anti_aliasing(): counter = itertools.count() showm = window.ShowManager( - scene, + scene=scene, size=(1980, 1080), reset_camera=False, order_transparent=True, @@ -103,7 +103,7 @@ def timer_callback(_obj, _event): counter = itertools.count() multi_samples = 0 showm = window.ShowManager( - scene, + scene=scene, size=(1980, 1080), reset_camera=False, order_transparent=True, @@ -161,7 +161,10 @@ def test_timer(): tb = ui.TextBlock2D() counter = itertools.count() showm = window.ShowManager( - scene, size=(1024, 768), reset_camera=False, order_transparent=True + scene=scene, + size=(1024, 768), + reset_camera=False, + order_transparent=True, ) scene.add(tb) diff --git a/fury/window.py b/fury/window.py index 7c36cedf3..fc79285fa 100644 --- a/fury/window.py +++ b/fury/window.py @@ -10,6 +10,7 @@ from fury import __version__ as fury_version import fury.animation as anim +from fury.decorators import warn_on_args_to_kwargs from fury.interactor import CustomInteractorStyle from fury.io import load_image, save_image from fury.lib import ( @@ -47,7 +48,8 @@ class Scene(OpenGLRenderer): available in ``vtkRenderer`` if necessary. """ - def __init__(self, background=(0, 0, 0), skybox=None): + @warn_on_args_to_kwargs() + def __init__(self, *, background=(0, 0, 0), skybox=None): self.__skybox = skybox self.__skybox_actor = None if skybox: @@ -61,7 +63,8 @@ def background(self, color): """Set a background color.""" self.SetBackground(color) - def skybox(self, visible=True, gamma_correct=True): + @warn_on_args_to_kwargs() + def skybox(self, *, visible=True, gamma_correct=True): """Show or hide the skybox. Parameters @@ -112,7 +115,8 @@ def rm_all(self): """Remove all actors from the scene.""" self.RemoveAllViewProps() - def projection(self, proj_type="perspective"): + @warn_on_args_to_kwargs() + def projection(self, *, proj_type="perspective"): """Decide between parallel or perspective projection. Parameters @@ -130,7 +134,8 @@ def reset_camera(self): """Reset the camera to an automatic position given by the engine.""" self.ResetCamera() - def reset_camera_tight(self, margin_factor=1.02): + @warn_on_args_to_kwargs() + def reset_camera_tight(self, *, margin_factor=1.02): """Resets camera so the content fit tightly within the window. Parameters @@ -180,7 +185,8 @@ def camera_info(self): print(" Focal Point (%.2f, %.2f, %.2f)" % cam.GetFocalPoint()) print(" View Up (%.2f, %.2f, %.2f)" % cam.GetViewUp()) - def set_camera(self, position=None, focal_point=None, view_up=None): + @warn_on_args_to_kwargs() + def set_camera(self, *, position=None, focal_point=None, view_up=None): """Set up camera position / Focal Point / View Up.""" if position is not None: self.GetActiveCamera().SetPosition(*position) @@ -290,8 +296,10 @@ def fxaa_off(self): class ShowManager: """Class interface between the scene, the window and the interactor.""" + @warn_on_args_to_kwargs() def __init__( self, + *, scene=None, title="FURY", size=(300, 300), @@ -521,7 +529,8 @@ def is_done(self): except AttributeError: return True - def start(self, multithreaded=False, desired_fps=60): + @warn_on_args_to_kwargs() + def start(self, *, multithreaded=False, desired_fps=60): """Start interaction. Parameters @@ -666,7 +675,8 @@ def _stop_recording_and_close(_obj, _evt): events = f.read() return events - def record_events_to_file(self, filename="record.log"): + @warn_on_args_to_kwargs() + def record_events_to_file(self, *, filename="record.log"): """Record events during the interaction. The recording is represented as a list of VTK events @@ -744,7 +754,8 @@ def play_events_from_file(self, filename): self.play_events(events) - def add_window_callback(self, win_callback, event=Command.ModifiedEvent): + @warn_on_args_to_kwargs() + def add_window_callback(self, win_callback, *, event=Command.ModifiedEvent): """Add window callbacks.""" self.window.AddObserver(event, win_callback) self.window.Render() @@ -761,7 +772,8 @@ def add_timer_callback(self, repeat, duration, timer_callback): self.timers.append(timer_id) return timer_id - def add_iren_callback(self, iren_callback, event="MouseMoveEvent"): + @warn_on_args_to_kwargs() + def add_iren_callback(self, iren_callback, *, event="MouseMoveEvent"): if not self.iren.GetInitialized(): self.initialize() self.iren.AddObserver(event, iren_callback) @@ -784,7 +796,8 @@ def exit(self): self.destroy_timers() self.timers.clear() - def save_screenshot(self, fname, magnification=1, size=None, stereo=None): + @warn_on_args_to_kwargs() + def save_screenshot(self, fname, *, magnification=1, size=None, stereo=None): """Save a screenshot of the current window in the specified filename. Parameters @@ -829,8 +842,10 @@ def save_screenshot(self, fname, magnification=1, size=None, stereo=None): ) +@warn_on_args_to_kwargs() def show( scene, + *, title="FURY", size=(300, 300), png_magnify=1, @@ -904,12 +919,12 @@ def show( """ show_manager = ShowManager( - scene, - title, - size, - png_magnify, - reset_camera, - order_transparent, + scene=scene, + title=title, + size=size, + png_magnify=png_magnify, + reset_camera=reset_camera, + order_transparent=order_transparent, stereo=stereo, multi_samples=multi_samples, max_peels=max_peels, @@ -919,7 +934,9 @@ def show( show_manager.start() +@warn_on_args_to_kwargs() def record( + *, scene=None, cam_pos=None, cam_focal=None, @@ -1073,7 +1090,8 @@ def record( renWin.Finalize() -def antialiasing(scene, win, multi_samples=8, max_peels=4, occlusion_ratio=0.0): +@warn_on_args_to_kwargs() +def antialiasing(scene, win, *, multi_samples=8, max_peels=4, occlusion_ratio=0.0): """Enable anti-aliasing and ordered transparency. Parameters @@ -1116,8 +1134,10 @@ def antialiasing(scene, win, multi_samples=8, max_peels=4, occlusion_ratio=0.0): scene.SetOcclusionRatio(occlusion_ratio) +@warn_on_args_to_kwargs() def snapshot( scene, + *, fname=None, size=(300, 300), offscreen=True, @@ -1190,7 +1210,11 @@ def snapshot( if order_transparent: antialiasing( - scene, render_window, multi_samples, max_peels, occlusion_ratio + scene, + render_window, + multi_samples=multi_samples, + max_peels=max_peels, + occlusion_ratio=occlusion_ratio, ) render_window.Render() @@ -1238,8 +1262,9 @@ class ReportScene: return report +@warn_on_args_to_kwargs() def analyze_snapshot( - im, bg_color=colors.black, colors=None, find_objects=True, strel=None + im, *, bg_color=colors.black, colors=None, find_objects=True, strel=None ): """Analyze snapshot from memory or file.