Skip to content

Commit

Permalink
Merge pull request #49 from oanegros/development
Browse files Browse the repository at this point in the history
Hotfixes volume size and test if material autogen things are there, restricts numpy to v1
  • Loading branch information
oanegros committed Jun 20, 2024
2 parents 397ede1 + 16f8ee6 commit 79c74d5
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 10 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ test:
version := $(shell grep version pyproject.toml | grep -o -E "\b[0-9]+\.[0-9]+\.[0-9]+\b")

template:
mkdir tif2blender/assets
mkdir tif2blender/assets/template
cd tif2blender/assets/template && zip -r tif2blender.zip ../../../tif2blender

# git clean -dfX
Expand Down
8 changes: 4 additions & 4 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "tif2blender"
version = "1.0.0"
version = "1.0.1"
description = "Loading and handling microscopy data in Blender."
authors = ["Oane Gros <oane.gros@embl.de>"]
include = [
Expand All @@ -12,6 +12,7 @@ python = "~=3.11.6"
bpy = ">=4.1.0"
tifffile = "==2023.4.12"
scikit-image = "==0.22.0"
numpy = "< 2.0.0"


[tool.poetry.dev-dependencies]
Expand Down
3 changes: 3 additions & 0 deletions tif2blender/load_components/load_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ def init_material_axes():
links.new(trbsdf.outputs[0], mix.inputs[2])
links.new(and_op.outputs[0], mix.inputs[0])

if nodes.get("Material Output") is None:
outnode = nodes.new(type='ShaderNodeOutputMaterial')
outnode.name = 'Material Output'
out = nodes.get("Material Output")
out.location = (650, 0)
links.new(mix.outputs[0], out.inputs[0])
Expand Down
6 changes: 5 additions & 1 deletion tif2blender/load_components/load_labelmask.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ def labelmask_shader(maskchannel, maxval):
except Exception as e:
print(e)
princ = nodes.new("ShaderNodeBsdfPrincipled")
if nodes.get("Material Output") is None:
outnode = nodes.new(type='ShaderNodeOutputMaterial')
outnode.name = 'Material Output'
links.new(princ.outputs[0], nodes.get('Material Output').inputs[0])

idnode = nodes.new("ShaderNodeVertexColor")
Expand Down Expand Up @@ -181,6 +184,7 @@ def export_alembic_and_loc(mask, maskchannel, cache_dir, remake, axes_order):

if Path(fname).exists() and remake:
Path(fname).unlink() # this may fix an issue with subsequent loads

bpy.ops.wm.alembic_export(filepath=fname,
visible_objects_only=False,
selected=True,
Expand Down Expand Up @@ -211,7 +215,7 @@ def import_abc_and_loc(maskchannel, scale, cache_dir):

channel_collection, _ = make_subcollection(f"channel {maskchannel} labelmask")
bpy.ops.wm.alembic_import(filepath=abcfname(cache_dir, maskchannel, 0), is_sequence=True)

with open(jsonfname(cache_dir, maskchannel), 'r') as fp:
locations = json.load(fp)

Expand Down
13 changes: 9 additions & 4 deletions tif2blender/load_components/load_volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def arrays_to_vdb_files(volume_arrays, axes_order, remake, cache_dir):
for ch in volume_arrays:
volume_arrays[ch]['vdbs'] = []
imgdata = volume_arrays[ch]['data']
n_splits = [(imgdata.shape[dim] // 50)+ 1 for dim in [axes_order.find('x'),axes_order.find('y'),axes_order.find('z')]]
n_splits = [(imgdata.shape[dim] // 2049)+ 1 for dim in [axes_order.find('x'),axes_order.find('y'),axes_order.find('z')]]
a_chunks = np.array_split(imgdata, n_splits[0], axis=axes_order.find('x'))
for a_ix, a_chunk in enumerate(a_chunks):
b_chunks = np.array_split(a_chunk, n_splits[1], axis=axes_order.find('y'))
Expand Down Expand Up @@ -102,7 +102,10 @@ def volume_materials(volume_inputs, emission_setting):
add.location = (450, -300)
links.new(adsorb.outputs[0], add.inputs[0])
links.new(scatter.outputs[0], add.inputs[1])


if nodes.get("Material Output") is None:
outnode = nodes.new(type='ShaderNodeOutputMaterial')
outnode.name = 'Material Output'
nodes.get("Material Output").location = (700,00)
if emission_setting:
links.new(emit.outputs[0], nodes.get("Material Output").inputs.get('Volume'))
Expand Down Expand Up @@ -145,6 +148,8 @@ def load_volume(volume_inputs, bbox_px, scale, cache_coll, base_coll, emission_s
for mat in vol_obj.data.materials:
# make sure color ramp is immediately visibile under Volume shader
# mat.node_tree.nodes["Slice Cube"].inputs[0].show_expanded = True
mat.node_tree.nodes["Emission"].inputs[0].show_expanded = True

try:
mat.node_tree.nodes["Emission"].inputs[0].show_expanded = True
except:
pass
return vol_obj, volume_inputs

0 comments on commit 79c74d5

Please sign in to comment.