Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

install oct2py and jdata from GUI, convert isnormalized properly #9

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions blender2mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 *

Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions mesh2blender.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@

import bpy
import numpy as np
import jdata as jd
import os
from .utils import *

class mesh2scene(bpy.types.Operator):
Expand All @@ -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()
Expand Down
5 changes: 3 additions & 2 deletions nii2mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@

import bpy
import numpy as np
import jdata as jd
import os
from .utils import *

g_maxvol=100
Expand All @@ -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):
Expand Down
5 changes: 3 additions & 2 deletions obj2surf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 *

Expand Down Expand Up @@ -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)
Expand Down
31 changes: 31 additions & 0 deletions pkg.py
Original file line number Diff line number Diff line change
@@ -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"}
5 changes: 3 additions & 2 deletions runmmc.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@

import bpy
import numpy as np
import jdata as jd
import os
from .utils import *

g_nphoton=10000
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion script/blendermmc.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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)

Expand Down