From fd613d7febf0b4dc2b13557d2ceee2bc82982ae4 Mon Sep 17 00:00:00 2001 From: victor Date: Thu, 20 Apr 2023 17:37:58 -0400 Subject: [PATCH 1/2] Add install package button --- __init__.py | 5 +++++ blender2mesh.py | 5 +++-- mesh2blender.py | 4 ++-- nii2mesh.py | 5 +++-- obj2surf.py | 5 +++-- pkg.py | 31 +++++++++++++++++++++++++++++++ runmmc.py | 5 +++-- ui.py | 4 ++++ 8 files changed, 54 insertions(+), 10 deletions(-) create mode 100644 pkg.py diff --git a/__init__.py b/__init__.py index e7cecae..4259caf 100644 --- a/__init__.py +++ b/__init__.py @@ -75,9 +75,12 @@ from .niifile import niifile from .nii2mesh import nii2mesh from bpy.props import PointerProperty +from .pkg import InstallOct2py, InstallJData def register(): print("Registering BlenderPhotonics") + bpy.utils.register_class(InstallOct2py) + bpy.utils.register_class(InstallJData) bpy.utils.register_class(scene2mesh) bpy.utils.register_class(object2surf) bpy.utils.register_class(niifile) @@ -90,6 +93,8 @@ def register(): def unregister(): print("Unregistering BlenderPhotonics") + bpy.utils.unregister_class(InstallOct2py) + bpy.utils.unregister_class(InstallJData) bpy.utils.unregister_class(scene2mesh) bpy.utils.unregister_class(object2surf) bpy.utils.unregister_class(niifile) diff --git a/blender2mesh.py b/blender2mesh.py index b20402d..bd69448 100644 --- a/blender2mesh.py +++ b/blender2mesh.py @@ -23,8 +23,6 @@ import bpy import numpy as np -import jdata as jd -import os from bpy.utils import register_class, unregister_class from .utils import * @@ -69,6 +67,9 @@ def description(cls, context, properties): return hints[properties.endstep] def func(self): + import jdata as jd + import os + outputdir = GetBPWorkFolder(); if not os.path.isdir(outputdir): os.makedirs(outputdir) diff --git a/mesh2blender.py b/mesh2blender.py index 5aa83a4..bc0d3e1 100644 --- a/mesh2blender.py +++ b/mesh2blender.py @@ -23,8 +23,6 @@ import bpy import numpy as np -import jdata as jd -import os from .utils import * class mesh2scene(bpy.types.Operator): @@ -33,6 +31,8 @@ class mesh2scene(bpy.types.Operator): bl_idname = 'blenderphotonics.meshtoscene' def importmesh(self): + import jdata as jd + import os # clear all object bpy.ops.object.select_all(action='SELECT') bpy.ops.object.delete() diff --git a/nii2mesh.py b/nii2mesh.py index 62af1ff..d772f97 100644 --- a/nii2mesh.py +++ b/nii2mesh.py @@ -24,8 +24,6 @@ import bpy import numpy as np -import jdata as jd -import os from .utils import * g_maxvol=100 @@ -51,6 +49,9 @@ class nii2mesh(bpy.types.Operator): method: bpy.props.EnumProperty(name="Mesh extraction method", items = [('auto','auto','auto'),('cgalmesh','cgalmesh','cgalmesh'), ('cgalsurf','cgalsurf','cgalsurf'), ('simplify','simplify','simplify')]) def vol2mesh(self): + import jdata as jd + import os + # Remove last .jmsh file outputdir = GetBPWorkFolder() if not os.path.isdir(outputdir): diff --git a/obj2surf.py b/obj2surf.py index 0a2f287..0aca2bf 100644 --- a/obj2surf.py +++ b/obj2surf.py @@ -23,8 +23,6 @@ import bpy from bpy_extras.io_utils import ImportHelper import numpy as np -import jdata as jd -import os from bpy.utils import register_class, unregister_class from .utils import * @@ -66,6 +64,9 @@ def description(cls, context, properties): return hints[properties.action] def func(self): + import jdata as jd + import os + outputdir = GetBPWorkFolder(); if not os.path.isdir(outputdir): os.makedirs(outputdir) diff --git a/pkg.py b/pkg.py new file mode 100644 index 0000000..e004974 --- /dev/null +++ b/pkg.py @@ -0,0 +1,31 @@ +import bpy +import subprocess +import sys +import os +import pathlib + + +class InstallOct2py(bpy.types.Operator): + bl_idname = "blenderphotonics.install_oct2py" + bl_label = "Install Package" + bl_description = "Install Oct2py Python package" + bl_options = {"REGISTER", "UNDO"} + + def execute(self, context): + # Install Oct2py + ADDON_DIR = os.path.join(os.path.abspath(pathlib.Path(__file__).resolve().parent.parent), "modules") + subprocess.call([sys.executable, "-m", "pip", "install", "oct2py", "--target=" + ADDON_DIR]) + return {"FINISHED"} + + +class InstallJData(bpy.types.Operator): + bl_idname = "blenderphotonics.install_jdata" + bl_label = "Install Package" + bl_description = "Install JData package" + bl_options = {"REGISTER", "UNDO"} + + def execute(self, context): + # Install JData + ADDON_DIR = os.path.join(os.path.abspath(pathlib.Path(__file__).resolve().parent.parent), "modules") + subprocess.call([sys.executable, "-m", "pip", "install", "jdata", "--target=" + ADDON_DIR]) + return {"FINISHED"} \ No newline at end of file diff --git a/runmmc.py b/runmmc.py index 153f47b..6142a97 100644 --- a/runmmc.py +++ b/runmmc.py @@ -23,8 +23,6 @@ import bpy import numpy as np -import jdata as jd -import os from .utils import * g_nphoton=10000 @@ -59,6 +57,9 @@ class runmmc(bpy.types.Operator): debuglevel: bpy.props.StringProperty(default=g_debuglevel,name="Debug flag [MCBWDIOXATRPE]") def preparemmc(self): + import jdata as jd + import os + ## save optical parameters and source source information parameters = [] # mu_a, mu_s, n, g cfg = [] # location, direction, photon number, Type, diff --git a/ui.py b/ui.py index c24ed5e..70ed35a 100644 --- a/ui.py +++ b/ui.py @@ -28,6 +28,7 @@ from .niifile import niifile from .nii2mesh import nii2mesh from .obj2surf import object2surf +from .pkg import InstallJData, InstallOct2py class BlenderPhotonics_UI(bpy.types.Panel): bl_label = 'BlenderPhotonics v2022' @@ -45,6 +46,9 @@ def draw(self, context): scene = context.scene bp = scene.blender_photonics rowengine = layout.row() + rowengine.operator(InstallOct2py.bl_idname, text="Install Oct2py", icon='FILE_TICK') + rowengine.operator(InstallJData.bl_idname, text="Install JData", icon='FILE_TICK') + rowengine = layout.row() rowengine.label(text="Backend:") rowengine.prop(bp, "backend", expand=True) From a285a8557d91f405776dfb848406d898cabb76b6 Mon Sep 17 00:00:00 2001 From: victor Date: Tue, 25 Apr 2023 13:56:38 -0400 Subject: [PATCH 2/2] fix isnormalized bug --- script/blendermmc.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/script/blendermmc.m b/script/blendermmc.m index 1319472..12bdbbc 100644 --- a/script/blendermmc.m +++ b/script/blendermmc.m @@ -63,7 +63,7 @@ function blendermmc(paramfile, meshfile) cfg.tend=param.cfg.tend; cfg.tstep=param.cfg.tstep; cfg.isreflect=double(param.cfg.isreflect); -cfg.isnormalized=param.cfg.isnormalized; +cfg.isnormalized=double(param.cfg.isnormalized); cfg.gpuid=param.cfg.gpuid; cfg.unitinmm = param.cfg.unitinmm; cfg.outputtype=param.cfg.outputtype;