From c82c2b7be47de2fcff9906c07c76e6936cbda1bc Mon Sep 17 00:00:00 2001 From: maharshigor Date: Wed, 18 Dec 2024 16:11:17 +0530 Subject: [PATCH] RF: Lib introduced to consolidate the pygfx imports --- fury/__init__.pyi | 99 ++++++------- fury/io.py | 268 ++++++++++++++++-------------------- fury/io/__init__.py | 3 - fury/io/__init__.pyi | 3 - fury/io/_texture.py | 24 ---- fury/lib.py | 14 ++ fury/window/screen.py | 4 +- fury/window/show_manager.py | 2 +- 8 files changed, 184 insertions(+), 233 deletions(-) delete mode 100644 fury/io/__init__.py delete mode 100644 fury/io/__init__.pyi delete mode 100644 fury/io/_texture.py create mode 100644 fury/lib.py diff --git a/fury/__init__.pyi b/fury/__init__.pyi index 73a25337d..cccc4e6d6 100644 --- a/fury/__init__.pyi +++ b/fury/__init__.pyi @@ -4,58 +4,59 @@ # # to help type-checking tools like mypy and improve the development experience # # with better autocompletion and documentation in code editors. -# __all__ = [ -# "actor", -# "actors", -# "animation", -# "colormap", -# "convert", -# "data", -# "deprecator", -# "decorators", -# "gltf", -# "interactor", -# "io", -# "layout", -# "lib", -# "material", -# "molecular", -# "optpkg", -# "pick", -# "pkg_info", -# "primitive", -# "shaders", -# "stream", -# "testing", -# "transform", -# "ui", -# "utils", -# "window", -# ] +__all__ = [ + # "actor", + # "actors", + # "animation", + # "colormap", + # "convert", + # "data", + # "deprecator", + # "decorators", + # "gltf", + # "interactor", + # "io", + # "layout", + "lib", + # "material", + # "molecular", + # "optpkg", + # "pick", + # "pkg_info", + # "primitive", + # "shaders", + # "stream", + # "testing", + # "transform", + # "ui", + # "utils", + # "window", +] # # the explicit definition of `__all__` will enable type inference for engines. -# from . import ( -# actors, -# animation, -# colormap, -# convert, -# data, -# decorators, -# deprecator, -# gltf, -# interactor, -# io, -# layout, -# optpkg, -# pkg_info, -# primitive, -# shaders, -# stream, -# testing, -# ui, -# window, -# ) +from . import ( + # actors, + # animation, + # colormap, + # convert, + # data, + # decorators, + # deprecator, + # gltf, + # interactor, + # io, + # layout, + # optpkg, + # pkg_info, + # primitive, + # shaders, + # stream, + # testing, + # ui, + # window, + lib, +) # # from .actor import ( # # Container as Container, diff --git a/fury/io.py b/fury/io.py index 485ce5819..2e6567bef 100644 --- a/fury/io.py +++ b/fury/io.py @@ -1,40 +1,77 @@ -# import os +import os + # from tempfile import TemporaryDirectory as InTemporaryDirectory -# from urllib.request import urlretrieve -# import warnings +from urllib.request import urlretrieve -# from PIL import Image -# import numpy as np +# import warnings +from PIL import Image +import numpy as np # from fury.decorators import warn_on_args_to_kwargs -# from fury.lib import ( -# BMPReader, -# BMPWriter, -# ImageData, -# ImageFlip, -# JPEGReader, -# JPEGWriter, -# MNIObjectReader, -# MNIObjectWriter, -# OBJReader, -# PLYReader, -# PLYWriter, -# PNGReader, -# PNGWriter, -# PolyDataReader, -# PolyDataWriter, -# STLReader, -# STLWriter, -# TIFFReader, -# TIFFWriter, -# Texture, -# XMLPolyDataReader, -# XMLPolyDataWriter, -# numpy_support, -# ) +from fury.lib import ( + # BMPReader, + # BMPWriter, + # ImageData, + # ImageFlip, + # JPEGReader, + # JPEGWriter, + # MNIObjectReader, + # MNIObjectWriter, + # OBJReader, + # PLYReader, + # PLYWriter, + # PNGReader, + # PNGWriter, + # PolyDataReader, + # PolyDataWriter, + # STLReader, + # STLWriter, + # TIFFReader, + # TIFFWriter, + # Texture, + # XMLPolyDataReader, + # XMLPolyDataWriter, + # numpy_support, + Texture, +) + # from fury.utils import set_input +def load_cube_map_texture(fnames, *, size=None, generate_mipmaps=True): + """Load Texture + + Parameters + ---------- + fnames : list + filenames to generate cube map. + size : tuple, optional + The display extent (width, height, depth), by default None + generate_mipmaps : bool, optional + automatically generates mipmaps when transferring data to the GPU, by default + True + + Returns + ------- + Texture + PyGfx Texture object. + """ + images = [] + + for fname in fnames: + images.append(load_image(fname)) + + if size is None: + min_side = min(*images[0].shape[:2]) + for image in images: + min_side = min(*image.shape[:2]) + size = (min_side, min_side, 6) + + data = np.stack(images, axis=0) + + return Texture(data, dim=2, size=size, generate_mipmaps=generate_mipmaps) + + # @warn_on_args_to_kwargs() # def load_cubemap_texture(fnames, *, interpolate_on=True, mipmap_on=True): # """Load a cube map texture from a list of 6 images. @@ -76,127 +113,56 @@ # return texture -# @warn_on_args_to_kwargs() -# def load_image(filename, *, as_vtktype=False, use_pillow=True): -# """Load an image. - -# Parameters -# ---------- -# filename: str -# should be png, bmp, jpeg or jpg files -# as_vtktype: bool, optional -# if True, return vtk output otherwise an ndarray. Default False. -# use_pillow: bool, optional -# Use pillow python library to load the files. Default True - -# Returns -# ------- -# image: ndarray or vtk output -# desired image array - -# """ -# is_url = (filename.lower().startswith("http://")) or ( -# filename.lower().startswith("https://") -# ) - -# if is_url: -# image_name = os.path.basename(filename) - -# if len(image_name.split(".")) < 2: -# raise IOError(f"{filename} is not a valid image URL") - -# urlretrieve(filename, image_name) -# filename = image_name - -# if use_pillow: -# with Image.open(filename) as pil_image: -# if pil_image.mode in ["P"]: -# pil_image = pil_image.convert("RGB") - -# if pil_image.mode in ["RGBA", "RGB", "L"]: -# image = np.asarray(pil_image) -# elif pil_image.mode.startswith("I;16"): -# raw = pil_image.tobytes("raw", pil_image.mode) -# dtype = ">u2" if pil_image.mode.endswith("B") else "