From a6ec769a9b20c45c87ab18a2229e9efa0f030873 Mon Sep 17 00:00:00 2001 From: Ma Nan Date: Fri, 2 Aug 2024 11:34:35 +0800 Subject: [PATCH] fix: macos-arm64 cannot install fix: better layer fill smooth filter --- bioxelnodes/bioxel/layer.py | 12 ++++++++---- bioxelnodes/bioxel/scipy/__init__.py | 5 ++++- bioxelnodes/blender_manifest.toml | 4 ++-- bioxelnodes/operators/container.py | 9 ++++++++- bioxelnodes/operators/io.py | 24 +++--------------------- bioxelnodes/operators/utils.py | 23 +++++++++++++++++++++++ build.py | 23 ++++++++++++++++------- pyproject.toml | 2 +- 8 files changed, 65 insertions(+), 37 deletions(-) diff --git a/bioxelnodes/bioxel/layer.py b/bioxelnodes/bioxel/layer.py index f44d1f9..2910e40 100644 --- a/bioxelnodes/bioxel/layer.py +++ b/bioxelnodes/bioxel/layer.py @@ -77,14 +77,18 @@ def fill(self, value: float, mask: np.ndarray): raise Exception("Mask frame count is not same as ") for f in range(self.frame_count): mask_frame = mask[f, :, :, :] - mask_frame = scipy.median_filter( - mask_frame.astype(np.float32), size=2) + mask_frame = scipy.minimum_filter( + mask_frame.astype(np.float32), size=3) + # mask_frame = scipy.median_filter( + # mask_frame.astype(np.float32), size=2) mask_frames += (mask_frame,) elif mask.ndim == 3: for f in range(self.frame_count): mask_frame = mask[:, :, :] - mask_frame = scipy.median_filter( - mask_frame.astype(np.float32), size=2) + mask_frame = scipy.minimum_filter( + mask_frame.astype(np.float32), size=3) + # mask_frame = scipy.median_filter( + # mask_frame.astype(np.float32), size=2) mask_frames += (mask_frame,) else: raise Exception("Mask shape order should be TXYZ or XYZ") diff --git a/bioxelnodes/bioxel/scipy/__init__.py b/bioxelnodes/bioxel/scipy/__init__.py index 299f581..c8b0ded 100644 --- a/bioxelnodes/bioxel/scipy/__init__.py +++ b/bioxelnodes/bioxel/scipy/__init__.py @@ -1,2 +1,5 @@ from ._interpolation import zoom -from ._filters import gaussian_filter, median_filter +from ._filters import (gaussian_filter, + median_filter, + maximum_filter, + minimum_filter) diff --git a/bioxelnodes/blender_manifest.toml b/bioxelnodes/blender_manifest.toml index 66aaf2d..f2d729b 100644 --- a/bioxelnodes/blender_manifest.toml +++ b/bioxelnodes/blender_manifest.toml @@ -1,7 +1,7 @@ schema_version = "1.0.0" id = "bioxelnodes" -version = "0.3.0" +version = "0.3.1" name = "Bioxel Nodes" tagline = "For scientific volumetric data visualization in Blender" maintainer = "Ma Nan " @@ -20,7 +20,7 @@ wheels = [ "./wheels/SimpleITK-2.3.1-cp311-cp311-macosx_11_0_arm64.whl", "./wheels/SimpleITK-2.3.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", "./wheels/lxml-5.2.2-cp311-cp311-win_amd64.whl", - "./wheels/lxml-5.2.2-cp311-cp311-macosx_10_9_universal2.whl", + "./wheels/lxml-5.2.2-cp311-cp311-macosx_10_9_arm64.whl", "./wheels/lxml-5.2.2-cp311-cp311-macosx_10_9_x86_64.whl", "./wheels/lxml-5.2.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", "./wheels/h5py-3.11.0-cp311-cp311-win_amd64.whl", diff --git a/bioxelnodes/operators/container.py b/bioxelnodes/operators/container.py index 34c45bf..1106e78 100644 --- a/bioxelnodes/operators/container.py +++ b/bioxelnodes/operators/container.py @@ -1,13 +1,15 @@ import bpy + import bmesh from ..nodes import custom_nodes from ..bioxel.io import load_container, save_container +from ..bioxelutils.layer import get_all_layer_objs from ..bioxelutils.container import (container_to_obj, obj_to_container, get_container_objs_from_selection) from ..bioxelutils.node import get_nodes_by_type, move_node_between_nodes, move_node_to_node -from .utils import get_cache_dir, select_object +from .utils import change_render_setting, get_cache_dir, get_preferences, select_object class SaveContainer(bpy.types.Operator): @@ -59,11 +61,16 @@ class LoadContainer(bpy.types.Operator): def execute(self, context): load_path = self.filepath container = load_container(self.filepath) + is_first_import = len(get_all_layer_objs()) == 0 + container_obj = container_to_obj(container, scene_scale=0.01, cache_dir=get_cache_dir(context)) select_object(container_obj) + if is_first_import: + change_render_setting(context) + self.report({"INFO"}, f"Successfully load {load_path}") return {'FINISHED'} diff --git a/bioxelnodes/operators/io.py b/bioxelnodes/operators/io.py index 723037b..d26c967 100644 --- a/bioxelnodes/operators/io.py +++ b/bioxelnodes/operators/io.py @@ -17,7 +17,7 @@ get_container_objs_from_selection) from ..bioxel.parse import (DICOM_EXTS, SUPPORT_EXTS, get_ext, parse_volumetric_data) -from .utils import (get_cache_dir, get_preferences, +from .utils import (change_render_setting, get_cache_dir, get_preferences, progress_update, progress_bar, select_object) # 3rd-party @@ -674,26 +674,8 @@ def modal(self, context, event): select_object(container_obj) # Change render setting for better result - preferences = get_preferences(context) - if preferences.do_change_render_setting and is_first_import: - bpy.context.scene.render.engine = 'CYCLES' - try: - bpy.context.scene.cycles.shading_system = True - bpy.context.scene.cycles.volume_bounces = 12 - bpy.context.scene.cycles.transparent_max_bounces = 16 - bpy.context.scene.cycles.volume_preview_step_rate = 10 - bpy.context.scene.cycles.volume_step_rate = 10 - except: - pass - - try: - bpy.context.scene.eevee.use_taa_reprojection = False - bpy.context.scene.eevee.volumetric_tile_size = '2' - bpy.context.scene.eevee.volumetric_shadow_samples = 128 - bpy.context.scene.eevee.volumetric_samples = 256 - bpy.context.scene.eevee.use_volumetric_shadows = True - except: - pass + if is_first_import: + change_render_setting(context) self.report({"INFO"}, "Successfully Imported") return {'FINISHED'} diff --git a/bioxelnodes/operators/utils.py b/bioxelnodes/operators/utils.py index 6298f3c..d1fda4f 100644 --- a/bioxelnodes/operators/utils.py +++ b/bioxelnodes/operators/utils.py @@ -3,6 +3,29 @@ from .. import __package__ as base_package +def change_render_setting(context): + preferences = get_preferences(context) + if preferences.do_change_render_setting: + bpy.context.scene.render.engine = 'CYCLES' + try: + bpy.context.scene.cycles.shading_system = True + bpy.context.scene.cycles.volume_bounces = 12 + bpy.context.scene.cycles.transparent_max_bounces = 16 + bpy.context.scene.cycles.volume_preview_step_rate = 10 + bpy.context.scene.cycles.volume_step_rate = 10 + except: + pass + + try: + bpy.context.scene.eevee.use_taa_reprojection = False + bpy.context.scene.eevee.volumetric_tile_size = '2' + bpy.context.scene.eevee.volumetric_shadow_samples = 128 + bpy.context.scene.eevee.volumetric_samples = 256 + bpy.context.scene.eevee.use_volumetric_shadows = True + except: + pass + + def select_object(target_obj): for obj in bpy.data.objects: obj.select_set(False) diff --git a/build.py b/build.py index 44e50d6..24a4b35 100644 --- a/build.py +++ b/build.py @@ -53,6 +53,11 @@ def build_extension(platform: Platform, python_version="3.11") -> None: if any([package in f.name for package in packages_to_remove]): f.unlink(missing_ok=True) + elif platform.blender_tag == "macos-arm64" and \ + "lxml" in f.name and "universal2" in f.name: + f.rename(Path(f.parent, + f.name.replace("universal2", "arm64"))) + for ndimage_filepath in scipy_ndimage_dirpath.iterdir(): to_filepath = Path("./bioxelnodes/bioxel/scipy", ndimage_filepath.name) shutil.copy(ndimage_filepath, to_filepath) @@ -61,14 +66,18 @@ def build_extension(platform: Platform, python_version="3.11") -> None: with toml_filepath.open("r") as file: manifest = tomlkit.parse(file.read()) - build = tomlkit.table(True) - generated = tomlkit.table() - generated["platforms"] = [platform.blender_tag] - generated["wheels"] = [f"./wheels/{f.name}" - for f in wheel_dirpath.glob('*.whl')] + manifest["platforms"] = [platform.blender_tag] + manifest["wheels"] = [f"./wheels/{f.name}" + for f in wheel_dirpath.glob('*.whl')] + + # build = tomlkit.table(True) + # generated = tomlkit.table() + # generated["platforms"] = [platform.blender_tag] + # generated["wheels"] = [f"./wheels/{f.name}" + # for f in wheel_dirpath.glob('*.whl')] - build.append('generated', generated) - manifest.append('build', build) + # build.append('generated', generated) + # manifest.append('build', build) # Write the updated TOML file with toml_filepath.open("w") as file: diff --git a/pyproject.toml b/pyproject.toml index c3afcb3..a85589c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "bioxelnodes" -version = "0.3.0" +version = "0.3.1" description = "" authors = ["Ma Nan "] license = "MIT"