Skip to content

Commit

Permalink
Merge pull request #35 from OmooLab/feature/dev
Browse files Browse the repository at this point in the history
fix: macos-arm64 cannot install
  • Loading branch information
icrdr authored Aug 2, 2024
2 parents 7430fbf + a6ec769 commit 088d9c1
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 37 deletions.
12 changes: 8 additions & 4 deletions bioxelnodes/bioxel/layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
5 changes: 4 additions & 1 deletion bioxelnodes/bioxel/scipy/__init__.py
Original file line number Diff line number Diff line change
@@ -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)
4 changes: 2 additions & 2 deletions bioxelnodes/blender_manifest.toml
Original file line number Diff line number Diff line change
@@ -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 <icrdr2010@outlook.com>"
Expand All @@ -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",
Expand Down
9 changes: 8 additions & 1 deletion bioxelnodes/operators/container.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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'}

Expand Down
24 changes: 3 additions & 21 deletions bioxelnodes/operators/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'}
Expand Down
23 changes: 23 additions & 0 deletions bioxelnodes/operators/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
23 changes: 16 additions & 7 deletions build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "bioxelnodes"
version = "0.3.0"
version = "0.3.1"
description = ""
authors = ["Ma Nan <icrdr2010@outlook.com>"]
license = "MIT"
Expand Down

0 comments on commit 088d9c1

Please sign in to comment.