23 Commits

Author SHA1 Message Date
Ma Nan
637fc758a7 Merge pull request #25 from OmooLab/feature/dev
chore: change version
2024-07-04 15:06:10 +08:00
f90bf5c532 chore: change version 2024-07-04 15:05:22 +08:00
Ma Nan
f2d1d02c48 Merge pull request #24 from OmooLab/feature/dev
fix: misspell of "scalar"
2024-07-04 15:03:58 +08:00
d04f100dfd fix: misspell of "scalar"
fix: not change raw value of data
2024-07-04 15:02:17 +08:00
Ma Nan
734c4d1cd9 Merge pull request #23 from OmooLab/feature/dev
fix: fail to import membrane shader
2024-07-04 13:50:11 +08:00
78aba5394f fix: fail to import membrane shader 2024-07-04 13:49:18 +08:00
Ma Nan
4fc89beaa0 Merge pull request #22 from OmooLab/feature/dev
fix: fail to import nd_image
2024-07-04 13:43:17 +08:00
fb2a3c9c23 fix: fail to import nd_image
fix: membrane shader
2024-07-04 13:41:52 +08:00
Ma Nan
bc6f88996c Merge pull request #21 from OmooLab/feature/dev
feat: rewrite resize
2024-07-04 13:06:24 +08:00
1db63dd3db feat: rewrite resize
add more nodes
2024-07-04 13:05:46 +08:00
Ma Nan
467d368a76 Merge pull request #19 from OmooLab/feature/dev
feat: support eevee
2024-06-12 15:24:06 +08:00
134d8e382b feat: support eevee 2024-06-12 15:23:09 +08:00
Ma Nan
fefc9285e1 Merge pull request #18 from OmooLab/feature/dev
Feature/dev
2024-06-05 09:40:33 +08:00
322b84cc70 docs: update cover img
add extension description
2024-06-05 09:39:15 +08:00
f3be5d8660 feat: support blender 4.2 extension 2024-06-05 09:11:22 +08:00
470cdab4f6 fix: logging utf-8 cannot decode 2024-06-03 12:36:23 +08:00
Ma Nan
b35c816c25 Merge pull request #17 from OmooLab/feature/dev
fix: cannot convert to mesh in chinese language blender
2024-05-31 13:38:08 +08:00
0e2d6fe1a2 fix: cannot convert to mesh in chinese language blender 2024-05-31 13:36:47 +08:00
Ma Nan
e0c46e95f8 Merge pull request #16 from OmooLab/feature/dev
fix: label join scalar cannot get scalar offset
2024-05-31 10:10:55 +08:00
2528d984ad fix: label join scalar cannot get scalar offset 2024-05-31 10:10:16 +08:00
Ma Nan
56606fd721 Merge pull request #15 from OmooLab/feature/dev
Feature/dev
2024-05-30 09:54:57 +08:00
f21f7d6357 docs: v0.2.0 docs 2024-05-30 09:53:07 +08:00
fa031e63f8 feat: redesign nodes 2024-05-29 11:00:38 +08:00
78 changed files with 5988 additions and 945 deletions

View File

@@ -22,7 +22,7 @@ jobs:
# id: draft_release # id: draft_release
# uses: cardinalby/git-get-release-action@1.2.4 # uses: cardinalby/git-get-release-action@1.2.4
# with: # with:
# releaseName: Draft # releaseName: Upload
# env: # env:
# GITHUB_TOKEN: ${{ github.token }} # GITHUB_TOKEN: ${{ github.token }}
@@ -58,7 +58,7 @@ jobs:
- name: Checkout Code - name: Checkout Code
uses: actions/checkout@v4 uses: actions/checkout@v4
with: with:
lfs: 'true' lfs: "true"
- name: Zip Add-on - name: Zip Add-on
run: | run: |
zip -r package.zip bioxelnodes zip -r package.zip bioxelnodes
@@ -70,5 +70,37 @@ jobs:
with: with:
upload_url: ${{ needs.draft_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps upload_url: ${{ needs.draft_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
asset_path: ./package.zip asset_path: ./package.zip
asset_name: BioxelNodes_${{ needs.draft_release.outputs.version }}.zip asset_name: BioxelNodes_Addon_${{ needs.draft_release.outputs.version }}.zip
asset_content_type: application/zip
upload_blender_extension:
name: Upload Blender Extension
needs: draft_release
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
lfs: "true"
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.11
- name: Zip Extension
run: |
pip download SimpleITK==2.3.1 --dest bioxelnodes/wheels --only-binary=:all: --python-version=3.11 --platform=win_amd64
rm -r bioxelnodes/externalpackage
cp extension/__init__.py bioxelnodes/__init__.py
cp extension/preferences.py bioxelnodes/preferences.py
cp extension/blender_manifest.toml bioxelnodes/blender_manifest.toml
zip -r package.zip bioxelnodes
- name: Upload Release Asset
id: upload-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ needs.draft_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
asset_path: ./package.zip
asset_name: BioxelNodes_Extension_${{ needs.draft_release.outputs.version }}.zip
asset_content_type: application/zip asset_content_type: application/zip

2
.gitignore vendored
View File

@@ -132,3 +132,5 @@ blendcache_*
*.ipynb *.ipynb
.secrets .secrets
!bioxelnodes/scipy/_nd_image.cp311-win_amd64.pyd

View File

@@ -1,25 +1,25 @@
[中文文档](https://uj6xfhbzp0.feishu.cn/wiki/Qx3VwHuNPimeI8kr6nDcvl1DnHf?from=from_copylink) [中文文档](https://uj6xfhbzp0.feishu.cn/wiki/Qx3VwHuNPimeI8kr6nDcvl1DnHf?from=from_copylink)
# Bioxel Nodes # 🦖 Bioxel Nodes
![Static Badge](https://img.shields.io/badge/Blender-orange?style=for-the-badge&logo=blender&logoColor=white) ![Static Badge](https://img.shields.io/badge/Blender-orange?style=for-the-badge&logo=blender&logoColor=white)
![GitHub License](https://img.shields.io/github/license/OmooLab/BioxelNodes?style=for-the-badge) ![GitHub License](https://img.shields.io/github/license/OmooLab/BioxelNodes?style=for-the-badge)
![GitHub Release](https://img.shields.io/github/v/release/OmooLab/BioxelNodes?style=for-the-badge) ![GitHub Release](https://img.shields.io/github/v/release/OmooLab/BioxelNodes?style=for-the-badge)
![GitHub Repo stars](https://img.shields.io/github/stars/OmooLab/BioxelNodes?style=for-the-badge) ![GitHub Repo stars](https://img.shields.io/github/stars/OmooLab/BioxelNodes?style=for-the-badge)
Bioxel Nodes is a Blender add-on for scientific volumetric data visualization. It using Blender's powerful Geometry Nodes | Cycles to process and render volumetric data. Bioxel Nodes is a Blender extension for scientific volumetric data visualization. It using Blender's powerful Geometry Nodes and Cycles to process and render volumetric data. You are free to share your blender file to anyone who does not install this extension, since most processes were done by Blender's native nodes.
# About ## About
Before us, there have been many tutorials and add-ons for importing volumetric data into Blender. However, we found that there were many details that were not addressed in place, some scientific facts were ignored, and the volume rendering was not pretty enough. With Bioxel Nodes, you can easily import the volumetric data into Blender, and more importantly, it can quickly make a beautiful realistic rendering of it. Before us, there have been many tutorials and extensions for importing volumetric data into Blender. However, we found that there were many scientific issues that were not addressed in place, and the volume render results were not epic. With Bioxel Nodes, you can easily import any format volumetric data into Blender, and more importantly, make a beautiful realistic volume rendering quickly.
Below are some examples with Bioxel Nodes. Thanks to Cycles Render, the volumetric data can be rendered with great detail: Below are some examples with Bioxel Nodes. Thanks to Cycles Render, the volumetric data can be rendered with great detail:
![gallery](docs/assets/gallery.png) ![cover](https://omoolab.github.io/BioxelNodes/latest/assets/cover.png)
The "Bioxel" in "BioxelNodes", is a combination of the words "Bio-" and "Voxel". Bioxel is a voxel that stores biological data. The volumetric data made up of Bioxel is called Bioxels. We are developing a toolkit around Bioxels for better biological data visualization. but before its release, we made this Blender version of bioxels toolkit first, in order to let more people to have fun with volumetric data. [Getting Started](https://omoolab.github.io/BioxelNodes/latest/getting-started) So how to use this extension? please check [Getting Started](https://omoolab.github.io/BioxelNodes/latest/getting-started)
# Supported Format ## Supported Format
| Format | EXT | Test | | Format | EXT | Test |
| ------ | ---------------------------------------- | ------- | | ------ | ---------------------------------------- | ------- |
@@ -39,7 +39,32 @@ The "Bioxel" in "BioxelNodes", is a combination of the words "Bio-" and "Voxel".
| MINC | .mnc, .MNC | yet | | MINC | .mnc, .MNC | yet |
| MRC | .mrc, .rec | yet | | MRC | .mrc, .rec | yet |
# Known limitations ## Known Limitations
- Sections cannot be generated - Sections cannot be generated (will be supported soon)
- Time sequence volume not supported (will be supported soon) - Time sequence volume not supported (will be supported soon)
## Upgrade from 0.1.x to 0.2.x
You need to do the following:
1. Remove the old version of Bioxel Nodes at Preferences > Add-ons
2. Add the new version and restart Blender.
It is not support editing the same blender file across extension versions. In order to make sure that the previous file works properly. You need to save the staged data before upgrading ( read the last section of [Getting Started](https://omoolab.github.io/BioxelNodes/latest/getting-started/#share-your-file) ).
But even then, there is still no guarantee that the new version of the extension will work on the old blender file. Therefore, it is highly recommended to open a new blender file to start the creating, not based on the old one.
Alternatively, objects from the old file that have nothing to do with Bioxel Nodes could be append to the new blender file.
## About EEVEE Render
Bioxel Nodes is designed for Cycles Render. However, it does support eevee render partially. "Solid Shader" node and "Volume Shader" node have a toggle called "EEVEE Render". If you want to render Bioxel Component in real-time, turn it on.
Also, there are some limitations:
1. Only one cutter supported.
2. You cannot use "Color Ramp" over 2 colors.
3. EEVEE Render result is not that great as Cycles does.
> "Volume Shader" node is not work properly in EEVEE Next since 4.2. It is because EEVEE Next is not support attributes from instances of volume shader by now. But the Blender 4.2 docs still say attributes reading is ok, so I suppose this feature will eventually be implemented.

View File

@@ -9,7 +9,7 @@ bl_info = {
"author": "Ma Nan", "author": "Ma Nan",
"description": "", "description": "",
"blender": (4, 0, 0), "blender": (4, 0, 0),
"version": (0, 1, 1), "version": (0, 2, 4),
"location": "File -> Import", "location": "File -> Import",
"warning": "", "warning": "",
"category": "Node" "category": "Node"
@@ -21,8 +21,8 @@ auto_load.init()
def register(): def register():
auto_load.register() auto_load.register()
menus.add() menus.add()
bpy.types.Scene.bioxels_dir = bpy.props.StringProperty( bpy.types.Scene.bioxel_layer_dir = bpy.props.StringProperty(
name="Bioxels Directory", name="Layer Directory",
subtype='DIR_PATH', subtype='DIR_PATH',
default="//" default="//"
) )

View File

@@ -57,7 +57,7 @@ def unregister():
################################################# #################################################
def get_all_submodules(directory): def get_all_submodules(directory):
return list(iter_submodules(directory, directory.name)) return list(iter_submodules(directory, __package__))
def iter_submodules(path, package_name): def iter_submodules(path, package_name):

View File

@@ -1,57 +0,0 @@
import bpy
from .utils import get_bioxels_obj, get_node_by_type
class ConvertToMesh(bpy.types.Operator):
bl_idname = "bioxelnodes.convert_to_mesh"
bl_label = "Bioxels To Mesh"
bl_description = "Convert Bioxels To Mesh"
bl_options = {'UNDO'}
@classmethod
def poll(cls, context):
bioxels_obj = None
for obj in bpy.context.selected_objects:
bioxels_obj = get_bioxels_obj(obj)
break
return True if bioxels_obj else False
def execute(self, context):
bioxels_objs = []
for obj in bpy.context.selected_objects:
bioxels_obj = get_bioxels_obj(obj)
if bioxels_obj:
bioxels_objs.append(bioxels_obj)
if len(bioxels_objs) == 0:
self.report({"WARNING"}, "Cannot find any bioxels.")
return {'FINISHED'}
for bioxels_obj in bioxels_objs:
bpy.ops.mesh.primitive_cube_add(
size=2, enter_editmode=False, align='WORLD', location=(0, 0, 0), scale=(1, 1, 1))
mesh_obj = bpy.context.active_object
mesh_obj.name = f"{bioxels_obj.parent.name}_Mesh"
bpy.ops.node.new_geometry_nodes_modifier()
modifier = mesh_obj.modifiers[0]
nodes = modifier.node_group.nodes
links = modifier.node_group.links
output_node = get_node_by_type(nodes, 'NodeGroupOutput')[0]
object_node = nodes.new("GeometryNodeObjectInfo")
realize_nodes = nodes.new("GeometryNodeRealizeInstances")
object_node.inputs[0].default_value = bioxels_obj
object_node.transform_space = 'RELATIVE'
links.new(object_node.outputs['Geometry'], realize_nodes.inputs[0])
links.new(realize_nodes.outputs[0], output_node.inputs[0])
bpy.ops.object.convert(target='MESH')
bpy.context.object.active_material_index = 1
bpy.ops.object.material_slot_remove()
self.report({"INFO"}, f"Successfully convert to mesh")
return {'FINISHED'}

View File

@@ -6,7 +6,7 @@ from .nodes import AddCustomNode
class SaveAllNodes(bpy.types.Operator): class SaveAllNodes(bpy.types.Operator):
bl_idname = "customnodes.save_all_nodes" bl_idname = "customnodes.save_all_nodes"
bl_label = "Save All Custom Nodes" bl_label = "Save All Nodes"
bl_description = "Save All Custom Nodes to Directory." bl_description = "Save All Custom Nodes to Directory."
bl_options = {'UNDO'} bl_options = {'UNDO'}
@@ -21,9 +21,9 @@ class SaveAllNodes(bpy.types.Operator):
for file in files: for file in files:
file_name = Path(file).name file_name = Path(file).name
# "//" # "//"
custom_nodes_dir = bpy.path.abspath(context.scene.custom_nodes_dir) customnodes_node_dir = bpy.path.abspath(context.scene.customnodes_node_dir)
output_path: Path = Path(custom_nodes_dir, file_name).resolve() output_path: Path = Path(customnodes_node_dir, file_name).resolve()
source_path: Path = Path(file).resolve() source_path: Path = Path(file).resolve()
if output_path != source_path: if output_path != source_path:
@@ -51,7 +51,7 @@ class CUSTOMNODES_PT_CustomNodes(bpy.types.Panel):
def draw(self, context): def draw(self, context):
layout = self.layout layout = self.layout
scene = context.scene scene = context.scene
layout.prop(scene, 'custom_nodes_dir') layout.prop(scene, 'customnodes_node_dir')
layout.operator(SaveAllNodes.bl_idname) layout.operator(SaveAllNodes.bl_idname)
@@ -146,10 +146,13 @@ class CustomNodes():
def _find_item(self, found_items, menu_items, node_type: str): def _find_item(self, found_items, menu_items, node_type: str):
for item in menu_items: for item in menu_items:
if item == 'separator':
continue
if item.get("node_type") == node_type: if item.get("node_type") == node_type:
found_items.append(item) found_items.append(item)
item_items = item.get('items') if item != 'separator' else None item_items = item.get('items')
if item_items: if item_items:
self._find_item(found_items, item_items, node_type) self._find_item(found_items, item_items, node_type)
@@ -160,24 +163,26 @@ class CustomNodes():
def add_node(self, node_tree, node_type: str): def add_node(self, node_tree, node_type: str):
item = self.find_item(node_type) item = self.find_item(node_type)
if item:
op = AddCustomNode() op = AddCustomNode()
op.nodes_file = self.nodes_file op.nodes_file = self.nodes_file
op.node_type = item['node_type'] op.node_type = node_type
if item:
op.node_label = item.get('label') or "" op.node_label = item.get('label') or ""
op.node_link = item.get('link') or True op.node_link = item.get('link') or True
op.node_callback = item.get('node_callback') or "" op.node_callback = item.get('node_callback') or ""
return op.add_node(node_tree)
else: else:
raise RuntimeError("No custom node type found.") op.node_label = ""
op.node_link = True
op.node_callback = ""
return op.add_node(node_tree)
def register(self): def register(self):
for cls in self.menu_classes: for cls in self.menu_classes:
bpy.utils.register_class(cls) bpy.utils.register_class(cls)
bpy.types.NODE_MT_add.append(self.add_node_menu) bpy.types.NODE_MT_add.append(self.add_node_menu)
bpy.types.Scene.custom_nodes_dir = bpy.props.StringProperty( bpy.types.Scene.customnodes_node_dir = bpy.props.StringProperty(
name="Nodes Directory", name="Node Directory",
subtype='DIR_PATH', subtype='DIR_PATH',
default="//" default="//"
) )

View File

@@ -76,7 +76,8 @@ class PackageInstaller():
# Set up logging configuration # Set up logging configuration
logfile_path = Path(self.log_path, f"{logfile_name}.log") logfile_path = Path(self.log_path, f"{logfile_name}.log")
logging.basicConfig(filename=logfile_path, level=logging.INFO) logging.basicConfig(filename=logfile_path,
level=logging.INFO, encoding='utf-8')
# Return logger object # Return logger object
return logging.getLogger() return logging.getLogger()
@@ -248,6 +249,7 @@ class PackageInstaller():
result = subprocess.run(cmd_list, timeout=timeout, result = subprocess.run(cmd_list, timeout=timeout,
stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout=subprocess.PIPE, stderr=subprocess.PIPE)
try:
if result.returncode != 0: if result.returncode != 0:
log.error('Command failed: %s', cmd_list) log.error('Command failed: %s', cmd_list)
log.error('stdout: %s', result.stdout.decode()) log.error('stdout: %s', result.stdout.decode())
@@ -255,6 +257,8 @@ class PackageInstaller():
else: else:
log.info('Command succeeded: %s', cmd_list) log.info('Command succeeded: %s', cmd_list)
log.info('stdout: %s', result.stdout.decode()) log.info('stdout: %s', result.stdout.decode())
except:
...
# return the command list, return code, stdout, and stderr as a tuple # return the command list, return code, stdout, and stderr as a tuple
return result return result

View File

@@ -1,3 +1,4 @@
import math
import bpy import bpy
import shutil import shutil
from bpy_extras.io_utils import axis_conversion from bpy_extras.io_utils import axis_conversion
@@ -6,16 +7,20 @@ import numpy as np
from pathlib import Path from pathlib import Path
from uuid import uuid4 from uuid import uuid4
import mathutils import mathutils
import math import random
from .utils import calc_bbox_verts, get_text_index_str, get_bioxels_obj, get_node_by_type, show_message
from . import skimage as ski
from .nodes import custom_nodes from .nodes import custom_nodes
from .props import BIOXELNODES_Series from .props import BIOXELNODES_Series
from .utils import (calc_bbox_verts, get_all_layers, get_container_from_selection, get_layer, get_text_index_str,
get_node_by_type, hide_in_ray, lock_transform, save_vdb, show_message)
try: try:
import SimpleITK as sitk import SimpleITK as sitk
except: except:
... ...
SUPPORT_EXTS = ['.dcm', '.DICOM', SUPPORT_EXTS = ['', '.dcm', '.DCM', '.DICOM',
'.bmp', '.BMP', '.bmp', '.BMP',
'.PIC', '.pic', '.PIC', '.pic',
'.gipl', '.gipl.gz', '.gipl', '.gipl.gz',
@@ -31,15 +36,15 @@ SUPPORT_EXTS = ['.dcm', '.DICOM',
'.png', '.PNG', '.png', '.PNG',
'.vtk'] '.vtk']
SEQUENCE_EXTS = ['.dcm', '.DICOM', SEQUENCE_EXTS = ['.dcm', '.DCM', '.DICOM',
'.bmp', '.BMP', '.bmp', '.BMP',
'.jpg', '.JPG', '.jpeg', '.JPEG', '.jpg', '.JPG', '.jpeg', '.JPEG',
'.tif', '.TIF', '.tiff', '.TIFF', '.tif', '.TIF', '.tiff', '.TIFF',
'.png', '.PNG'] '.png', '.PNG']
DICOM_EXTS = ['.dcm', '.DICOM'] DICOM_EXTS = ['', '.dcm', '.DCM', '.DICOM']
FH_EXTS = ['.dcm', '.DICOM', FH_EXTS = ['', '.dcm', '.DCM', '.DICOM',
'.gipl', '.gipl.gz', '.gipl', '.gipl.gz',
'.mnc', '.MNC', '.mnc', '.MNC',
'.mrc', '.rec', '.mrc', '.rec',
@@ -51,7 +56,7 @@ FH_EXTS = ['.dcm', '.DICOM',
'.gz'] '.gz']
def get_bioxels_shape(bioxel_size: float, orig_shape: tuple, orig_spacing: tuple): def get_layer_shape(bioxel_size: float, orig_shape: tuple, orig_spacing: tuple):
shape = (int(orig_shape[0] / bioxel_size * orig_spacing[0]), shape = (int(orig_shape[0] / bioxel_size * orig_spacing[0]),
int(orig_shape[1] / bioxel_size * orig_spacing[1]), int(orig_shape[1] / bioxel_size * orig_spacing[1]),
int(orig_shape[2] / bioxel_size * orig_spacing[2])) int(orig_shape[2] / bioxel_size * orig_spacing[2]))
@@ -61,6 +66,14 @@ def get_bioxels_shape(bioxel_size: float, orig_shape: tuple, orig_spacing: tuple
shape[2] if shape[2] > 0 else 1) shape[2] if shape[2] > 0 else 1)
def get_layer_size(shape: tuple, bioxel_size: float, scale: float = 1.0):
size = (float(shape[0] * bioxel_size * scale),
float(shape[1] * bioxel_size * scale),
float(shape[2] * bioxel_size * scale))
return size
def get_ext(filepath: str) -> str: def get_ext(filepath: str) -> str:
file_path = Path(filepath) file_path = Path(filepath)
if file_path.name.endswith(".nii.gz"): if file_path.name.endswith(".nii.gz"):
@@ -87,7 +100,7 @@ def get_sequence_index(filepath: str) -> int:
return int(index) if index else 0 return int(index) if index else 0
def collect_image_sequence(filepath: str): def collect_sequence(filepath: str):
file_path = Path(filepath).resolve() file_path = Path(filepath).resolve()
files = list(file_path.parent.iterdir()) files = list(file_path.parent.iterdir())
@@ -100,7 +113,7 @@ def collect_image_sequence(filepath: str):
return sequence return sequence
def read_image(filepath: str, series_id=""): def parse_volume_data(filepath: str, series_id=""):
ext = get_ext(filepath) ext = get_ext(filepath)
if ext in DICOM_EXTS: if ext in DICOM_EXTS:
@@ -111,57 +124,65 @@ def read_image(filepath: str, series_id=""):
series_files = reader.GetGDCMSeriesFileNames( series_files = reader.GetGDCMSeriesFileNames(
str(dir_path), series_id) str(dir_path), series_id)
reader.SetFileNames(series_files) reader.SetFileNames(series_files)
image = reader.Execute() itk_volume = reader.Execute()
name = dir_path.name name = dir_path.name
elif ext in SEQUENCE_EXTS: elif ext in SEQUENCE_EXTS:
image = sitk.ReadImage(filepath) itk_volume = sitk.ReadImage(filepath)
if image.GetDimension() == 2: if itk_volume.GetDimension() == 2:
sequence = collect_image_sequence(filepath) sequence = collect_sequence(filepath)
image = sitk.ReadImage(sequence) itk_volume = sitk.ReadImage(sequence)
name = get_sequence_name(filepath) name = get_sequence_name(filepath)
else: else:
image = sitk.ReadImage(filepath) itk_volume = sitk.ReadImage(filepath)
name = Path(filepath).name.removesuffix(ext) name = Path(filepath).name.removesuffix(ext)
else: else:
image = sitk.ReadImage(filepath) itk_volume = sitk.ReadImage(filepath)
name = Path(filepath).name.removesuffix(ext) name = Path(filepath).name.removesuffix(ext)
return image, name itk_volume = sitk.DICOMOrient(itk_volume, 'RAS')
volume = sitk.GetArrayFromImage(itk_volume)
if volume.ndim == 4:
volume = np.transpose(volume, (2, 1, 0, 3))
else:
volume = np.transpose(volume)
def rgb2gray(image): meta = {
# Convert sRGB image to gray scale and rescale results to [0,255] "name": name,
channels = [sitk.VectorIndexSelectionCast( "shape": tuple(itk_volume.GetSize()),
image, i, sitk.sitkFloat32) for i in range(image.GetNumberOfComponentsPerPixel())] "spacing": tuple(itk_volume.GetSpacing()),
# linear mapping "origin": tuple(itk_volume.GetOrigin()),
I = (0.2126*channels[0] + 0.7152*channels[1] + 0.0722*channels[2]) "direction": tuple(itk_volume.GetDirection()),
}
return sitk.Cast(I, sitk.sitkFloat32) for key, value in meta.items():
print(f"{key}: {value}")
return volume, meta
def x2gray(image):
return sitk.VectorIndexSelectionCast(image, 0, sitk.sitkUInt16)
class ImportVolumeDataDialog(bpy.types.Operator): class ImportVolumeDataDialog(bpy.types.Operator):
bl_idname = "bioxelnodes.import_volume_data_dialog" bl_idname = "bioxelnodes.import_volume_data_dialog"
bl_label = "Volume Data as Bioxels" bl_label = "Volume Data as Bioxel Layer"
bl_description = "Import Volume Data as Bioxels (VDB)" bl_description = "Import Volume Data as Bioxel Layer"
bl_options = {'UNDO'} bl_options = {'UNDO'}
filepath: bpy.props.StringProperty( filepath: bpy.props.StringProperty(
subtype="FILE_PATH", subtype="FILE_PATH"
options={'HIDDEN'} ) # type: ignore
container_name: bpy.props.StringProperty(
name="Container Name"
) # type: ignore
layer_name: bpy.props.StringProperty(
name="Layer Name",
) # type: ignore ) # type: ignore
series_id: bpy.props.StringProperty() # type: ignore series_id: bpy.props.StringProperty() # type: ignore
resample_method: bpy.props.EnumProperty( container: bpy.props.StringProperty() # type: ignore
name="Resample Method",
default="linear",
items=[("linear", "Linear", ""),
("nearest_neighbor", "Nearest Neighbor", ""),
("gaussian", "Gaussian", "")]
) # type: ignore
read_as: bpy.props.EnumProperty( read_as: bpy.props.EnumProperty(
name="Read as", name="Read as",
@@ -170,15 +191,10 @@ class ImportVolumeDataDialog(bpy.types.Operator):
("labels", "Labels", "")] ("labels", "Labels", "")]
) # type: ignore ) # type: ignore
label_index: bpy.props.IntProperty(
name="Label Index",
default=1
) # type: ignore
bioxel_size: bpy.props.FloatProperty( bioxel_size: bpy.props.FloatProperty(
name="Bioxel Size (Larger size means small resolution)", name="Bioxel Size (Larger size means small resolution)",
soft_min=0.1, soft_max=10.0, soft_min=0.1, soft_max=10.0,
min=1e-2, max=1e2, min=0.1, max=1e2,
default=1, default=1,
) # type: ignore ) # type: ignore
@@ -193,8 +209,8 @@ class ImportVolumeDataDialog(bpy.types.Operator):
) # type: ignore ) # type: ignore
scene_scale: bpy.props.FloatProperty( scene_scale: bpy.props.FloatProperty(
name="Scene Scale (Bioxels Unit pre Blender Unit)", name="Scene Scale (Bioxel Unit pre Blender Unit)",
soft_min=0.001, soft_max=100.0, soft_min=0.0001, soft_max=10.0,
min=1e-6, max=1e6, min=1e-6, max=1e6,
default=0.01, default=0.01,
) # type: ignore ) # type: ignore
@@ -204,139 +220,21 @@ class ImportVolumeDataDialog(bpy.types.Operator):
default=True, default=True,
) # type: ignore ) # type: ignore
invert_scalar: bpy.props.BoolProperty(
name="Invert Scalar (Background value maybe higher than object)",
default=False,
) # type: ignore
def execute(self, context): def execute(self, context):
image, bioxels_name = read_image(self.filepath, self.series_id) is_first_import = len(get_all_layers()) == 0
volume, meta = parse_volume_data(self.filepath)
container_name = self.container_name or meta['name'] or "Container"
bioxel_size = self.bioxel_size bioxel_size = self.bioxel_size
orig_spacing = self.orig_spacing orig_spacing = self.orig_spacing
image_spacing = image.GetSpacing()
image_shape = image.GetSize()
bioxels_spacing = ( layer_spacing = (
image_spacing[0] / orig_spacing[0] * bioxel_size, meta['spacing'][0] / orig_spacing[0] * bioxel_size,
image_spacing[1] / orig_spacing[1] * bioxel_size, meta['spacing'][1] / orig_spacing[1] * bioxel_size,
image_spacing[2] / orig_spacing[2] * bioxel_size meta['spacing'][2] / orig_spacing[2] * bioxel_size
) )
bioxels_shape = get_bioxels_shape( layer_shape = get_layer_shape(
bioxel_size, image_shape, orig_spacing) bioxel_size, meta['shape'], orig_spacing)
if self.read_as == "labels":
if "vector" in image.GetPixelIDTypeAsString():
print("Convet to Grayscale...")
image = x2gray(image)
else:
image = sitk.Cast(image, sitk.sitkUInt16)
default_value = 0
elif self.read_as == "scalar":
if "vector" in image.GetPixelIDTypeAsString():
print("Convet to Grayscale...")
image = rgb2gray(image)
else:
image = sitk.Cast(image, sitk.sitkFloat32)
stats = sitk.StatisticsImageFilter()
stats.Execute(image)
default_value = stats.GetMaximum() if self.invert_scalar else stats.GetMinimum()
if self.resample_method == "linear":
interpolator = sitk.sitkLinear
elif self.resample_method == "nearest_neighbor":
interpolator = sitk.sitkNearestNeighbor
elif self.resample_method == "gaussian":
interpolator = sitk.sitkGaussian
print(f"Resampling...")
image = sitk.Resample(
image1=image,
size=bioxels_shape,
transform=sitk.Transform(),
interpolator=interpolator,
outputOrigin=image.GetOrigin(),
outputSpacing=bioxels_spacing,
outputDirection=image.GetDirection(),
defaultPixelValue=default_value,
outputPixelType=image.GetPixelID(),
)
if self.do_orient:
print("Orienting to RAS...")
image = sitk.DICOMOrient(image, 'RAS')
print("Oriented Origin:", image.GetOrigin())
print("Oriented Direction:", image.GetDirection())
# return {'FINISHED'}
# ITK indices, by convention, are [i,j,k] while NumPy indices are [k,j,i]
# https://www.slicer.org/wiki/Coordinate_systems
# ITK Numpy 3D
# R (ight) i -> k -> x
# A (nterior) j -> j -> y
# S (uperior) k -> i -> z
array = sitk.GetArrayFromImage(image)
orig_dtype = str(array.dtype)
# print(f"Coverting Dtype from {orig_dtype} to float...")
# array = array.astype(float)
if array.ndim == 4:
# if array.shape[0] == 3 and self.read_as == "scalar":
# # RGB -> Grayscale
# array = np.dot(array[..., :3], [0.2989, 0.5870, 0.1140])
# else:
# array = array[:, :, :, 0]
array = array[:, :, :, 0]
array = np.transpose(array)
bioxels_shape = array.shape
bioxels_offset = 0.0
if self.read_as == "labels":
array = array == np.full_like(array, self.label_index)
bioxels_default_threshold = 1.0
bioxels_max = 1.0
bioxels_min = 0.0
bioxels_name = f"{bioxels_name}_{self.label_index}"
else:
if self.invert_scalar:
array = -array
orig_max = float(np.max(array))
orig_min = float(np.min(array))
orig_median = float(np.median(array))
orig_percentile80 = float(np.percentile(array, 80)) \
if self.invert_scalar else float(np.percentile(array, 80))
# if (orig_dtype[0] != "u" and orig_min < 0) \
# or (orig_dtype[0] == "u" and self.invert_scalar):
if orig_min < 0:
bioxels_offset = -orig_min
array = array + np.full_like(array, bioxels_offset)
bioxels_default_threshold = orig_percentile80
bioxels_max = float(np.max(array))
bioxels_min = float(np.min(array))
stats_table = [("Max", orig_max),
("Min", orig_min),
("Median", orig_median),
("80%", orig_percentile80)]
print("Bioxels Value Stats:")
for stats in stats_table:
print("| {: >10} | {: >40} |".format(*stats))
# # Build VDB
grid = vdb.BoolGrid() if self.read_as == "labels" else vdb.FloatGrid()
grid.copyFromArray(array.copy().astype(float))
# After sitk.DICOMOrient(), origin and direction will also orient base on LPS # After sitk.DICOMOrient(), origin and direction will also orient base on LPS
# so we need to convert them into RAS # so we need to convert them into RAS
@@ -347,46 +245,25 @@ class ImportVolumeDataDialog(bpy.types.Operator):
to_up='Y' to_up='Y'
).to_4x4() ).to_4x4()
origin = image.GetOrigin()
direction = image.GetDirection()
mat_location = mathutils.Matrix.Translation( mat_location = mathutils.Matrix.Translation(
mathutils.Vector(origin) mathutils.Vector(meta['origin'])
) )
mat_rotation = mathutils.Matrix( mat_rotation = mathutils.Matrix(
np.array(direction).reshape((3, 3)) np.array(meta['direction']).reshape((3, 3))
).to_4x4() ).to_4x4()
mat_scale = mathutils.Matrix.Scale( mat_scale = mathutils.Matrix.Scale(
bioxel_size, 4 bioxel_size, 4
) )
transfrom = mat_lps2ras @ mat_location @ mat_rotation @ mat_scale \ # transfrom = mat_lps2ras @ mat_location @ mat_rotation @ mat_scale \
if self.do_orient else mat_location @ mat_rotation @ mat_scale # if self.do_orient else mat_location @ mat_rotation @ mat_scale
grid.transform = vdb.createLinearTransform(transfrom.transposed()) transfrom = mat_lps2ras @ mat_location @ mat_rotation @ mat_scale
grid.name = "scalar"
preferences = context.preferences.addons[__package__].preferences
vdb_dirpath = Path(preferences.cache_dir, 'VDBs')
vdb_dirpath.mkdir(parents=True, exist_ok=True)
vdb_path = Path(vdb_dirpath, f"{uuid4()}.vdb")
print(f"Storing the VDB file ({str(vdb_path)})...")
vdb.write(str(vdb_path), grids=[grid])
# Read VDB
print(f"Importing the VDB file to Blender scene...")
bpy.ops.object.volume_import(
filepath=str(vdb_path), align='WORLD', location=(0, 0, 0), scale=(1, 1, 1))
bioxels_obj = bpy.context.active_object
# Set props to VDB object
bioxels_obj.name = f"{bioxels_name}_Bioxels"
bioxels_obj.data.name = f"{bioxels_name}_Bioxels"
# Wrapper a Container
if not self.container:
# Make transformation # Make transformation
scene_scale = float(self.scene_scale) scene_scale = float(self.scene_scale)
@@ -403,118 +280,253 @@ class ImportVolumeDataDialog(bpy.types.Operator):
scene_scale, 4 scene_scale, 4
) )
bioxels_obj.matrix_world = mat_ras2blender @ mat_scene_scale
bioxels_obj.lock_location[0] = True
bioxels_obj.lock_location[1] = True
bioxels_obj.lock_location[2] = True
bioxels_obj.lock_rotation[0] = True
bioxels_obj.lock_rotation[1] = True
bioxels_obj.lock_rotation[2] = True
bioxels_obj.lock_scale[0] = True
bioxels_obj.lock_scale[1] = True
bioxels_obj.lock_scale[2] = True
bioxels_obj.hide_select = True
bioxels_obj['bioxels'] = True
bpy.ops.node.new_geometry_nodes_modifier()
node_tree = bioxels_obj.modifiers[0].node_group
# Wrapper a Container
bpy.ops.mesh.primitive_cube_add( bpy.ops.mesh.primitive_cube_add(
enter_editmode=False, align='WORLD', location=(0, 0, 0), scale=(1, 1, 1) enter_editmode=False, align='WORLD', location=(0, 0, 0), scale=(1, 1, 1)
) )
container_obj = bpy.context.active_object container = bpy.context.active_object
bbox_verts = calc_bbox_verts((0, 0, 0), bioxels_shape)
for index, vert in enumerate(container_obj.data.vertices): bbox_verts = calc_bbox_verts((0, 0, 0), volume.shape)
bbox_transform = mat_ras2blender @ mat_scene_scale @ transfrom for index, vert in enumerate(container.data.vertices):
bbox_transform = transfrom
vert.co = bbox_transform @ mathutils.Vector(bbox_verts[index]) vert.co = bbox_transform @ mathutils.Vector(bbox_verts[index])
bioxels_obj.parent = container_obj container.matrix_world = mat_ras2blender @ mat_scene_scale
container_obj.name = bioxels_name container.name = container_name
container_obj.data.name = bioxels_name container.data.name = container_name
container_obj.visible_camera = False
container_obj.visible_diffuse = False
container_obj.visible_glossy = False
container_obj.visible_transmission = False
container_obj.visible_volume_scatter = False
container_obj.visible_shadow = False
container_obj.display_type = 'WIRE'
container_obj['bioxels_container'] = True
container_obj['scene_scale'] = scene_scale
container_obj['bioxel_size'] = bioxel_size
container_obj['bioxels_max'] = bioxels_max
container_obj['bioxels_min'] = bioxels_min
container_obj['bioxels_offset'] = bioxels_offset
container_obj['bioxels_shape'] = bioxels_shape
bpy.ops.object.modifier_add(type='NODES') container['bioxel_container'] = True
container_obj.modifiers[0].node_group = node_tree container['scene_scale'] = scene_scale
container_obj.modifiers[0].show_in_editmode = False bpy.ops.node.new_geometry_nodes_modifier()
container_obj.modifiers[0].show_viewport = False container_node_tree = container.modifiers[0].node_group
container_obj.modifiers[0].show_render = False input_node = get_node_by_type(container_node_tree.nodes,
'NodeGroupInput')[0]
container_node_tree.links.remove(input_node.outputs[0].links[0])
# Create BioxelNodes to VDB object else:
print(f"Creating BioxelNodes to the VDB...") container = bpy.data.objects[self.container]
container_node_tree = container.modifiers[0].node_group
if preferences.do_add_segmentnode: preferences = context.preferences.addons[__package__].preferences
loc, rot, sca = transfrom.decompose()
layer_origin = tuple(loc)
layer_rotation = tuple(rot.to_euler())
def create_layer(volume, layer_name, layer_type="scalar"):
grid = vdb.FloatGrid()
volume = volume.copy().astype(np.float32)
grid.copyFromArray(volume)
grid.transform = vdb.createLinearTransform(transfrom.transposed())
grid.name = layer_type
vdb_path = save_vdb([grid], context)
# Read VDB
print(f"Loading the cache to Blender scene...")
bpy.ops.object.volume_import(
filepath=str(vdb_path), align='WORLD', location=(0, 0, 0), scale=(1, 1, 1))
layer = bpy.context.active_object
# Set props to VDB object
layer.name = layer_name
layer.data.name = layer_name
lock_transform(layer)
hide_in_ray(layer)
layer.hide_select = True
layer.hide_render = True
layer.hide_viewport = True
layer.data.display.use_slice = True
layer.data.display.density = 1e-05
layer['bioxel_layer'] = True
layer['bioxel_layer_type'] = layer_type
layer.parent = container
for collection in layer.users_collection:
collection.objects.unlink(layer)
for collection in container.users_collection:
collection.objects.link(layer)
print(f"Creating layer ...")
bpy.ops.node.new_geometry_nodes_modifier()
node_tree = layer.modifiers[0].node_group
nodes = node_tree.nodes nodes = node_tree.nodes
links = node_tree.links links = node_tree.links
input_node = get_node_by_type(nodes, 'NodeGroupInput')[0] input_node = get_node_by_type(nodes, 'NodeGroupInput')[0]
output_node = get_node_by_type(nodes, 'NodeGroupOutput')[0] output_node = get_node_by_type(nodes, 'NodeGroupOutput')[0]
segment_node = custom_nodes.add_node( to_layer_node = custom_nodes.add_node(nodes,
nodes, 'BioxelNodes_Segment') "BioxelNodes__ConvertToLayer")
segment_node.inputs['Threshold'].default_value = bioxels_default_threshold links.new(input_node.outputs[0], to_layer_node.inputs[0])
links.new(to_layer_node.outputs[0], output_node.inputs[0])
links.new(input_node.outputs[0], segment_node.inputs[0]) to_layer_node.inputs['Layer ID'].default_value = random.randint(-200000000,
links.new(segment_node.outputs[0], output_node.inputs[0]) 200000000)
to_layer_node.inputs['Bioxel Size'].default_value = bioxel_size
to_layer_node.inputs['Shape'].default_value = layer_shape
to_layer_node.inputs['Origin'].default_value = layer_origin
to_layer_node.inputs['Rotation'].default_value = layer_rotation
return layer
if self.read_as == "labels":
if volume.ndim == 4:
volume = np.amax(volume, -1)
volume = volume.astype(int)
orig_max = int(np.max(volume))
orig_min = int(np.min(volume))
layer_name = self.layer_name or "Label"
for i in range(orig_max):
label = volume == np.full_like(volume, i+1)
print(f"Resampling...")
label = ski.resize(label.astype(np.float32),
layer_shape,
anti_aliasing=True)
layer = create_layer(volume=label,
layer_name=f"{container_name}_{layer_name}_{i+1}",
layer_type="label")
# Deselect all nodes first
for node in container_node_tree.nodes:
if node.select:
node.select = False
mask_node = custom_nodes.add_node(container_node_tree.nodes,
'BioxelNodes_MaskByLabel')
mask_node.label = f"{layer_name}_{i+1}"
mask_node.inputs[0].default_value = layer
# Connect to output if no output linked
output_node = get_node_by_type(container_node_tree.nodes,
'NodeGroupOutput')[0]
if len(output_node.inputs[0].links) == 0:
container_node_tree.links.new(mask_node.outputs[0],
output_node.inputs[0])
else:
if volume.ndim == 4:
volume = np.amax(volume, -1)
# volume = skimage.color.rgb2gray(volume)
# if volume.dtype.kind == 'u':
# imax_in = np.iinfo(volume.dtype).max
# volume = np.multiply(volume, 255.0 / imax_in, dtype=np.float32)
# elif volume.dtype.kind == 'i':
# volume = volume.astype(np.float32)
# should not change any value!
volume = volume.astype(np.float32)
print(f"Resampling...")
volume = ski.resize(volume,
layer_shape,
anti_aliasing=True)
orig_max = float(np.max(volume))
orig_min = float(np.min(volume))
scalar_offset = 0
if orig_min < 0:
scalar_offset = -orig_min
volume = volume + np.full_like(volume, scalar_offset)
layer_name = self.layer_name or "Scalar"
layer = create_layer(volume=volume,
layer_name=f"{container_name}_{layer_name}",
layer_type="scalar")
layer_node_tree = layer.modifiers[0].node_group
to_layer_node = layer_node_tree.nodes['BioxelNodes__ConvertToLayer']
to_layer_node.inputs['Scalar Offset'].default_value = scalar_offset
to_layer_node.inputs['Scalar Max'].default_value = orig_max
to_layer_node.inputs['Scalar Min'].default_value = orig_min
# Deselect all nodes first
for node in container_node_tree.nodes:
if node.select:
node.select = False
mask_node = custom_nodes.add_node(container_node_tree.nodes,
'BioxelNodes_MaskByThreshold')
mask_node.label = layer_name
mask_node.inputs[0].default_value = layer
# Connect to output if no output linked
output_node = get_node_by_type(container_node_tree.nodes,
'NodeGroupOutput')[0]
if len(output_node.inputs[0].links) == 0:
container_node_tree.links.new(mask_node.outputs[0],
output_node.inputs[0])
bpy.context.view_layer.objects.active = container
# Change render setting for better result # Change render setting for better result
if preferences.do_change_render_setting: if preferences.do_change_render_setting and is_first_import:
bpy.context.scene.render.engine = 'CYCLES' bpy.context.scene.render.engine = 'CYCLES'
try:
bpy.context.scene.cycles.volume_bounces = 12 bpy.context.scene.cycles.volume_bounces = 12
bpy.context.scene.cycles.transparent_max_bounces = 64 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
bpy.context.scene.eevee.volumetric_tile_size = '2'
bpy.context.scene.eevee.volumetric_shadow_samples = 128
bpy.context.scene.eevee.volumetric_samples = 256
except:
pass
self.report({"INFO"}, "Successfully Imported") self.report({"INFO"}, "Successfully Imported")
return {'FINISHED'} return {'FINISHED'}
def invoke(self, context, event): def invoke(self, context, event):
min_size = min( if self.read_as == "labels":
self.orig_spacing[0], self.orig_spacing[1], self.orig_spacing[2]) volume_dtype = "Label"
default_size = 1.0 elif self.read_as == "scalar":
self.bioxel_size = min_size if min_size > default_size else default_size volume_dtype = "Scalar"
context.window_manager.invoke_props_dialog(self, width=400) title = f"Import '{volume_dtype}' Layer (Add to Container: {self.container})" \
if self.container != "" else f"Import '{volume_dtype}' Layer (Init a Container)"
context.window_manager.invoke_props_dialog(self,
width=500,
title=title)
return {'RUNNING_MODAL'} return {'RUNNING_MODAL'}
def draw(self, context): def draw(self, context):
layout = self.layout layer_shape = get_layer_shape(self.bioxel_size,
bioxels_shape = get_bioxels_shape( self.orig_shape,
self.bioxel_size, self.orig_shape, self.orig_spacing) self.orig_spacing)
bioxel_count = bioxels_shape[0] * bioxels_shape[1] * bioxels_shape[2] layer_size = get_layer_size(layer_shape,
text = f"Shape will be: {str(bioxels_shape)} {bioxel_count:,} " self.bioxel_size,
self.scene_scale)
bioxel_count = layer_shape[0] * layer_shape[1] * layer_shape[2]
layer_shape_text = f"Shape will be: {str(layer_shape)} {bioxel_count:,} "
if bioxel_count > 100000000: if bioxel_count > 100000000:
text += "**TOO LARGE!**" layer_shape_text += "**TOO LARGE!**"
layer_size_text = f"Size will be: ({layer_size[0]:.2f}, {layer_size[1]:.2f}, {layer_size[2]:.2f}) m"
layout = self.layout
panel = layout.box()
if self.container == "":
panel.prop(self, "container_name")
panel.prop(self, "layer_name")
panel = layout.box() panel = layout.box()
panel.prop(self, "resample_method")
panel.prop(self, "bioxel_size") panel.prop(self, "bioxel_size")
row = panel.row() row = panel.row()
row.prop(self, "orig_spacing") row.prop(self, "orig_spacing")
panel.label(text=text) panel.label(text=layer_shape_text)
panel = layout.box()
panel.prop(self, "read_as")
if self.read_as == "labels":
panel.prop(self, "label_index")
else:
panel.prop(self, "invert_scalar")
if self.container == "":
panel = layout.box() panel = layout.box()
panel.prop(self, "scene_scale") panel.prop(self, "scene_scale")
panel.prop(self, "do_orient") panel.label(text=layer_size_text)
def get_series_ids(self, context): def get_series_ids(self, context):
@@ -530,14 +542,22 @@ def get_series_ids(self, context):
return items return items
class ReadDICOM(bpy.types.Operator): class ParseVolumeData(bpy.types.Operator):
bl_idname = "bioxelnodes.read_dicom" bl_idname = "bioxelnodes.parse_volume_data"
bl_label = "Volume Data as Bioxels" bl_label = "Volume Data as Bioxel Layer"
bl_description = "Import Volume Data as Bioxels (VDB)" bl_description = "Import Volume Data as Bioxel Layer"
bl_options = {'UNDO'} bl_options = {'UNDO'}
filepath: bpy.props.StringProperty(subtype="FILE_PATH") # type: ignore filepath: bpy.props.StringProperty(subtype="FILE_PATH") # type: ignore
directory: bpy.props.StringProperty(subtype='DIR_PATH') # type: ignore directory: bpy.props.StringProperty(subtype='DIR_PATH') # type: ignore
container: bpy.props.StringProperty() # type: ignore
read_as: bpy.props.EnumProperty(
name="Read as",
default="scalar",
items=[("scalar", "Scalar", ""),
("labels", "Labels", "")]
) # type: ignore
series_id: bpy.props.EnumProperty( series_id: bpy.props.EnumProperty(
name="Select Series", name="Select Series",
@@ -554,26 +574,37 @@ class ReadDICOM(bpy.types.Operator):
return {'CANCELLED'} return {'CANCELLED'}
print("Collecting Meta Data...") print("Collecting Meta Data...")
image, name = read_image(self.filepath, self.series_id) volume, meta = parse_volume_data(self.filepath)
stats_table = [("Shape", str(image.GetSize())),
("Spacing", str(image.GetSpacing())),
("Origin", str(image.GetOrigin())),
("Direction", str(image.GetDirection())),
("Data Type", image.GetPixelIDTypeAsString())]
print("Meta Data:")
for stats in stats_table:
print("| {: >10} | {: >40} |".format(*stats))
do_orient = ext not in SEQUENCE_EXTS or ext in DICOM_EXTS do_orient = ext not in SEQUENCE_EXTS or ext in DICOM_EXTS
orig_shape = meta['shape']
orig_spacing = meta['spacing']
min_size = min(orig_spacing[0], orig_spacing[1], orig_spacing[2])
bioxel_size = max(min_size, 1.0)
layer_size = get_layer_size(orig_shape,
bioxel_size)
log10 = math.floor(math.log10(max(*layer_size)))
scene_scale = math.pow(10, -log10)
if self.container:
container = bpy.data.objects[self.container]
container_name = container.name
else:
container_name = meta['name']
bpy.ops.bioxelnodes.import_volume_data_dialog( bpy.ops.bioxelnodes.import_volume_data_dialog(
'INVOKE_DEFAULT', 'INVOKE_DEFAULT',
filepath=self.filepath, filepath=self.filepath,
orig_shape=image.GetSize(), container_name=container_name,
orig_spacing=image.GetSpacing(), orig_shape=orig_shape,
orig_spacing=orig_spacing,
bioxel_size=bioxel_size,
series_id=self.series_id or "", series_id=self.series_id or "",
do_orient=do_orient do_orient=do_orient,
container=self.container,
read_as=self.read_as,
scene_scale=scene_scale
) )
self.report({"INFO"}, "Successfully Readed.") self.report({"INFO"}, "Successfully Readed.")
@@ -621,21 +652,32 @@ class ReadDICOM(bpy.types.Operator):
text="Please be patient...") text="Please be patient...")
class ImportVolumeData(bpy.types.Operator): class ImportVolumeData():
bl_idname = "bioxelnodes.import_volume_data"
bl_label = "Volume Data as Bioxels"
bl_description = "Import Volume Data as Bioxels (VDB)"
bl_options = {'UNDO'} bl_options = {'UNDO'}
filepath: bpy.props.StringProperty(subtype="FILE_PATH") # type: ignore filepath: bpy.props.StringProperty(subtype="FILE_PATH") # type: ignore
directory: bpy.props.StringProperty(subtype='DIR_PATH') # type: ignore directory: bpy.props.StringProperty(subtype='DIR_PATH') # type: ignore
read_as = "scalar"
def execute(self, context): def execute(self, context):
bpy.ops.bioxelnodes.read_dicom( containers = get_container_from_selection()
if len(containers) > 0:
bpy.ops.bioxelnodes.parse_volume_data(
'INVOKE_DEFAULT',
filepath=self.filepath,
directory=self.directory,
container=containers[0].name,
read_as=self.read_as
)
else:
bpy.ops.bioxelnodes.parse_volume_data(
'INVOKE_DEFAULT', 'INVOKE_DEFAULT',
filepath=self.filepath, filepath=self.filepath,
directory=self.directory directory=self.directory
) )
return {'FINISHED'} return {'FINISHED'}
def invoke(self, context, event): def invoke(self, context, event):
@@ -643,11 +685,25 @@ class ImportVolumeData(bpy.types.Operator):
return {'RUNNING_MODAL'} return {'RUNNING_MODAL'}
class ImportAsScalarLayer(bpy.types.Operator, ImportVolumeData):
bl_idname = "bioxelnodes.import_as_scalar_layer"
bl_label = "Import as Scalar"
bl_description = "Import Volume Data to Container as Scalar"
read_as = "scalar"
class ImportAsLabelLayer(bpy.types.Operator, ImportVolumeData):
bl_idname = "bioxelnodes.import_as_label_layer"
bl_label = "Import as Labels"
bl_description = "Import Volume Data to Container as Label"
read_as = "labels"
try: try:
class BIOXELNODES_FH_ImportVolumeData(bpy.types.FileHandler): class BIOXELNODES_FH_ImportVolumeData(bpy.types.FileHandler):
bl_idname = "BIOXELNODES_FH_ImportVolumeData" bl_idname = "BIOXELNODES_FH_ImportVolumeData"
bl_label = "File handler for dicom import" bl_label = "File handler for dicom import"
bl_import_operator = "bioxelnodes.read_dicom" bl_import_operator = "bioxelnodes.parse_volume_data"
bl_file_extensions = ";".join(FH_EXTS) bl_file_extensions = ";".join(FH_EXTS)
@classmethod @classmethod
@@ -657,10 +713,40 @@ except:
... ...
class ExportVDB(bpy.types.Operator): class AddVolumeData(bpy.types.Operator):
bl_idname = "bioxelnodes.export_vdb" bl_idname = "bioxelnodes.add_volume_data"
bl_label = "Bioxels as VDB" bl_label = "Import as Bioxel Layer"
bl_description = "Export Bioxels original VDB data" bl_description = "Import additional Volume Data to Container"
bl_options = {'UNDO'}
filepath: bpy.props.StringProperty(subtype="FILE_PATH") # type: ignore
directory: bpy.props.StringProperty(subtype='DIR_PATH') # type: ignore
@classmethod
def poll(cls, context):
containers = get_container_from_selection()
return len(containers) > 0
def execute(self, context):
containers = get_container_from_selection()
bpy.ops.bioxelnodes.parse_volume_data(
'INVOKE_DEFAULT',
filepath=self.filepath,
directory=self.directory,
container=containers[0].name
)
return {'FINISHED'}
def invoke(self, context, event):
context.window_manager.fileselect_add(self)
return {'RUNNING_MODAL'}
class ExportVolumeData(bpy.types.Operator):
bl_idname = "bioxelnodes.export_volume_data"
bl_label = "Export Layer"
bl_description = "Export Bioxel Layer as VDB"
bl_options = {'UNDO'} bl_options = {'UNDO'}
filepath: bpy.props.StringProperty( filepath: bpy.props.StringProperty(
@@ -671,26 +757,19 @@ class ExportVDB(bpy.types.Operator):
@classmethod @classmethod
def poll(cls, context): def poll(cls, context):
bioxels_obj = None layer = get_layer(bpy.context.active_object)
for obj in bpy.context.selected_objects: return True if layer else False
bioxels_obj = get_bioxels_obj(obj)
break
return True if bioxels_obj else False
def invoke(self, context, event): def invoke(self, context, event):
context.window_manager.fileselect_add(self) context.window_manager.fileselect_add(self)
return {'RUNNING_MODAL'} return {'RUNNING_MODAL'}
def execute(self, context): def execute(self, context):
bioxels_obj = None layer = get_layer(bpy.context.active_object)
for obj in bpy.context.selected_objects:
bioxels_obj = get_bioxels_obj(obj)
break
filepath = f"{self.filepath.split('.')[0]}.vdb" filepath = f"{self.filepath.split('.')[0]}.vdb"
# "//" # "//"
source_dir = bpy.path.abspath(bioxels_obj.data.filepath) source_dir = bpy.path.abspath(layer.data.filepath)
output_path: Path = Path(filepath).resolve() output_path: Path = Path(filepath).resolve()
source_path: Path = Path(source_dir).resolve() source_path: Path = Path(source_dir).resolve()

View File

@@ -23,199 +23,3 @@ def create_points_obj(points, name="points"):
bm.to_mesh(mesh) bm.to_mesh(mesh)
bm.free() # always do this when finished bm.free() # always do this when finished
return obj return obj
# class ImportDICOMPointsDialog(bpy.types.Operator):
# bl_idname = "bioxelnodes.import_dicom_points_dialog"
# bl_label = "Volume Data as Bioxels"
# bl_description = "Import Volume Data as Bioxels (VDB)"
# bl_options = {'UNDO'}
# filepath: bpy.props.StringProperty(
# subtype="FILE_PATH",
# options={'HIDDEN'}
# ) # type: ignore
# bioxels_shape: bpy.props.IntVectorProperty(
# name="Bioxels Shape (ReadOnly)",
# min=0,
# default=(100, 100, 100)
# ) # type: ignore
# bioxel_size: bpy.props.FloatProperty(
# name="Bioxel Size",
# soft_min=0.1, soft_max=10.0,
# min=1e-2, max=1e2,
# default=1,
# update=on_bioxel_size_changed
# ) # type: ignore
# orig_spacing: bpy.props.FloatVectorProperty(
# name="Original Spacing",
# default=(1, 1, 1),
# update=on_orig_spacing_changed
# ) # type: ignore
# orig_shape: bpy.props.IntVectorProperty(
# name="Original Shape",
# default=(100, 100, 100),
# options={'HIDDEN'}
# ) # type: ignore
# auto: bpy.props.BoolProperty(
# name="Auto Setting",
# default=False,
# options={'HIDDEN'}
# ) # type: ignore
# scene_scale: bpy.props.FloatProperty(
# name="Scene Scale",
# soft_min=0.001, soft_max=100.0,
# min=1e-6, max=1e6,
# default=0.01,
# ) # type: ignore
# do_add_segmentnode: bpy.props.BoolProperty(
# name="Add Segment Node",
# default=True,
# ) # type: ignore
# do_change_render_setting: bpy.props.BoolProperty(
# name="Change Render Setting",
# default=True,
# ) # type: ignore
# def execute(self, context):
# files = get_data_files(self.filepath)
# name = Path(self.filepath).parent.name
# image = sitk.ReadImage(files)
# bioxel_size = float(self.bioxel_size)
# orig_spacing = tuple(self.orig_spacing)
# image_spacing = image.GetSpacing()
# image_shape = image.GetSize()
# bioxels_spacing = (
# image_spacing[0] / orig_spacing[0] * bioxel_size,
# image_spacing[1] / orig_spacing[1] * bioxel_size,
# image_spacing[2] / orig_spacing[2] * bioxel_size
# )
# bioxels_shape = (
# int(image_shape[0] / bioxel_size * orig_spacing[0]),
# int(image_shape[1] / bioxel_size * orig_spacing[1]),
# int(image_shape[2] / bioxel_size * orig_spacing[2]),
# )
# print("Resampling...")
# image = sitk.Resample(
# image1=image,
# size=bioxels_shape,
# transform=sitk.Transform(),
# interpolator=sitk.sitkLinear,
# outputOrigin=image.GetOrigin(),
# outputSpacing=bioxels_spacing,
# outputDirection=image.GetDirection(),
# defaultPixelValue=0,
# outputPixelType=image.GetPixelID(),
# )
# print("Orienting to RAS...")
# image = sitk.DICOMOrient(image, 'RAS')
# array = sitk.GetArrayFromImage(image)
# orig_dtype = str(array.dtype)
# print(f"Coverting Dtype from {orig_dtype} to float...")
# array = array.astype(float)
# # ITK indices, by convention, are [i,j,k] while NumPy indices are [k,j,i]
# # https://www.slicer.org/wiki/Coordinate_systems
# # ITK Numpy 3D
# # R (ight) i -> k -> x
# # A (nterior) j -> j -> y
# # S (uperior) k -> i -> z
# array = np.transpose(array)
# bioxels_max = float(np.max(array))
# bioxels_min = float(np.min(array))
# bioxels_shape = array.shape
# print("Bioxel Size:", bioxel_size)
# print("Bioxels Shape:", bioxels_shape)
# bioxels_offset = 0.0
# if bioxels_min < 0 and orig_dtype[0] != "u":
# bioxels_offset = -bioxels_min
# array = array + np.full_like(array, bioxels_offset)
# bioxels_max = float(np.max(array))
# bioxels_min = float(np.min(array))
# print("Offseted Max:", bioxels_max)
# print("Offseted Min:", bioxels_min)
# points = []
# for x in range(array.shape[0]):
# for y in range(array.shape[1]):
# for z in range(array.shape[2]):
# points.append({
# "pos": (x, y, z),
# "value": array[x, y, z],
# })
# # # Build VDB
# # grid = vdb.FloatGrid()
# # grid.copyFromArray(array.copy())
# # # After sitk.DICOMOrient(), origin and direction will also orient base on LPS
# # # so we need to convert them into RAS
# # mat_lps2ras = axis_conversion(
# # from_forward='-Z',
# # from_up='-Y',
# # to_forward='-Z',
# # to_up='Y'
# # ).to_4x4()
# # mat_location = mathutils.Matrix.Translation(
# # mathutils.Vector(image.GetOrigin())
# # )
# # mat_rotation = mathutils.Matrix(
# # np.array(image.GetDirection()).reshape((3, 3))
# # ).to_4x4()
# # mat_scale = mathutils.Matrix.Scale(
# # bioxel_size, 4
# # )
# # transfrom = mat_lps2ras @ mat_location @ mat_rotation @ mat_scale
# obj = create_points_obj(points)
# # Make transformation
# scene_scale = float(self.scene_scale)
# # (S)uperior -Z -> Y
# # (A)osterior Y -> Z
# mat_ras2blender = axis_conversion(
# from_forward='-Z',
# from_up='Y',
# to_forward='Y',
# to_up='Z'
# ).to_4x4()
# mat_scene_scale = mathutils.Matrix.Scale(
# scene_scale, 4
# )
# obj.matrix_world = mat_ras2blender @ mat_scene_scale
# self.report({"INFO"}, "Successfully Imported")
# return {'FINISHED'}
# def invoke(self, context, event):
# # print(tuple(self.orig_shape))
# self.auto = True
# self.bioxel_size = 1
# context.window_manager.invoke_props_dialog(self)
# return {'RUNNING_MODAL'}

View File

@@ -1,45 +1,128 @@
import bpy import bpy
from .convert import ConvertToMesh from .operators import (AddPlaneCutter, AddCylinderCutter, AddCubeCutter, AddSphereCutter, CombineLabels,
from .io import ExportVDB, ImportVolumeData ConvertToMesh, InvertScalar, FillByLabel, FillByThreshold, FillByRange)
from .misc import SaveBioxels from .io import ExportVolumeData, ImportAsLabelLayer, ImportAsScalarLayer, ImportVolumeData, AddVolumeData
from .misc import SaveLayers
class ObjectMenu(bpy.types.Menu): class ModifyLayer(bpy.types.Menu):
bl_idname = "BIOXELNODES_MT_OBJECT" bl_idname = "BIOXELNODES_MT_MODIFY_LAYERS"
bl_label = "Bioxels" bl_label = "Modify Layer"
def draw(self, context): def draw(self, context):
layout = self.layout layout = self.layout
layout.operator(InvertScalar.bl_idname)
layout.operator(FillByThreshold.bl_idname)
layout.operator(FillByRange.bl_idname)
layout.operator(FillByLabel.bl_idname)
layout.operator(CombineLabels.bl_idname)
class AddCutterMenu(bpy.types.Menu):
bl_idname = "BIOXELNODES_MT_CUTTERS"
bl_label = "Add Cutter"
def draw(self, context):
layout = self.layout
layout.operator(AddPlaneCutter.bl_idname)
layout.operator(AddCylinderCutter.bl_idname)
layout.operator(AddCubeCutter.bl_idname)
layout.operator(AddSphereCutter.bl_idname)
class ImportLayerMenu(bpy.types.Menu):
bl_idname = "BIOXELNODES_MT_LAYERS"
bl_label = "Import Layer"
def draw(self, context):
layout = self.layout
layout.operator(ImportAsScalarLayer.bl_idname)
layout.operator(ImportAsLabelLayer.bl_idname)
class BioxelNodesView3DMenu(bpy.types.Menu):
bl_idname = "BIOXELNODES_MT_VIEW3D"
bl_label = "Bioxel Nodes"
def draw(self, context):
layout = self.layout
layout.menu(ImportLayerMenu.bl_idname)
layout.menu(AddCutterMenu.bl_idname)
layout.operator(ConvertToMesh.bl_idname) layout.operator(ConvertToMesh.bl_idname)
layout.separator() layout.separator()
layout.operator(SaveBioxels.bl_idname) layout.operator(SaveLayers.bl_idname)
def TOPBAR_FILE_IMPORT(self, context): class BioxelNodesOutlinerMenu(bpy.types.Menu):
bl_idname = "BIOXELNODES_MT_OUTLINER"
bl_label = "Bioxel Nodes"
def draw(self, context):
layout = self.layout layout = self.layout
layout.menu(ImportLayerMenu.bl_idname)
layout.menu(AddCutterMenu.bl_idname)
layout.operator(ConvertToMesh.bl_idname)
layout.separator() layout.separator()
layout.operator(ImportVolumeData.bl_idname) layout.menu(ModifyLayer.bl_idname)
layout.separator()
layout.operator(SaveLayers.bl_idname)
def TOPBAR_FILE_EXPORT(self, context): # def TOPBAR_FILE_IMPORT(self, context):
layout = self.layout # layout = self.layout
layout.separator() # layout.separator()
layout.operator(ExportVDB.bl_idname) # layout.operator(ImportVolumeData.bl_idname)
# def TOPBAR_FILE_EXPORT(self, context):
# layout = self.layout
# layout.separator()
# layout.operator(ExportVolumeData.bl_idname)
def VIEW3D_OBJECT(self, context): def VIEW3D_OBJECT(self, context):
layout = self.layout layout = self.layout
layout.menu(ObjectMenu.bl_idname) layout.menu(BioxelNodesView3DMenu.bl_idname)
layout.separator() layout.separator()
def OUTLINER_OBJECT(self, context):
layout = self.layout
layout.menu(BioxelNodesOutlinerMenu.bl_idname)
layout.separator()
class BioxelNodesTopbarMenu(bpy.types.Menu):
bl_idname = "BIOXELNODES_MT_TOPBAR"
bl_label = "Bioxel Nodes"
def draw(self, context):
layout = self.layout
layout.menu(ImportLayerMenu.bl_idname)
layout.operator(ExportVolumeData.bl_idname)
layout.separator()
layout.menu(AddCutterMenu.bl_idname)
layout.operator(ConvertToMesh.bl_idname)
layout.separator()
layout.operator(SaveLayers.bl_idname)
def TOPBAR(self, context):
layout = self.layout
layout.menu(BioxelNodesTopbarMenu.bl_idname)
def add(): def add():
bpy.types.TOPBAR_MT_file_import.append(TOPBAR_FILE_IMPORT) # bpy.types.TOPBAR_MT_file_import.append(TOPBAR_FILE_IMPORT)
bpy.types.TOPBAR_MT_file_export.append(TOPBAR_FILE_EXPORT) # bpy.types.TOPBAR_MT_file_export.append(TOPBAR_FILE_EXPORT)
bpy.types.OUTLINER_MT_object.prepend(OUTLINER_OBJECT)
bpy.types.VIEW3D_MT_object_context_menu.prepend(VIEW3D_OBJECT) bpy.types.VIEW3D_MT_object_context_menu.prepend(VIEW3D_OBJECT)
bpy.types.TOPBAR_MT_editor_menus.append(TOPBAR)
def remove(): def remove():
bpy.types.TOPBAR_MT_file_import.remove(TOPBAR_FILE_IMPORT) # bpy.types.TOPBAR_MT_file_import.remove(TOPBAR_FILE_IMPORT)
bpy.types.TOPBAR_MT_file_export.remove(TOPBAR_FILE_EXPORT) # bpy.types.TOPBAR_MT_file_export.remove(TOPBAR_FILE_EXPORT)
bpy.types.OUTLINER_MT_object.remove(OUTLINER_OBJECT)
bpy.types.VIEW3D_MT_object_context_menu.remove(VIEW3D_OBJECT) bpy.types.VIEW3D_MT_object_context_menu.remove(VIEW3D_OBJECT)
bpy.types.TOPBAR_MT_editor_menus.remove(TOPBAR)

View File

@@ -1,97 +1,86 @@
import bpy import bpy
from pathlib import Path from pathlib import Path
import shutil import shutil
from bioxelnodes.utils import get_all_bioxels_objs, get_bioxels_obj from .utils import get_all_layers, get_container, get_container_layers
class SaveBioxels(bpy.types.Operator): def save_layer(layer, output_dir):
bl_idname = "bioxelnodes.save_bioxels" name = layer.name
bl_label = "Save Bioxels"
bl_description = "Save Bioxels to Directory." # "//"
output_dir = bpy.path.abspath(output_dir)
source_dir = bpy.path.abspath(layer.data.filepath)
output_path: Path = Path(output_dir, f"{name}.vdb").resolve()
source_path: Path = Path(source_dir).resolve()
if output_path != source_path:
shutil.copy(source_path, output_path)
blend_path = Path(bpy.path.abspath("//")).resolve()
layer.data.filepath = bpy.path.relpath(
str(output_path), start=str(blend_path))
class SaveLayers(bpy.types.Operator):
bl_idname = "bioxelnodes.save_layers"
bl_label = "Save Layers"
bl_description = "Save Bioxel Layers to Directory."
bl_options = {'UNDO'} bl_options = {'UNDO'}
@classmethod @classmethod
def poll(cls, context): def poll(cls, context):
bioxels_obj = None container = get_container(bpy.context.active_object)
for obj in bpy.context.selected_objects: return True if container else False
bioxels_obj = get_bioxels_obj(obj)
break
return True if bioxels_obj else False
def execute(self, context): def execute(self, context):
bioxels_objs = [] container = get_container(bpy.context.active_object)
for obj in bpy.context.selected_objects: if not container:
bioxels_obj = get_bioxels_obj(obj) self.report({"WARNING"}, "Cannot find any bioxel container.")
if bioxels_obj:
bioxels_objs.append(bioxels_obj)
if len(bioxels_objs) == 0:
self.report({"WARNING"}, "Cannot find any bioxels.")
return {'FINISHED'} return {'FINISHED'}
for bioxels_obj in bioxels_objs: for layer in get_container_layers(container):
name = bioxels_obj.parent.name try:
save_layer(layer, context.scene.bioxel_layer_dir)
except:
self.report(
{"WARNING"}, f"Fail to save {layer.name}, skiped")
# "//" self.report({"INFO"}, f"Successfully saved bioxel layers.")
bioxels_dir = bpy.path.abspath(context.scene.bioxels_dir)
source_dir = bpy.path.abspath(bioxels_obj.data.filepath)
output_path: Path = Path(bioxels_dir, f"{name}.vdb").resolve()
source_path: Path = Path(source_dir).resolve()
if output_path != source_path:
shutil.copy(source_path, output_path)
blend_path = Path(bpy.path.abspath("//")).resolve()
bioxels_obj.data.filepath = bpy.path.relpath(
str(output_path), start=str(blend_path))
self.report({"INFO"}, f"Successfully saved bioxels")
return {'FINISHED'} return {'FINISHED'}
class SaveAllBioxels(bpy.types.Operator): class SaveAllLayers(bpy.types.Operator):
bl_idname = "bioxelnodes.save_all_bioxels" bl_idname = "bioxelnodes.save_all_layers"
bl_label = "Save All Bioxels" bl_label = "Save All Layers"
bl_description = "Save All Bioxels to Directory." bl_description = "Save All Bioxel Layers to Directory."
bl_options = {'UNDO'} bl_options = {'UNDO'}
def execute(self, context): def execute(self, context):
bioxels_objs = get_all_bioxels_objs() layers = get_all_layers()
if len(bioxels_objs) == 0: if len(layers) == 0:
self.report({"WARNING"}, "Cannot find any bioxels.") self.report({"WARNING"}, "Cannot find any bioxel layer.")
return {'FINISHED'} return {'FINISHED'}
for bioxels_obj in bioxels_objs: for layer in layers:
name = bioxels_obj.parent.name try:
save_layer(layer, context.scene.bioxel_layer_dir)
except:
self.report(
{"WARNING"}, f"Fail to save {layer.name}, skiped")
# "//" self.report({"INFO"}, f"Successfully saved bioxel layers.")
bioxels_dir = bpy.path.abspath(context.scene.bioxels_dir)
source_dir = bpy.path.abspath(bioxels_obj.data.filepath)
output_path: Path = Path(bioxels_dir, f"{name}.vdb").resolve()
source_path: Path = Path(source_dir).resolve()
if output_path != source_path:
shutil.copy(source_path, output_path)
blend_path = Path(bpy.path.abspath("//")).resolve()
bioxels_obj.data.filepath = bpy.path.relpath(
str(output_path), start=str(blend_path))
self.report({"INFO"}, f"Successfully saved bioxels")
return {'FINISHED'} return {'FINISHED'}
class BIOXELNODES_PT_Bioxels(bpy.types.Panel): class BIOXELNODES_PT_Bioxels(bpy.types.Panel):
bl_idname = "BIOXELNODES_PT_Bioxels" bl_idname = "BIOXELNODES_PT_Bioxels"
bl_label = "Bioxels" bl_label = "Bioxel Nodes"
bl_space_type = "PROPERTIES" bl_space_type = "PROPERTIES"
bl_region_type = "WINDOW" bl_region_type = "WINDOW"
bl_context = "scene" bl_context = "scene"
@@ -99,5 +88,5 @@ class BIOXELNODES_PT_Bioxels(bpy.types.Panel):
def draw(self, context): def draw(self, context):
layout = self.layout layout = self.layout
scene = context.scene scene = context.scene
layout.prop(scene, 'bioxels_dir') layout.prop(scene, 'bioxel_layer_dir')
layout.operator(SaveAllBioxels.bl_idname) layout.operator(SaveAllLayers.bl_idname)

View File

@@ -3,146 +3,386 @@ from pathlib import Path
from .customnodes import CustomNodes from .customnodes import CustomNodes
import bpy import bpy
# def set_object_to_node_factory(object_type:str):
def add_driver_to_node_factory(source_prop, target_prop): # if object_type == "plane":
callback_str = f""" # create_object = """
import bpy # bpy.ops.mesh.primitive_plane_add(size=2, enter_editmode=False, align='WORLD', location=(0, 0, 0), scale=(1, 1, 1))
from bioxelnodes.utils import add_direct_driver, get_bioxels_obj # """
bioxels_obj = get_bioxels_obj(bpy.context.active_object) # callback_str = f"""
if bioxels_obj: # import bpy
container_obj = bioxels_obj.parent # from ..utils import get_container
add_direct_driver( # container = get_container(bpy.context.active_object)
target=node, # if container:
target_prop='{target_prop}', # {create_object}
source=container_obj, # object = bpy.context.active_object
source_prop='{source_prop}' # node.inputs[0].default_value = object
) # else:
else: # print('Cannot find any Bioxel Container.')
print('Cannot find any bioxels.') # """
""" # return callback_str
return callback_str
def set_prop_to_node_factory(source_prop, target_prop): # def add_driver_to_node_factory(source_prop, target_prop):
callback_str = f""" # callback_str = f"""
import bpy # import bpy
from bioxelnodes.utils import get_bioxels_obj # from .utils import add_direct_driver, get_bioxels_obj
bioxels_obj = get_bioxels_obj(bpy.context.active_object) # bioxels_obj = get_bioxels_obj(bpy.context.active_object)
if bioxels_obj: # if bioxels_obj:
container_obj = bioxels_obj.parent # container_obj = bioxels_obj.parent
node.inputs.get('{target_prop}').default_value = container_obj.get( # add_direct_driver(
'{source_prop}') # target=node,
else: # target_prop='{target_prop}',
print('Cannot find any bioxels.') # source=container_obj,
""" # source_prop='{source_prop}'
return callback_str # )
# else:
# print('Cannot find any bioxels.')
# """
# return callback_str
# def set_prop_to_node_factory(source_prop, target_prop):
# callback_str = f"""
# import bpy
# from .utils import get_bioxels_obj
# bioxels_obj = get_bioxels_obj(bpy.context.active_object)
# if bioxels_obj:
# container_obj = bioxels_obj.parent
# node.inputs.get('{target_prop}').default_value = container_obj.get(
# '{source_prop}')
# else:
# print('Cannot find any bioxels.')
# """
# return callback_str
if bpy.app.version >= (4, 1, 0):
NODE_FILE = "BioxelNodes_4.1"
MENU_ITEMS = [ MENU_ITEMS = [
{ {
'label': 'Presets', 'label': 'Methods',
'icon': 'MESH_MONKEY',
'items': [
{
'label': 'Segment',
'icon': 'BONE_DATA',
'node_type': 'BioxelNodes_Segment',
'node_description': '',
'node_callback': "\n".join([
set_prop_to_node_factory("bioxel_size", "Detail Size"),
set_prop_to_node_factory("bioxels_offset", "Offset"),
])
}
# {
# 'label': 'Anatomy',
# 'icon': 'CONSTRAINT_BONE',
# 'node_type': 'BioxelNodes_Anatomy',
# 'node_description': '',
# 'node_callback': "\n".join([
# set_prop_to_node_factory("bioxel_size", "Detail Size"),
# set_prop_to_node_factory("bioxels_offset", "Offset"),
# ])
# }
]
},
{
'label': 'Segment',
'icon': 'OUTLINER_DATA_VOLUME', 'icon': 'OUTLINER_DATA_VOLUME',
'items': [ 'items': [
{ {
'label': 'Segment by Level', 'label': 'Mask by Threshold',
'icon': 'EMPTY_SINGLE_ARROW', 'icon': 'EMPTY_SINGLE_ARROW',
'node_type': 'BioxelNodes_SegmentByLevel', 'node_type': 'BioxelNodes_MaskByThreshold',
'node_description': '', 'node_description': ''
'node_callback': "\n".join([
set_prop_to_node_factory("bioxel_size", "Detail Size"),
set_prop_to_node_factory("bioxels_offset", "Offset"),
])
}, },
{ {
'label': 'Segment by Range', 'label': 'Mask by Range',
'icon': 'IPO_CONSTANT', 'icon': 'IPO_CONSTANT',
'node_type': 'BioxelNodes_SegmentByRange', 'node_type': 'BioxelNodes_MaskByRange',
'node_description': '', 'node_description': ''
'node_callback': "\n".join([ },
set_prop_to_node_factory("bioxel_size", "Detail Size"), {
set_prop_to_node_factory("bioxels_offset", "Offset"), 'label': 'Mask by Label',
]) 'icon': 'MESH_CAPSULE',
'node_type': 'BioxelNodes_MaskByLabel',
'node_description': ''
} }
# {
# 'label': 'Segment by Layers',
# 'icon': 'ALIGN_JUSTIFY',
# 'node_type': 'BioxelNodes_SegmentsByLayers',
# 'node_description': '',
# 'node_callback': "\n".join([
# set_prop_to_node_factory("bioxel_size", "Detail Size"),
# set_prop_to_node_factory("bioxels_offset", "Offset"),
# ])
# }
] ]
}, },
{ {
'label': 'Shader', 'label': 'Shaders',
'icon': 'SHADING_RENDERED', 'icon': 'SHADING_RENDERED',
'items': [ 'items': [
{ {
'label': 'Segment Shader', 'label': 'Membrane Shader',
'icon': 'OUTLINER_OB_VOLUME', 'icon': 'NODE_MATERIAL',
'node_type': 'BioxelNodes_SegmentShader', 'node_type': 'BioxelNodes_AssignMembraneShader',
'node_description': ''
},
{
'label': 'Solid Shader',
'icon': 'SHADING_SOLID',
'node_type': 'BioxelNodes_AssignSolidShader',
'node_description': ''
},
{
'label': 'Slime Shader',
'icon': 'OUTLINER_DATA_META',
'node_type': 'BioxelNodes_AssignSlimeShader',
'node_description': ''
},
{
'label': 'Volume Shader',
'icon': 'VOLUME_DATA',
'node_type': 'BioxelNodes_AssignVolumeShader',
'node_description': ''
},
{
'label': 'Universal Shader',
'icon': 'MATSHADERBALL',
'node_type': 'BioxelNodes_AssignUniversalShader',
'node_description': '' 'node_description': ''
} }
] ]
} },
] {
'label': 'Colors',
NODE_FILE = "BioxelNodes_4.0" 'icon': 'COLOR',
if bpy.app.version >= (4, 1, 0):
MENU_ITEMS.append({
'label': 'Slicer',
'icon': 'CLIPUV_DEHLT',
'items': [ 'items': [
{ {
'label': 'RAS Slicer', 'label': 'Color Presets',
'icon': 'EMPTY_DATA', 'icon': 'COLOR',
'node_type': 'BioxelNodes_RAS-Slicer', 'node_type': 'BioxelNodes_SetColorPresets',
'node_description': ''
},
"separator",
{
'label': 'Color Ramp 2',
'icon': 'IPO_QUAD',
'node_type': 'BioxelNodes_SetColorRamp2',
'node_description': '' 'node_description': ''
}, },
{ {
'label': 'Axis Slicer', 'label': 'Color Ramp 3',
'icon': 'OUTLINER_OB_EMPTY', 'icon': 'IPO_CUBIC',
'node_type': 'BioxelNodes_AxisSlicer', 'node_type': 'BioxelNodes_SetColorRamp3',
'node_description': ''
},
{
'label': 'Color Ramp 4',
'icon': 'IPO_QUART',
'node_type': 'BioxelNodes_SetColorRamp4',
'node_description': ''
},
{
'label': 'Color Ramp 5',
'icon': 'IPO_QUINT',
'node_type': 'BioxelNodes_SetColorRamp5',
'node_description': ''
}
]
},
{
'label': 'Cutters',
'icon': 'MOD_BEVEL',
'items': [
{
'label': 'Cut',
'icon': 'MOD_BEVEL',
'node_type': 'BioxelNodes_Cut',
'node_description': ''
},
"separator",
{
'label': 'Plane Cutter',
'icon': 'MESH_PLANE',
'node_type': 'BioxelNodes_PlaneObjectCutter',
'node_description': ''
},
{
'label': 'Cylinder Cutter',
'icon': 'MESH_CYLINDER',
'node_type': 'BioxelNodes_CylinderObjectCutter',
'node_description': '', 'node_description': '',
}, },
{ {
'label': 'Box Slicer', 'label': 'Cube Cutter',
'icon': 'MOD_WIREFRAME', 'icon': 'MESH_CUBE',
'node_type': 'BioxelNodes_BoxSlicer', 'node_type': 'BioxelNodes_CubeObjectCutter',
'node_description': '',
},
{
'label': 'Sphere Cutter',
'icon': 'MESH_UVSPHERE',
'node_type': 'BioxelNodes_SphereObjectCutter',
'node_description': '', 'node_description': '',
} }
] ]
}) },
NODE_FILE = "BioxelNodes_4.1" {
'label': 'Utils',
'icon': 'MODIFIER',
'items': [
{
'label': 'Join Component',
'icon': 'CONSTRAINT_BONE',
'node_type': 'BioxelNodes_JoinComponent',
'node_description': ''
},
"separator",
{
'label': 'To Mesh',
'icon': 'OUTLINER_OB_MESH',
'node_type': 'BioxelNodes_ToMesh',
'node_description': ''
},
{
'label': 'To Volume',
'icon': 'OUTLINER_OB_VOLUME',
'node_type': 'BioxelNodes_ToVolume',
'node_description': ''
},
{
'label': 'To Bbox Wire',
'icon': 'MESH_CUBE',
'node_type': 'BioxelNodes_ToBboxWire',
'node_description': ''
},
"separator",
{
'label': 'Inflate',
'icon': 'OUTLINER_OB_META',
'node_type': 'META_DATA',
'node_description': ''
},
{
'label': 'Smooth',
'icon': 'MOD_SMOOTH',
'node_type': 'BioxelNodes_M_Smooth',
'node_description': ''
},
{
'label': 'Remove Small Island',
'icon': 'FORCE_LENNARDJONES',
'node_type': 'BioxelNodes_M_RemoveSmallIsland',
'node_description': ''
}
]
}
]
else:
NODE_FILE = "BioxelNodes_4.0"
MENU_ITEMS = [
{
'label': 'Methods',
'icon': 'OUTLINER_DATA_VOLUME',
'items': [
{
'label': 'Mask by Threshold',
'icon': 'EMPTY_SINGLE_ARROW',
'node_type': 'BioxelNodes_MaskByThreshold',
'node_description': ''
},
{
'label': 'Mask by Range',
'icon': 'IPO_CONSTANT',
'node_type': 'BioxelNodes_MaskByRange',
'node_description': ''
},
{
'label': 'Mask by Label',
'icon': 'MESH_CAPSULE',
'node_type': 'BioxelNodes_MaskByLabel',
'node_description': ''
}
]
},
{
'label': 'Shaders',
'icon': 'SHADING_RENDERED',
'items': [
{
'label': 'Solid Shader',
'icon': 'SHADING_SOLID',
'node_type': 'BioxelNodes_AssignSolidShader',
'node_description': ''
},
{
'label': 'Slime Shader',
'icon': 'OUTLINER_OB_META',
'node_type': 'BioxelNodes_AssignSlimeShader',
'node_description': ''
},
{
'label': 'Volume Shader',
'icon': 'OUTLINER_OB_VOLUME',
'node_type': 'BioxelNodes_AssignVolumeShader',
'node_description': ''
},
{
'label': 'Universal Shader',
'icon': 'SHADING_RENDERED',
'node_type': 'BioxelNodes_AssignUniversalShader',
'node_description': ''
}
]
},
{
'label': 'Colors',
'icon': 'COLOR',
'items': [
{
'label': 'Color Ramp 2',
'icon': 'IPO_QUAD',
'node_type': 'BioxelNodes_SetColorRamp2',
'node_description': ''
},
{
'label': 'Color Ramp 3',
'icon': 'IPO_CUBIC',
'node_type': 'BioxelNodes_SetColorRamp3',
'node_description': ''
},
{
'label': 'Color Ramp 4',
'icon': 'IPO_QUART',
'node_type': 'BioxelNodes_SetColorRamp4',
'node_description': ''
},
{
'label': 'Color Ramp 5',
'icon': 'IPO_QUINT',
'node_type': 'BioxelNodes_SetColorRamp5',
'node_description': ''
}
]
},
{
'label': 'Cutters',
'icon': 'MOD_BEVEL',
'items': [
{
'label': 'Cut',
'icon': 'MOD_BEVEL',
'node_type': 'BioxelNodes_Cut',
'node_description': ''
},
"separator",
{
'label': 'Plane Cutter',
'icon': 'MESH_PLANE',
'node_type': 'BioxelNodes_PlaneObjectCutter',
'node_description': ''
},
{
'label': 'Cylinder Cutter',
'icon': 'MESH_CYLINDER',
'node_type': 'BioxelNodes_CylinderObjectCutter',
'node_description': '',
},
{
'label': 'Cube Cutter',
'icon': 'MESH_CUBE',
'node_type': 'BioxelNodes_CubeObjectCutter',
'node_description': '',
},
{
'label': 'Sphere Cutter',
'icon': 'MESH_UVSPHERE',
'node_type': 'BioxelNodes_SphereObjectCutter',
'node_description': '',
}
]
},
{
'label': 'Utils',
'icon': 'MODIFIER',
'items': [
{
'label': 'Join Component',
'icon': 'CONSTRAINT_BONE',
'node_type': 'BioxelNodes_JoinComponent',
'node_description': ''
}
]
}
]
custom_nodes = CustomNodes( custom_nodes = CustomNodes(

722
bioxelnodes/operators.py Normal file
View File

@@ -0,0 +1,722 @@
from pathlib import Path
import random
import bpy
import pyopenvdb as vdb
import numpy as np
from . import skimage as ski
from . import scipy
from .nodes import custom_nodes
from .utils import (get_container, get_container_from_selection, get_container_layers,
get_layer, get_node_by_type, hide_in_ray, lock_transform, save_vdb)
def get_layer_name(layer):
container = layer.parent
return layer.name.removeprefix(container.name).replace("_", "")
def get_grids(layer):
layer_dir = bpy.path.abspath(layer.data.filepath)
grids, base_metadata = vdb.readAll(layer_dir)
return grids
def set_volume(grids, index, volume):
grids[index].clear()
grids[index].copyFromArray(volume.copy().astype(np.float32))
def get_volume(grids, index, shape):
volume = np.ndarray(shape, np.float32)
volume.fill(index)
grids[0].copyToArray(volume)
return volume
def get_shape(layer):
layer_node = layer.modifiers[0].node_group.nodes['BioxelNodes__ConvertToLayer']
return [int(a)
for a in layer_node.inputs['Shape'].default_value]
def get_layer_meta(layer, key: str):
layer_node = layer.modifiers[0].node_group.nodes['BioxelNodes__ConvertToLayer']
return layer_node.inputs[key].default_value
def set_layer_meta(layer, key: str, value):
layer_node = layer.modifiers[0].node_group.nodes['BioxelNodes__ConvertToLayer']
layer_node.inputs[key].default_value = value
def add_mask_node(container, layer, node_type: str, node_label: str):
modifier = container.modifiers[0]
node_tree = modifier.node_group
# Deselect all nodes first
for node in node_tree.nodes:
if node.select:
node.select = False
mask_node = custom_nodes.add_node(node_tree.nodes, node_type)
mask_node.label = node_label
mask_node.inputs[0].default_value = layer
# Connect to output if no output linked
output_node = get_node_by_type(node_tree.nodes,
'NodeGroupOutput')[0]
if len(output_node.inputs[0].links) == 0:
node_tree.links.new(mask_node.outputs[0],
output_node.inputs[0])
return mask_node
def deep_copy_layer(vdb_path, base_layer, name):
# Read VDB
print(f"Loading the cache to Blender scene...")
bpy.ops.object.volume_import(
filepath=str(vdb_path), align='WORLD', location=(0, 0, 0), scale=(1, 1, 1))
copyed_layer = bpy.context.active_object
# Set props to VDB object
copyed_layer.name = name
copyed_layer.data.name = name
lock_transform(copyed_layer)
hide_in_ray(copyed_layer)
copyed_layer.hide_select = True
copyed_layer.hide_render = True
copyed_layer.hide_viewport = True
copyed_layer.data.display.use_slice = True
copyed_layer.data.display.density = 1e-05
copyed_layer['bioxel_layer'] = True
copyed_layer['bioxel_layer_type'] = base_layer['bioxel_layer_type']
copyed_layer.parent = base_layer.parent
for collection in copyed_layer.users_collection:
collection.objects.unlink(copyed_layer)
for collection in base_layer.users_collection:
collection.objects.link(copyed_layer)
# add convert to layer node
base_layer_node = base_layer.modifiers[0].node_group.nodes['BioxelNodes__ConvertToLayer']
bioxel_size = base_layer_node.inputs['Bioxel Size'].default_value
layer_shape = base_layer_node.inputs['Shape'].default_value
layer_origin = base_layer_node.inputs['Origin'].default_value
layer_rotation = base_layer_node.inputs['Rotation'].default_value
scalar_offset = base_layer_node.inputs['Scalar Offset'].default_value
scalar_min = base_layer_node.inputs['Scalar Min'].default_value
scalar_max = base_layer_node.inputs['Scalar Max'].default_value
bpy.ops.node.new_geometry_nodes_modifier()
node_tree = copyed_layer.modifiers[0].node_group
input_node = get_node_by_type(node_tree.nodes, 'NodeGroupInput')[0]
output_node = get_node_by_type(node_tree.nodes, 'NodeGroupOutput')[0]
copyed_layer_node = custom_nodes.add_node(node_tree.nodes,
"BioxelNodes__ConvertToLayer")
node_tree.links.new(input_node.outputs[0], copyed_layer_node.inputs[0])
node_tree.links.new(copyed_layer_node.outputs[0], output_node.inputs[0])
copyed_layer_node.inputs['Layer ID'].default_value = random.randint(-200000000,
200000000)
copyed_layer_node.inputs['Bioxel Size'].default_value = bioxel_size
copyed_layer_node.inputs['Shape'].default_value = layer_shape
copyed_layer_node.inputs['Origin'].default_value = layer_origin
copyed_layer_node.inputs['Rotation'].default_value = layer_rotation
copyed_layer_node.inputs['Scalar Offset'].default_value = scalar_offset
copyed_layer_node.inputs['Scalar Min'].default_value = scalar_min
copyed_layer_node.inputs['Scalar Max'].default_value = scalar_max
return copyed_layer
def get_scalar_layer_selection(self, context):
items = [("None", "None", "")]
container = get_container(bpy.context.active_object)
for layer in get_container_layers(container):
if layer.get("bioxel_layer_type") == "scalar":
items.append((
layer.name,
layer.name,
""
))
return items
def get_label_layer_selection(self, context):
items = [("None", "None", "")]
container = get_container(bpy.context.active_object)
for layer in get_container_layers(container):
if layer.get("bioxel_layer_type") == "label":
items.append((
layer.name,
layer.name,
""
))
return items
# class JoinLayers(bpy.types.Operator):
# bl_idname = "bioxelnodes.join_layers"
# bl_label = "Join Bioxel Layers"
# bl_description = "Join Additional Bioxel Layers"
# bl_options = {'UNDO'}
# base_layer: bpy.props.StringProperty(
# options={"HIDDEN"}
# ) # type: ignore
# scalar_layer: bpy.props.EnumProperty(
# name="Scalar Layer",
# items=get_scalar_layer_selection
# ) # type: ignore
# label_layer: bpy.props.EnumProperty(
# name="Label Layer",
# items=get_label_layer_selection
# ) # type: ignore
# # color_layer: bpy.props.StringProperty() # type: ignore
# @classmethod
# def poll(cls, context):
# layer = get_layer(bpy.context.active_object)
# return True if layer else False
# def execute(self, context):
# base_layer = bpy.data.objects[self.base_layer]
# if not base_layer:
# self.report({"WARNING"}, "Cannot find any bioxel layer as base.")
# return {'FINISHED'}
# base_layer_dir = bpy.path.abspath(base_layer.data.filepath)
# base_grids, base_metadata = vdb.readAll(base_layer_dir)
# layers = []
# if self.scalar_layer != "None":
# scalar_layer = bpy.data.objects[self.scalar_layer]
# layers.append(scalar_layer)
# if self.label_layer != "None":
# label_layer = bpy.data.objects[self.label_layer]
# layers.append(label_layer)
# # TODO: add color and vector
# if len(layers) == 0:
# self.report({"WARNING"}, "No additinal layers setted.")
# return {'FINISHED'}
# for layer in layers:
# layer_dir = bpy.path.abspath(layer.data.filepath)
# grids, metadata = vdb.readAll(layer_dir)
# base_grids.extend(grids)
# vdb_path = save_vdb(base_grids, context)
# joined_layer = deep_copy_layer(vdb_path,
# base_layer,
# f"{base_layer.name}_Joined")
# return {'FINISHED'}
# def invoke(self, context, event):
# base_layer = get_layer(bpy.context.active_object)
# self.base_layer = base_layer.name
# context.window_manager.invoke_props_dialog(self, width=400)
# return {'RUNNING_MODAL'}
class InvertScalar(bpy.types.Operator):
bl_idname = "bioxelnodes.invert_scalar"
bl_label = "Invert Scalar"
bl_description = "Invert the scalar value"
bl_options = {'UNDO'}
@classmethod
def poll(cls, context):
layer = get_layer(bpy.context.active_object)
if layer:
return layer.get("bioxel_layer_type") == "scalar"
else:
return False
def execute(self, context):
base_layer = get_layer(bpy.context.active_object)
container = base_layer.parent
inverted_layer_name = f"{get_layer_name(base_layer)}_Inverted"
base_shape = get_shape(base_layer)
scalar_offset = get_layer_meta(base_layer, "Scalar Offset")
base_grids = get_grids(base_layer)
base_volume = get_volume(base_grids, 0, base_shape)
base_volume = -(base_volume - scalar_offset)
base_min = float(np.min(base_volume))
base_max = float(np.max(base_volume))
scalar_offset = 0
if base_min < 0:
scalar_offset = -base_min
base_volume = base_volume + scalar_offset
set_volume(base_grids, 0, base_volume)
vdb_path = save_vdb(base_grids, context)
inverted_layer = deep_copy_layer(vdb_path,
base_layer,
f"{container.name}_{inverted_layer_name}")
set_layer_meta(inverted_layer, 'Scalar Offset', scalar_offset)
set_layer_meta(inverted_layer, 'Scalar Min', base_min)
set_layer_meta(inverted_layer, 'Scalar Max', base_max)
add_mask_node(container,
inverted_layer,
"BioxelNodes_MaskByThreshold",
inverted_layer_name)
bpy.context.view_layer.objects.active = container
return {'FINISHED'}
class FillByThreshold(bpy.types.Operator):
bl_idname = "bioxelnodes.fill_by_threshold"
bl_label = "Fill by Threshold"
bl_description = "Fill Value by Threshold"
bl_options = {'UNDO'}
threshold: bpy.props.FloatProperty(
name="Threshold",
soft_min=0, soft_max=1024,
default=128,
) # type: ignore
fill_value: bpy.props.FloatProperty(
name="Fill Value",
soft_min=0, soft_max=1024.0,
default=0,
) # type: ignore
invert: bpy.props.BoolProperty(
name="Invert Area",
default=True,
) # type: ignore
@classmethod
def poll(cls, context):
layer = get_layer(bpy.context.active_object)
if layer:
return layer.get("bioxel_layer_type") == "scalar"
else:
return False
def execute(self, context):
base_layer = get_layer(bpy.context.active_object)
container = base_layer.parent
filled_layer_name = f"{get_layer_name(base_layer)}_{self.threshold}-Filled"
scalar_offset = get_layer_meta(base_layer, "Scalar Offset")
base_shape = get_shape(base_layer)
base_grids = get_grids(base_layer)
base_volume = get_volume(base_grids, 0, base_shape)
mask = base_volume > (self.threshold + scalar_offset)
mask = scipy.median_filter(mask.astype(np.float32), size=2)
if self.invert:
base_volume = mask * base_volume + \
(1-mask) * (self.fill_value + scalar_offset)
else:
base_volume = (1-mask) * base_volume + \
mask * (self.fill_value + scalar_offset)
set_volume(base_grids, 0, base_volume)
vdb_path = save_vdb(base_grids, context)
filled_layer = deep_copy_layer(vdb_path,
base_layer,
f"{container.name}_{filled_layer_name}")
mask_node = add_mask_node(container,
filled_layer,
"BioxelNodes_MaskByThreshold",
filled_layer_name)
mask_node.inputs[1].default_value = self.threshold
bpy.context.view_layer.objects.active = container
return {'FINISHED'}
def invoke(self, context, event):
base_layer = get_layer(bpy.context.active_object)
scalar_min = get_layer_meta(base_layer, "Scalar Min")
self.fill_value = scalar_min
context.window_manager.invoke_props_dialog(self, width=400)
return {'RUNNING_MODAL'}
class FillByRange(bpy.types.Operator):
bl_idname = "bioxelnodes.fill_by_range"
bl_label = "Fill by Range"
bl_description = "Fill Value by Range"
bl_options = {'UNDO'}
from_min: bpy.props.FloatProperty(
name="From Min",
soft_min=0, soft_max=1024,
default=128,
) # type: ignore
from_max: bpy.props.FloatProperty(
name="From Max",
soft_min=0, soft_max=1024,
default=256,
) # type: ignore
fill_value: bpy.props.FloatProperty(
name="Fill Value",
soft_min=0, soft_max=1024.0,
default=0,
) # type: ignore
invert: bpy.props.BoolProperty(
name="Invert Area",
default=True,
) # type: ignore
@classmethod
def poll(cls, context):
layer = get_layer(bpy.context.active_object)
if layer:
return layer.get("bioxel_layer_type") == "scalar"
else:
return False
def execute(self, context):
base_layer = get_layer(bpy.context.active_object)
container = base_layer.parent
filled_layer_name = f"{get_layer_name(base_layer)}_{self.from_min}-{self.from_max}-Filled"
scalar_offset = get_layer_meta(base_layer, "Scalar Offset")
base_shape = get_shape(base_layer)
base_grids = get_grids(base_layer)
base_volume = get_volume(base_grids, 0, base_shape)
mask = (base_volume > self.from_min + scalar_offset) \
& (base_volume < self.from_max + scalar_offset)
mask = scipy.median_filter(mask.astype(np.float32), size=2)
if self.invert:
base_volume = mask * base_volume + \
(1-mask) * (self.fill_value + scalar_offset)
else:
base_volume = (1-mask) * base_volume + \
mask * (self.fill_value + scalar_offset)
set_volume(base_grids, 0, base_volume)
vdb_path = save_vdb(base_grids, context)
filled_layer = deep_copy_layer(vdb_path,
base_layer,
f"{container.name}_{filled_layer_name}")
mask_node = add_mask_node(container,
filled_layer,
"BioxelNodes_MaskByThreshold",
filled_layer_name)
mask_node.inputs[1].default_value = self.from_min
bpy.context.view_layer.objects.active = container
return {'FINISHED'}
def invoke(self, context, event):
base_layer = get_layer(bpy.context.active_object)
scalar_min = get_layer_meta(base_layer, "Scalar Min")
self.fill_value = scalar_min
context.window_manager.invoke_props_dialog(self, width=400)
return {'RUNNING_MODAL'}
class FillByLabel(bpy.types.Operator):
bl_idname = "bioxelnodes.fill_by_label"
bl_label = "Fill by Label"
bl_description = "Fill Value by Label Area"
bl_options = {'UNDO'}
label_layer: bpy.props.EnumProperty(
name="Label Layer",
items=get_label_layer_selection
) # type: ignore
fill_value: bpy.props.FloatProperty(
name="Fill Value",
soft_min=0, soft_max=1024.0,
default=0,
) # type: ignore
invert: bpy.props.BoolProperty(
name="Invert Label",
default=True,
) # type: ignore
@classmethod
def poll(cls, context):
layer = get_layer(bpy.context.active_object)
if layer:
return layer.get("bioxel_layer_type") == "scalar"
else:
return False
def execute(self, context):
base_layer = get_layer(bpy.context.active_object)
label_layer = bpy.data.objects[self.label_layer]
if not label_layer:
self.report({"WARNING"}, "Cannot find any label layer.")
return {'FINISHED'}
container = base_layer.parent
filled_layer_name = f"{get_layer_name(base_layer)}_{get_layer_name(label_layer)}-Filled"
scalar_offset = get_layer_meta(base_layer, "Scalar Offset")
base_shape = get_shape(base_layer)
label_shape = get_shape(label_layer)
base_grids = get_grids(base_layer)
base_volume = get_volume(base_grids, 0, base_shape)
label_grids = get_grids(label_layer)
mask = get_volume(label_grids, 0, label_shape)
mask = ski.resize(mask,
base_shape,
anti_aliasing=True)
mask = scipy.median_filter(mask.astype(np.float32), size=2)
if self.invert:
base_volume = mask * base_volume + \
(1-mask) * (self.fill_value + scalar_offset)
else:
base_volume = (1-mask) * base_volume + \
mask * (self.fill_value + scalar_offset)
set_volume(base_grids, 0, base_volume)
vdb_path = save_vdb(base_grids, context)
filled_layer = deep_copy_layer(vdb_path,
base_layer,
f"{container.name}_{filled_layer_name}")
add_mask_node(container,
filled_layer,
"BioxelNodes_MaskByThreshold",
filled_layer_name)
bpy.context.view_layer.objects.active = container
return {'FINISHED'}
def invoke(self, context, event):
base_layer = get_layer(bpy.context.active_object)
scalar_min = get_layer_meta(base_layer, "Scalar Min")
self.fill_value = scalar_min
context.window_manager.invoke_props_dialog(self, width=400)
return {'RUNNING_MODAL'}
class CombineLabels(bpy.types.Operator):
bl_idname = "bioxelnodes.combine_labels"
bl_label = "Combine Labels"
bl_description = "Combine all selected labels"
bl_options = {'UNDO'}
@classmethod
def poll(cls, context):
labels = [obj for obj in context.selected_ids
if obj.get("bioxel_layer_type") == "label"]
return True if len(labels) > 1 else False
def execute(self, context):
labels = [obj for obj in context.selected_ids
if obj.get("bioxel_layer_type") == "label"]
base_layer = labels[0]
labels = labels[1:]
container = base_layer.parent
label_names = [get_layer_name(base_layer)]
base_shape = get_shape(base_layer)
base_grids = get_grids(base_layer)
base_volume = get_volume(base_grids, 0, base_shape)
base_volume = base_volume
for label in labels:
label_shape = get_shape(label)
label_grids = get_grids(label)
label_volume = get_volume(label_grids, 0, label_shape)
label_volume = ski.resize(label_volume,
base_shape,
anti_aliasing=True)
base_volume = np.maximum(base_volume, label_volume)
label_names.append(get_layer_name(label))
set_volume(base_grids, 0, base_volume)
combined_layer_name = f"{'-'.join(label_names)}-Combined"
vdb_path = save_vdb(base_grids, context)
combined_layer = deep_copy_layer(vdb_path,
base_layer,
f"{container.name}_{combined_layer_name}")
add_mask_node(container,
combined_layer,
"BioxelNodes_MaskByLabel",
combined_layer_name)
bpy.context.view_layer.objects.active = container
return {'FINISHED'}
class ConvertToMesh(bpy.types.Operator):
bl_idname = "bioxelnodes.convert_to_mesh"
bl_label = "Convert To Mesh"
bl_description = "Convert Bioxel Components To Mesh"
bl_options = {'UNDO'}
@classmethod
def poll(cls, context):
containers = get_container_from_selection()
return len(containers) > 0
def execute(self, context):
containers = get_container_from_selection()
if len(containers) == 0:
self.report({"WARNING"}, "Cannot find any bioxel container.")
return {'FINISHED'}
container = containers[0]
bpy.ops.mesh.primitive_cube_add(
size=2, enter_editmode=False, align='WORLD', location=(0, 0, 0), scale=(1, 1, 1))
mesh = bpy.context.active_object
mesh.name = f"Mesh_{container.name}"
# bpy.ops.object.constraint_add(type='COPY_TRANSFORMS')
# mesh.constraints[0].target = container
bpy.ops.node.new_geometry_nodes_modifier()
modifier = mesh.modifiers[0]
node_tree = modifier.node_group
output_node = get_node_by_type(node_tree.nodes, 'NodeGroupOutput')[0]
to_mesh_node = custom_nodes.add_node(node_tree.nodes,
"BioxelNodes_ToMesh")
to_mesh_node.inputs[0].default_value = container
node_tree.links.new(to_mesh_node.outputs[0], output_node.inputs[0])
bpy.ops.object.convert(target='MESH')
# bpy.ops.constraint.apply(
# constraint=mesh.constraints[0].name, owner='OBJECT')
bpy.context.object.active_material_index = 1
bpy.ops.object.material_slot_remove()
self.report({"INFO"}, f"Successfully convert to mesh")
return {'FINISHED'}
class AddCutter():
bl_options = {'UNDO'}
@classmethod
def poll(cls, context):
containers = get_container_from_selection()
return len(containers) > 0
def execute(self, context):
containers = get_container_from_selection()
if len(containers) == 0:
self.report({"WARNING"}, "Cannot find any bioxel container.")
return {'FINISHED'}
container = containers[0]
if self.object_type == "plane":
node_type = "BioxelNodes_PlaneObjectCutter"
bpy.ops.mesh.primitive_plane_add(
size=2, enter_editmode=False, align='WORLD', location=(0, 0, 0), scale=(1, 1, 1))
elif self.object_type == "cylinder":
node_type = "BioxelNodes_CylinderObjectCutter"
bpy.ops.mesh.primitive_cylinder_add(
radius=1, depth=2, enter_editmode=False, align='WORLD', location=(0, 0, 0), scale=(1, 1, 1))
bpy.context.object.rotation_euler[0] = container.rotation_euler[0]
elif self.object_type == "cube":
node_type = "BioxelNodes_CubeObjectCutter"
bpy.ops.mesh.primitive_cube_add(
size=2, enter_editmode=False, align='WORLD', location=(0, 0, 0), scale=(1, 1, 1))
elif self.object_type == "sphere":
node_type = "BioxelNodes_SphereObjectCutter"
bpy.ops.mesh.primitive_ico_sphere_add(
radius=1, enter_editmode=False, align='WORLD', location=(0, 0, 0), scale=(1, 1, 1))
cutter = bpy.context.active_object
cutter.visible_camera = False
cutter.visible_diffuse = False
cutter.visible_glossy = False
cutter.visible_transmission = False
cutter.visible_volume_scatter = False
cutter.visible_shadow = False
cutter.hide_render = True
cutter.display_type = 'WIRE'
modifier = container.modifiers[0]
node_tree = modifier.node_group
cutter_node = custom_nodes.add_node(node_tree.nodes, node_type)
cutter_node.inputs[0].default_value = cutter
bpy.context.view_layer.objects.active = container
return {'FINISHED'}
class AddPlaneCutter(bpy.types.Operator, AddCutter):
bl_idname = "bioxelnodes.add_plane_cutter"
bl_label = "Add Plane Cutter"
bl_description = "Add Plane Cutter to Container"
bl_options = {'UNDO'}
object_type = "plane"
class AddCylinderCutter(bpy.types.Operator, AddCutter):
bl_idname = "bioxelnodes.add_cylinder_cutter"
bl_label = "Add Cylinder Cutter"
bl_description = "Add Cylinder Cutter to Container"
bl_options = {'UNDO'}
object_type = "cylinder"
class AddCubeCutter(bpy.types.Operator, AddCutter):
bl_idname = "bioxelnodes.add_cube_cutter"
bl_label = "Add Cube Cutter"
bl_description = "Add Cube Cutter to Container"
bl_options = {'UNDO'}
object_type = "cube"
class AddSphereCutter(bpy.types.Operator, AddCutter):
bl_idname = "bioxelnodes.add_sphere_cutter"
bl_label = "Add Sphere Cutter"
bl_description = "Add Sphere Cutter to Container"
bl_options = {'UNDO'}
object_type = "sphere"

View File

@@ -12,11 +12,6 @@ class BioxelNodesPreferences(bpy.types.AddonPreferences, ExternalPackagePreferen
default=str(Path(Path.home(), '.bioxelnodes')) default=str(Path(Path.home(), '.bioxelnodes'))
) # type: ignore ) # type: ignore
do_add_segmentnode: bpy.props.BoolProperty(
name="Add Segment Node",
default=True,
) # type: ignore
do_change_render_setting: bpy.props.BoolProperty( do_change_render_setting: bpy.props.BoolProperty(
name="Change Render Setting", name="Change Render Setting",
default=True, default=True,
@@ -31,6 +26,4 @@ class BioxelNodesPreferences(bpy.types.AddonPreferences, ExternalPackagePreferen
layout.label(text="Configuration") layout.label(text="Configuration")
layout.prop(self, 'cache_dir') layout.prop(self, 'cache_dir')
layout.prop(self, "do_change_render_setting") layout.prop(self, "do_change_render_setting")
layout.prop(self, "do_add_segmentnode")

View File

@@ -0,0 +1,2 @@
from ._interpolation import zoom
from ._filters import gaussian_filter, median_filter

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,313 @@
import numpy as np
import warnings
from . import _ni_support
from . import _nd_image
from ._utils import normalize_axis_index
def _prepad_for_spline_filter(input, mode, cval):
if mode in ['nearest', 'grid-constant']:
npad = 12
if mode == 'grid-constant':
padded = np.pad(input, npad, mode='constant',
constant_values=cval)
elif mode == 'nearest':
padded = np.pad(input, npad, mode='edge')
else:
# other modes have exact boundary conditions implemented so
# no prepadding is needed
npad = 0
padded = input
return padded, npad
def spline_filter1d(input, order=3, axis=-1, output=np.float64,
mode='mirror'):
"""
Calculate a 1-D spline filter along the given axis.
The lines of the array along the given axis are filtered by a
spline filter. The order of the spline must be >= 2 and <= 5.
Parameters
----------
%(input)s
order : int, optional
The order of the spline, default is 3.
axis : int, optional
The axis along which the spline filter is applied. Default is the last
axis.
output : ndarray or dtype, optional
The array in which to place the output, or the dtype of the returned
array. Default is ``numpy.float64``.
%(mode_interp_mirror)s
Returns
-------
spline_filter1d : ndarray
The filtered input.
See Also
--------
spline_filter : Multidimensional spline filter.
Notes
-----
All of the interpolation functions in `ndimage` do spline interpolation of
the input image. If using B-splines of `order > 1`, the input image
values have to be converted to B-spline coefficients first, which is
done by applying this 1-D filter sequentially along all
axes of the input. All functions that require B-spline coefficients
will automatically filter their inputs, a behavior controllable with
the `prefilter` keyword argument. For functions that accept a `mode`
parameter, the result will only be correct if it matches the `mode`
used when filtering.
For complex-valued `input`, this function processes the real and imaginary
components independently.
.. versionadded:: 1.6.0
Complex-valued support added.
Examples
--------
We can filter an image using 1-D spline along the given axis:
>>> from scipy.ndimage import spline_filter1d
>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> orig_img = np.eye(20) # create an image
>>> orig_img[10, :] = 1.0
>>> sp_filter_axis_0 = spline_filter1d(orig_img, axis=0)
>>> sp_filter_axis_1 = spline_filter1d(orig_img, axis=1)
>>> f, ax = plt.subplots(1, 3, sharex=True)
>>> for ind, data in enumerate([[orig_img, "original image"],
... [sp_filter_axis_0, "spline filter (axis=0)"],
... [sp_filter_axis_1, "spline filter (axis=1)"]]):
... ax[ind].imshow(data[0], cmap='gray_r')
... ax[ind].set_title(data[1])
>>> plt.tight_layout()
>>> plt.show()
"""
if order < 0 or order > 5:
raise RuntimeError('spline order not supported')
input = np.asarray(input)
complex_output = np.iscomplexobj(input)
output = _ni_support._get_output(output, input,
complex_output=complex_output)
if complex_output:
spline_filter1d(input.real, order, axis, output.real, mode)
spline_filter1d(input.imag, order, axis, output.imag, mode)
return output
if order in [0, 1]:
output[...] = np.array(input)
else:
mode = _ni_support._extend_mode_to_code(mode)
axis = normalize_axis_index(axis, input.ndim)
_nd_image.spline_filter1d(input, order, axis, output, mode)
return output
def spline_filter(input, order=3, output=np.float64, mode='mirror'):
"""
Multidimensional spline filter.
Parameters
----------
%(input)s
order : int, optional
The order of the spline, default is 3.
output : ndarray or dtype, optional
The array in which to place the output, or the dtype of the returned
array. Default is ``numpy.float64``.
%(mode_interp_mirror)s
Returns
-------
spline_filter : ndarray
Filtered array. Has the same shape as `input`.
See Also
--------
spline_filter1d : Calculate a 1-D spline filter along the given axis.
Notes
-----
The multidimensional filter is implemented as a sequence of
1-D spline filters. The intermediate arrays are stored
in the same data type as the output. Therefore, for output types
with a limited precision, the results may be imprecise because
intermediate results may be stored with insufficient precision.
For complex-valued `input`, this function processes the real and imaginary
components independently.
.. versionadded:: 1.6.0
Complex-valued support added.
Examples
--------
We can filter an image using multidimentional splines:
>>> from scipy.ndimage import spline_filter
>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> orig_img = np.eye(20) # create an image
>>> orig_img[10, :] = 1.0
>>> sp_filter = spline_filter(orig_img, order=3)
>>> f, ax = plt.subplots(1, 2, sharex=True)
>>> for ind, data in enumerate([[orig_img, "original image"],
... [sp_filter, "spline filter"]]):
... ax[ind].imshow(data[0], cmap='gray_r')
... ax[ind].set_title(data[1])
>>> plt.tight_layout()
>>> plt.show()
"""
if order < 2 or order > 5:
raise RuntimeError('spline order not supported')
input = np.asarray(input)
complex_output = np.iscomplexobj(input)
output = _ni_support._get_output(output, input,
complex_output=complex_output)
if complex_output:
spline_filter(input.real, order, output.real, mode)
spline_filter(input.imag, order, output.imag, mode)
return output
if order not in [0, 1] and input.ndim > 0:
for axis in range(input.ndim):
spline_filter1d(input, order, axis, output=output, mode=mode)
input = output
else:
output[...] = input[...]
return output
def zoom(input, zoom, output=None, order=3, mode='constant', cval=0.0,
prefilter=True, *, grid_mode=False):
"""
Zoom an array.
The array is zoomed using spline interpolation of the requested order.
Parameters
----------
%(input)s
zoom : float or sequence
The zoom factor along the axes. If a float, `zoom` is the same for each
axis. If a sequence, `zoom` should contain one value for each axis.
%(output)s
order : int, optional
The order of the spline interpolation, default is 3.
The order has to be in the range 0-5.
%(mode_interp_constant)s
%(cval)s
%(prefilter)s
grid_mode : bool, optional
If False, the distance from the pixel centers is zoomed. Otherwise, the
distance including the full pixel extent is used. For example, a 1d
signal of length 5 is considered to have length 4 when `grid_mode` is
False, but length 5 when `grid_mode` is True. See the following
visual illustration:
.. code-block:: text
| pixel 1 | pixel 2 | pixel 3 | pixel 4 | pixel 5 |
|<-------------------------------------->|
vs.
|<----------------------------------------------->|
The starting point of the arrow in the diagram above corresponds to
coordinate location 0 in each mode.
Returns
-------
zoom : ndarray
The zoomed input.
Notes
-----
For complex-valued `input`, this function zooms the real and imaginary
components independently.
.. versionadded:: 1.6.0
Complex-valued support added.
Examples
--------
>>> from scipy import ndimage, datasets
>>> import matplotlib.pyplot as plt
>>> fig = plt.figure()
>>> ax1 = fig.add_subplot(121) # left side
>>> ax2 = fig.add_subplot(122) # right side
>>> ascent = datasets.ascent()
>>> result = ndimage.zoom(ascent, 3.0)
>>> ax1.imshow(ascent, vmin=0, vmax=255)
>>> ax2.imshow(result, vmin=0, vmax=255)
>>> plt.show()
>>> print(ascent.shape)
(512, 512)
>>> print(result.shape)
(1536, 1536)
"""
if order < 0 or order > 5:
raise RuntimeError('spline order not supported')
input = np.asarray(input)
if input.ndim < 1:
raise RuntimeError('input and output rank must be > 0')
zoom = _ni_support._normalize_sequence(zoom, input.ndim)
output_shape = tuple(
[int(round(ii * jj)) for ii, jj in zip(input.shape, zoom)])
complex_output = np.iscomplexobj(input)
output = _ni_support._get_output(output, input, shape=output_shape,
complex_output=complex_output)
if complex_output:
# import under different name to avoid confusion with zoom parameter
from scipy.ndimage._interpolation import zoom as _zoom
kwargs = dict(order=order, mode=mode, prefilter=prefilter)
_zoom(input.real, zoom, output=output.real,
cval=np.real(cval), **kwargs)
_zoom(input.imag, zoom, output=output.imag,
cval=np.imag(cval), **kwargs)
return output
if prefilter and order > 1:
padded, npad = _prepad_for_spline_filter(input, mode, cval)
filtered = spline_filter(padded, order, output=np.float64, mode=mode)
else:
npad = 0
filtered = input
if grid_mode:
# warn about modes that may have surprising behavior
suggest_mode = None
if mode == 'constant':
suggest_mode = 'grid-constant'
elif mode == 'wrap':
suggest_mode = 'grid-wrap'
if suggest_mode is not None:
warnings.warn(
(f"It is recommended to use mode = {suggest_mode} instead of {mode} "
f"when grid_mode is True."),
stacklevel=2
)
mode = _ni_support._extend_mode_to_code(mode)
zoom_div = np.array(output_shape)
zoom_nominator = np.array(input.shape)
if not grid_mode:
zoom_div -= 1
zoom_nominator -= 1
# Zooming to infinite values is unpredictable, so just choose
# zoom factor 1 instead
zoom = np.divide(zoom_nominator, zoom_div,
out=np.ones_like(input.shape, dtype=np.float64),
where=zoom_div != 0)
zoom = np.ascontiguousarray(zoom)
_nd_image.zoom_shift(filtered, zoom, None, output, order, mode, cval, npad,
grid_mode)
return output

Binary file not shown.

Binary file not shown.

View File

@@ -0,0 +1,119 @@
# Copyright (C) 2003-2005 Peter J. Verveer
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above
# copyright notice, this list of conditions and the following
# disclaimer in the documentation and/or other materials provided
# with the distribution.
#
# 3. The name of the author may not be used to endorse or promote
# products derived from this software without specific prior
# written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
# OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
# GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
from collections.abc import Iterable
import operator
import warnings
import numpy as np
def _extend_mode_to_code(mode):
"""Convert an extension mode to the corresponding integer code.
"""
if mode == 'nearest':
return 0
elif mode == 'wrap':
return 1
elif mode in ['reflect', 'grid-mirror']:
return 2
elif mode == 'mirror':
return 3
elif mode == 'constant':
return 4
elif mode == 'grid-wrap':
return 5
elif mode == 'grid-constant':
return 6
else:
raise RuntimeError('boundary mode not supported')
def _normalize_sequence(input, rank):
"""If input is a scalar, create a sequence of length equal to the
rank by duplicating the input. If input is a sequence,
check if its length is equal to the length of array.
"""
is_str = isinstance(input, str)
if not is_str and isinstance(input, Iterable):
normalized = list(input)
if len(normalized) != rank:
err = "sequence argument must have length equal to input rank"
raise RuntimeError(err)
else:
normalized = [input] * rank
return normalized
def _get_output(output, input, shape=None, complex_output=False):
if shape is None:
shape = input.shape
if output is None:
if not complex_output:
output = np.zeros(shape, dtype=input.dtype.name)
else:
complex_type = np.promote_types(input.dtype, np.complex64)
output = np.zeros(shape, dtype=complex_type)
elif isinstance(output, (type, np.dtype)):
# Classes (like `np.float32`) and dtypes are interpreted as dtype
if complex_output and np.dtype(output).kind != 'c':
warnings.warn("promoting specified output dtype to complex", stacklevel=3)
output = np.promote_types(output, np.complex64)
output = np.zeros(shape, dtype=output)
elif isinstance(output, str):
output = np.dtype(output)
if complex_output and output.kind != 'c':
raise RuntimeError("output must have complex dtype")
elif not issubclass(output.type, np.number):
raise RuntimeError("output must have numeric dtype")
output = np.zeros(shape, dtype=output)
elif output.shape != shape:
raise RuntimeError("output shape not correct")
elif complex_output and output.dtype.kind != 'c':
raise RuntimeError("output must have complex dtype")
return output
def _check_axes(axes, ndim):
if axes is None:
return tuple(range(ndim))
elif np.isscalar(axes):
axes = (operator.index(axes),)
elif isinstance(axes, Iterable):
for ax in axes:
axes = tuple(operator.index(ax) for ax in axes)
if ax < -ndim or ax > ndim - 1:
raise ValueError(f"specified axis: {ax} is out of range")
axes = tuple(ax % ndim if ax < 0 else ax for ax in axes)
else:
message = "axes must be an integer, iterable of integers, or None"
raise ValueError(message)
if len(tuple(set(axes))) != len(axes):
raise ValueError("axes must be unique")
return axes

View File

@@ -0,0 +1,10 @@
def normalize_axis_index(axis, ndim):
# Check if `axis` is in the correct range and normalize it
if axis < -ndim or axis >= ndim:
msg = f"axis {axis} is out of bounds for array of dimension {ndim}"
raise Exception(msg)
if axis < 0:
axis = axis + ndim
return axis

View File

@@ -0,0 +1 @@
from ._warps import resize

View File

@@ -0,0 +1,37 @@
import numpy as np
def convert_to_float(image, preserve_range):
"""Convert input image to float image with the appropriate range.
Parameters
----------
image : ndarray
Input image.
preserve_range : bool
Determines if the range of the image should be kept or transformed
using img_as_float. Also see
https://scikit-image.org/docs/dev/user_guide/data_types.html
Notes
-----
* Input images with `float32` data type are not upcast.
Returns
-------
image : ndarray
Transformed version of the input.
"""
if image.dtype == np.float16:
return image.astype(np.float32)
if preserve_range:
# Convert image to double only if it is not single or double
# precision float
if image.dtype.char not in 'df':
image = image.astype(float)
else:
from .dtype import img_as_float
image = img_as_float(image)
return image

View File

@@ -0,0 +1,318 @@
import warnings
import numpy as np
from .. import scipy as ndi
from ._utils import convert_to_float
def _clip_warp_output(input_image, output_image, mode, cval, clip):
"""Clip output image to range of values of input image.
Note that this function modifies the values of `output_image` in-place
and it is only modified if ``clip=True``.
Parameters
----------
input_image : ndarray
Input image.
output_image : ndarray
Output image, which is modified in-place.
Other parameters
----------------
mode : {'constant', 'edge', 'symmetric', 'reflect', 'wrap'}
Points outside the boundaries of the input are filled according
to the given mode. Modes match the behaviour of `numpy.pad`.
cval : float
Used in conjunction with mode 'constant', the value outside
the image boundaries.
clip : bool
Whether to clip the output to the range of values of the input image.
This is enabled by default, since higher order interpolation may
produce values outside the given input range.
"""
if clip:
min_val = np.min(input_image)
if np.isnan(min_val):
# NaNs detected, use NaN-safe min/max
min_func = np.nanmin
max_func = np.nanmax
min_val = min_func(input_image)
else:
min_func = np.min
max_func = np.max
max_val = max_func(input_image)
# Check if cval has been used such that it expands the effective input
# range
preserve_cval = (
mode == 'constant'
and not min_val <= cval <= max_val
and min_func(output_image) <= cval <= max_func(output_image)
)
# expand min/max range to account for cval
if preserve_cval:
# cast cval to the same dtype as the input image
cval = input_image.dtype.type(cval)
min_val = min(min_val, cval)
max_val = max(max_val, cval)
# Convert array-like types to ndarrays (gh-7159)
min_val, max_val = np.asarray(min_val), np.asarray(max_val)
np.clip(output_image, min_val, max_val, out=output_image)
def _validate_interpolation_order(image_dtype, order):
"""Validate and return spline interpolation's order.
Parameters
----------
image_dtype : dtype
Image dtype.
order : int, optional
The order of the spline interpolation. The order has to be in
the range 0-5. See `skimage.transform.warp` for detail.
Returns
-------
order : int
if input order is None, returns 0 if image_dtype is bool and 1
otherwise. Otherwise, image_dtype is checked and input order
is validated accordingly (order > 0 is not supported for bool
image dtype)
"""
if order is None:
return 0 if image_dtype == bool else 1
if order < 0 or order > 5:
raise ValueError(
"Spline interpolation order has to be in the " "range 0-5.")
if image_dtype == bool and order != 0:
raise ValueError(
"Input image dtype is bool. Interpolation is not defined "
"with bool data type. Please set order to 0 or explicitly "
"cast input image to another data type."
)
return order
def _preprocess_resize_output_shape(image, output_shape):
"""Validate resize output shape according to input image.
Parameters
----------
image: ndarray
Image to be resized.
output_shape: iterable
Size of the generated output image `(rows, cols[, ...][, dim])`. If
`dim` is not provided, the number of channels is preserved.
Returns
-------
image: ndarray
The input image, but with additional singleton dimensions appended in
the case where ``len(output_shape) > input.ndim``.
output_shape: tuple
The output image converted to tuple.
Raises
------
ValueError:
If output_shape length is smaller than the image number of
dimensions
Notes
-----
The input image is reshaped if its number of dimensions is not
equal to output_shape_length.
"""
output_shape = tuple(output_shape)
output_ndim = len(output_shape)
input_shape = image.shape
if output_ndim > image.ndim:
# append dimensions to input_shape
input_shape += (1,) * (output_ndim - image.ndim)
image = np.reshape(image, input_shape)
elif output_ndim == image.ndim - 1:
# multichannel case: append shape of last axis
output_shape = output_shape + (image.shape[-1],)
elif output_ndim < image.ndim:
raise ValueError(
"output_shape length cannot be smaller than the "
"image number of dimensions"
)
return image, output_shape
def _to_ndimage_mode(mode):
"""Convert from `numpy.pad` mode name to the corresponding ndimage mode."""
mode_translation_dict = dict(
constant='constant',
edge='nearest',
symmetric='reflect',
reflect='mirror',
wrap='wrap',
)
if mode not in mode_translation_dict:
raise ValueError(
f"Unknown mode: '{mode}', or cannot translate mode. The "
f"mode should be one of 'constant', 'edge', 'symmetric', "
f"'reflect', or 'wrap'. See the documentation of numpy.pad for "
f"more info."
)
return _fix_ndimage_mode(mode_translation_dict[mode])
def _fix_ndimage_mode(mode):
# SciPy 1.6.0 introduced grid variants of constant and wrap which
# have less surprising behavior for images. Use these when available
grid_modes = {'constant': 'grid-constant', 'wrap': 'grid-wrap'}
return grid_modes.get(mode, mode)
def resize(
image,
output_shape,
order=None,
mode='reflect',
cval=0,
clip=True,
preserve_range=False,
anti_aliasing=None,
anti_aliasing_sigma=None,
):
"""Resize image to match a certain size.
Performs interpolation to up-size or down-size N-dimensional images. Note
that anti-aliasing should be enabled when down-sizing images to avoid
aliasing artifacts. For downsampling with an integer factor also see
`skimage.transform.downscale_local_mean`.
Parameters
----------
image : ndarray
Input image.
output_shape : iterable
Size of the generated output image `(rows, cols[, ...][, dim])`. If
`dim` is not provided, the number of channels is preserved. In case the
number of input channels does not equal the number of output channels a
n-dimensional interpolation is applied.
Returns
-------
resized : ndarray
Resized version of the input.
Other parameters
----------------
order : int, optional
The order of the spline interpolation, default is 0 if
image.dtype is bool and 1 otherwise. The order has to be in
the range 0-5. See `skimage.transform.warp` for detail.
mode : {'constant', 'edge', 'symmetric', 'reflect', 'wrap'}, optional
Points outside the boundaries of the input are filled according
to the given mode. Modes match the behaviour of `numpy.pad`.
cval : float, optional
Used in conjunction with mode 'constant', the value outside
the image boundaries.
clip : bool, optional
Whether to clip the output to the range of values of the input image.
This is enabled by default, since higher order interpolation may
produce values outside the given input range.
preserve_range : bool, optional
Whether to keep the original range of values. Otherwise, the input
image is converted according to the conventions of `img_as_float`.
Also see https://scikit-image.org/docs/dev/user_guide/data_types.html
anti_aliasing : bool, optional
Whether to apply a Gaussian filter to smooth the image prior
to downsampling. It is crucial to filter when downsampling
the image to avoid aliasing artifacts. If not specified, it is set to
True when downsampling an image whose data type is not bool.
It is also set to False when using nearest neighbor interpolation
(``order`` == 0) with integer input data type.
anti_aliasing_sigma : {float, tuple of floats}, optional
Standard deviation for Gaussian filtering used when anti-aliasing.
By default, this value is chosen as (s - 1) / 2 where s is the
downsampling factor, where s > 1. For the up-size case, s < 1, no
anti-aliasing is performed prior to rescaling.
Notes
-----
Modes 'reflect' and 'symmetric' are similar, but differ in whether the edge
pixels are duplicated during the reflection. As an example, if an array
has values [0, 1, 2] and was padded to the right by four values using
symmetric, the result would be [0, 1, 2, 2, 1, 0, 0], while for reflect it
would be [0, 1, 2, 1, 0, 1, 2].
Examples
--------
>>> from skimage import data
>>> from skimage.transform import resize
>>> image = data.camera()
>>> resize(image, (100, 100)).shape
(100, 100)
"""
image, output_shape = _preprocess_resize_output_shape(image, output_shape)
input_shape = image.shape
input_type = image.dtype
if input_type == np.float16:
image = image.astype(np.float32)
if anti_aliasing is None:
anti_aliasing = (
not input_type == bool
and not (np.issubdtype(input_type, np.integer) and order == 0)
and any(x < y for x, y in zip(output_shape, input_shape))
)
if input_type == bool and anti_aliasing:
raise ValueError("anti_aliasing must be False for boolean images")
factors = np.divide(input_shape, output_shape)
order = _validate_interpolation_order(input_type, order)
if order > 0:
image = convert_to_float(image, preserve_range)
# Translate modes used by np.pad to those used by scipy.ndimage
ndi_mode = _to_ndimage_mode(mode)
if anti_aliasing:
if anti_aliasing_sigma is None:
anti_aliasing_sigma = np.maximum(0, (factors - 1) / 2)
else:
anti_aliasing_sigma = np.atleast_1d(anti_aliasing_sigma) * np.ones_like(
factors
)
if np.any(anti_aliasing_sigma < 0):
raise ValueError(
"Anti-aliasing standard deviation must be "
"greater than or equal to zero"
)
elif np.any((anti_aliasing_sigma > 0) & (factors <= 1)):
warnings.warn(
"Anti-aliasing standard deviation greater than zero but "
"not down-sampling along all axes",
stacklevel=2
)
filtered = ndi.gaussian_filter(
image, anti_aliasing_sigma, cval=cval, mode=ndi_mode
)
else:
filtered = image
zoom_factors = [1 / f for f in factors]
out = ndi.zoom(
filtered, zoom_factors, order=order, mode=ndi_mode, cval=cval, grid_mode=True
)
_clip_warp_output(image, out, mode, cval, clip)
return out

View File

@@ -0,0 +1,600 @@
import warnings
from warnings import warn
import numpy as np
__all__ = [
'img_as_float32',
'img_as_float64',
'img_as_float',
'img_as_int',
'img_as_uint',
'img_as_ubyte',
'img_as_bool',
'dtype_limits',
]
# Some of these may or may not be aliases depending on architecture & platform
_integer_types = (
np.int8,
np.byte,
np.int16,
np.short,
np.int32,
np.int64,
np.longlong,
np.int_,
np.intp,
np.intc,
int,
np.uint8,
np.ubyte,
np.uint16,
np.ushort,
np.uint32,
np.uint64,
np.ulonglong,
np.uint,
np.uintp,
np.uintc,
)
_integer_ranges = {t: (np.iinfo(t).min, np.iinfo(t).max) for t in _integer_types}
dtype_range = {
bool: (False, True),
np.bool_: (False, True),
float: (-1, 1),
np.float16: (-1, 1),
np.float32: (-1, 1),
np.float64: (-1, 1),
}
with warnings.catch_warnings():
warnings.filterwarnings('ignore', category=DeprecationWarning)
# np.bool8 is a deprecated alias of np.bool_
if hasattr(np, 'bool8'):
dtype_range[np.bool8] = (False, True)
dtype_range.update(_integer_ranges)
_supported_types = list(dtype_range.keys())
def dtype_limits(image, clip_negative=False):
"""Return intensity limits, i.e. (min, max) tuple, of the image's dtype.
Parameters
----------
image : ndarray
Input image.
clip_negative : bool, optional
If True, clip the negative range (i.e. return 0 for min intensity)
even if the image dtype allows negative values.
Returns
-------
imin, imax : tuple
Lower and upper intensity limits.
"""
imin, imax = dtype_range[image.dtype.type]
if clip_negative:
imin = 0
return imin, imax
def _dtype_itemsize(itemsize, *dtypes):
"""Return first of `dtypes` with itemsize greater than `itemsize`
Parameters
----------
itemsize: int
The data type object element size.
Other Parameters
----------------
*dtypes:
Any Object accepted by `np.dtype` to be converted to a data
type object
Returns
-------
dtype: data type object
First of `dtypes` with itemsize greater than `itemsize`.
"""
return next(dt for dt in dtypes if np.dtype(dt).itemsize >= itemsize)
def _dtype_bits(kind, bits, itemsize=1):
"""Return dtype of `kind` that can store a `bits` wide unsigned int
Parameters:
kind: str
Data type kind.
bits: int
Desired number of bits.
itemsize: int
The data type object element size.
Returns
-------
dtype: data type object
Data type of `kind` that can store a `bits` wide unsigned int
"""
s = next(
i
for i in (itemsize,) + (2, 4, 8)
if bits < (i * 8) or (bits == (i * 8) and kind == 'u')
)
return np.dtype(kind + str(s))
def _scale(a, n, m, copy=True):
"""Scale an array of unsigned/positive integers from `n` to `m` bits.
Numbers can be represented exactly only if `m` is a multiple of `n`.
Parameters
----------
a : ndarray
Input image array.
n : int
Number of bits currently used to encode the values in `a`.
m : int
Desired number of bits to encode the values in `out`.
copy : bool, optional
If True, allocates and returns new array. Otherwise, modifies
`a` in place.
Returns
-------
out : array
Output image array. Has the same kind as `a`.
"""
kind = a.dtype.kind
if n > m and a.max() < 2**m:
mnew = int(np.ceil(m / 2) * 2)
if mnew > m:
dtype = f'int{mnew}'
else:
dtype = f'uint{mnew}'
n = int(np.ceil(n / 2) * 2)
warn(
f'Downcasting {a.dtype} to {dtype} without scaling because max '
f'value {a.max()} fits in {dtype}',
stacklevel=3,
)
return a.astype(_dtype_bits(kind, m))
elif n == m:
return a.copy() if copy else a
elif n > m:
# downscale with precision loss
if copy:
b = np.empty(a.shape, _dtype_bits(kind, m))
np.floor_divide(a, 2 ** (n - m), out=b, dtype=a.dtype, casting='unsafe')
return b
else:
a //= 2 ** (n - m)
return a
elif m % n == 0:
# exact upscale to a multiple of `n` bits
if copy:
b = np.empty(a.shape, _dtype_bits(kind, m))
np.multiply(a, (2**m - 1) // (2**n - 1), out=b, dtype=b.dtype)
return b
else:
a = a.astype(_dtype_bits(kind, m, a.dtype.itemsize), copy=False)
a *= (2**m - 1) // (2**n - 1)
return a
else:
# upscale to a multiple of `n` bits,
# then downscale with precision loss
o = (m // n + 1) * n
if copy:
b = np.empty(a.shape, _dtype_bits(kind, o))
np.multiply(a, (2**o - 1) // (2**n - 1), out=b, dtype=b.dtype)
b //= 2 ** (o - m)
return b
else:
a = a.astype(_dtype_bits(kind, o, a.dtype.itemsize), copy=False)
a *= (2**o - 1) // (2**n - 1)
a //= 2 ** (o - m)
return a
def _convert(image, dtype, force_copy=False, uniform=False):
"""
Convert an image to the requested data-type.
Warnings are issued in case of precision loss, or when negative values
are clipped during conversion to unsigned integer types (sign loss).
Floating point values are expected to be normalized and will be clipped
to the range [0.0, 1.0] or [-1.0, 1.0] when converting to unsigned or
signed integers respectively.
Numbers are not shifted to the negative side when converting from
unsigned to signed integer types. Negative values will be clipped when
converting to unsigned integers.
Parameters
----------
image : ndarray
Input image.
dtype : dtype
Target data-type.
force_copy : bool, optional
Force a copy of the data, irrespective of its current dtype.
uniform : bool, optional
Uniformly quantize the floating point range to the integer range.
By default (uniform=False) floating point values are scaled and
rounded to the nearest integers, which minimizes back and forth
conversion errors.
.. versionchanged:: 0.15
``_convert`` no longer warns about possible precision or sign
information loss. See discussions on these warnings at:
https://github.com/scikit-image/scikit-image/issues/2602
https://github.com/scikit-image/scikit-image/issues/543#issuecomment-208202228
https://github.com/scikit-image/scikit-image/pull/3575
References
----------
.. [1] DirectX data conversion rules.
https://msdn.microsoft.com/en-us/library/windows/desktop/dd607323%28v=vs.85%29.aspx
.. [2] Data Conversions. In "OpenGL ES 2.0 Specification v2.0.25",
pp 7-8. Khronos Group, 2010.
.. [3] Proper treatment of pixels as integers. A.W. Paeth.
In "Graphics Gems I", pp 249-256. Morgan Kaufmann, 1990.
.. [4] Dirty Pixels. J. Blinn. In "Jim Blinn's corner: Dirty Pixels",
pp 47-57. Morgan Kaufmann, 1998.
"""
image = np.asarray(image)
dtypeobj_in = image.dtype
if dtype is np.floating:
dtypeobj_out = np.dtype('float64')
else:
dtypeobj_out = np.dtype(dtype)
dtype_in = dtypeobj_in.type
dtype_out = dtypeobj_out.type
kind_in = dtypeobj_in.kind
kind_out = dtypeobj_out.kind
itemsize_in = dtypeobj_in.itemsize
itemsize_out = dtypeobj_out.itemsize
# Below, we do an `issubdtype` check. Its purpose is to find out
# whether we can get away without doing any image conversion. This happens
# when:
#
# - the output and input dtypes are the same or
# - when the output is specified as a type, and the input dtype
# is a subclass of that type (e.g. `np.floating` will allow
# `float32` and `float64` arrays through)
if np.issubdtype(dtype_in, dtype):
if force_copy:
image = image.copy()
return image
if not (dtype_in in _supported_types and dtype_out in _supported_types):
raise ValueError(f'Cannot convert from {dtypeobj_in} to ' f'{dtypeobj_out}.')
if kind_in in 'ui':
imin_in = np.iinfo(dtype_in).min
imax_in = np.iinfo(dtype_in).max
if kind_out in 'ui':
imin_out = np.iinfo(dtype_out).min
imax_out = np.iinfo(dtype_out).max
# any -> binary
if kind_out == 'b':
return image > dtype_in(dtype_range[dtype_in][1] / 2)
# binary -> any
if kind_in == 'b':
result = image.astype(dtype_out)
if kind_out != 'f':
result *= dtype_out(dtype_range[dtype_out][1])
return result
# float -> any
if kind_in == 'f':
if kind_out == 'f':
# float -> float
return image.astype(dtype_out)
if np.min(image) < -1.0 or np.max(image) > 1.0:
raise ValueError("Images of type float must be between -1 and 1.")
# floating point -> integer
# use float type that can represent output integer type
computation_type = _dtype_itemsize(
itemsize_out, dtype_in, np.float32, np.float64
)
if not uniform:
if kind_out == 'u':
image_out = np.multiply(image, imax_out, dtype=computation_type)
else:
image_out = np.multiply(
image, (imax_out - imin_out) / 2, dtype=computation_type
)
image_out -= 1.0 / 2.0
np.rint(image_out, out=image_out)
np.clip(image_out, imin_out, imax_out, out=image_out)
elif kind_out == 'u':
image_out = np.multiply(image, imax_out + 1, dtype=computation_type)
np.clip(image_out, 0, imax_out, out=image_out)
else:
image_out = np.multiply(
image, (imax_out - imin_out + 1.0) / 2.0, dtype=computation_type
)
np.floor(image_out, out=image_out)
np.clip(image_out, imin_out, imax_out, out=image_out)
return image_out.astype(dtype_out)
# signed/unsigned int -> float
if kind_out == 'f':
# use float type that can exactly represent input integers
computation_type = _dtype_itemsize(
itemsize_in, dtype_out, np.float32, np.float64
)
if kind_in == 'u':
# using np.divide or np.multiply doesn't copy the data
# until the computation time
image = np.multiply(image, 1.0 / imax_in, dtype=computation_type)
# DirectX uses this conversion also for signed ints
# if imin_in:
# np.maximum(image, -1.0, out=image)
elif kind_in == 'i':
# From DirectX conversions:
# The most negative value maps to -1.0f
# Every other value is converted to a float (call it c)
# and then result = c * (1.0f / (2⁽ⁿ⁻¹⁾-1)).
image = np.multiply(image, 1.0 / imax_in, dtype=computation_type)
np.maximum(image, -1.0, out=image)
else:
image = np.add(image, 0.5, dtype=computation_type)
image *= 2 / (imax_in - imin_in)
return np.asarray(image, dtype_out)
# unsigned int -> signed/unsigned int
if kind_in == 'u':
if kind_out == 'i':
# unsigned int -> signed int
image = _scale(image, 8 * itemsize_in, 8 * itemsize_out - 1)
return image.view(dtype_out)
else:
# unsigned int -> unsigned int
return _scale(image, 8 * itemsize_in, 8 * itemsize_out)
# signed int -> unsigned int
if kind_out == 'u':
image = _scale(image, 8 * itemsize_in - 1, 8 * itemsize_out)
result = np.empty(image.shape, dtype_out)
np.maximum(image, 0, out=result, dtype=image.dtype, casting='unsafe')
return result
# signed int -> signed int
if itemsize_in > itemsize_out:
return _scale(image, 8 * itemsize_in - 1, 8 * itemsize_out - 1)
image = image.astype(_dtype_bits('i', itemsize_out * 8))
image -= imin_in
image = _scale(image, 8 * itemsize_in, 8 * itemsize_out, copy=False)
image += imin_out
return image.astype(dtype_out)
def convert(image, dtype, force_copy=False, uniform=False):
warn(
"The use of this function is discouraged as its behavior may change "
"dramatically in scikit-image 1.0. This function will be removed "
"in scikit-image 1.0.",
FutureWarning,
stacklevel=2,
)
return _convert(image=image, dtype=dtype, force_copy=force_copy, uniform=uniform)
if _convert.__doc__ is not None:
convert.__doc__ = (
_convert.__doc__
+ """
Warns
-----
FutureWarning:
.. versionadded:: 0.17
The use of this function is discouraged as its behavior may change
dramatically in scikit-image 1.0. This function will be removed
in scikit-image 1.0.
"""
)
def img_as_float32(image, force_copy=False):
"""Convert an image to single-precision (32-bit) floating point format.
Parameters
----------
image : ndarray
Input image.
force_copy : bool, optional
Force a copy of the data, irrespective of its current dtype.
Returns
-------
out : ndarray of float32
Output image.
Notes
-----
The range of a floating point image is [0.0, 1.0] or [-1.0, 1.0] when
converting from unsigned or signed datatypes, respectively.
If the input image has a float type, intensity values are not modified
and can be outside the ranges [0.0, 1.0] or [-1.0, 1.0].
"""
return _convert(image, np.float32, force_copy)
def img_as_float64(image, force_copy=False):
"""Convert an image to double-precision (64-bit) floating point format.
Parameters
----------
image : ndarray
Input image.
force_copy : bool, optional
Force a copy of the data, irrespective of its current dtype.
Returns
-------
out : ndarray of float64
Output image.
Notes
-----
The range of a floating point image is [0.0, 1.0] or [-1.0, 1.0] when
converting from unsigned or signed datatypes, respectively.
If the input image has a float type, intensity values are not modified
and can be outside the ranges [0.0, 1.0] or [-1.0, 1.0].
"""
return _convert(image, np.float64, force_copy)
def img_as_float(image, force_copy=False):
"""Convert an image to floating point format.
This function is similar to `img_as_float64`, but will not convert
lower-precision floating point arrays to `float64`.
Parameters
----------
image : ndarray
Input image.
force_copy : bool, optional
Force a copy of the data, irrespective of its current dtype.
Returns
-------
out : ndarray of float
Output image.
Notes
-----
The range of a floating point image is [0.0, 1.0] or [-1.0, 1.0] when
converting from unsigned or signed datatypes, respectively.
If the input image has a float type, intensity values are not modified
and can be outside the ranges [0.0, 1.0] or [-1.0, 1.0].
"""
return _convert(image, np.floating, force_copy)
def img_as_uint(image, force_copy=False):
"""Convert an image to 16-bit unsigned integer format.
Parameters
----------
image : ndarray
Input image.
force_copy : bool, optional
Force a copy of the data, irrespective of its current dtype.
Returns
-------
out : ndarray of uint16
Output image.
Notes
-----
Negative input values will be clipped.
Positive values are scaled between 0 and 65535.
"""
return _convert(image, np.uint16, force_copy)
def img_as_int(image, force_copy=False):
"""Convert an image to 16-bit signed integer format.
Parameters
----------
image : ndarray
Input image.
force_copy : bool, optional
Force a copy of the data, irrespective of its current dtype.
Returns
-------
out : ndarray of int16
Output image.
Notes
-----
The values are scaled between -32768 and 32767.
If the input data-type is positive-only (e.g., uint8), then
the output image will still only have positive values.
"""
return _convert(image, np.int16, force_copy)
def img_as_ubyte(image, force_copy=False):
"""Convert an image to 8-bit unsigned integer format.
Parameters
----------
image : ndarray
Input image.
force_copy : bool, optional
Force a copy of the data, irrespective of its current dtype.
Returns
-------
out : ndarray of ubyte (uint8)
Output image.
Notes
-----
Negative input values will be clipped.
Positive values are scaled between 0 and 255.
"""
return _convert(image, np.uint8, force_copy)
def img_as_bool(image, force_copy=False):
"""Convert an image to boolean format.
Parameters
----------
image : ndarray
Input image.
force_copy : bool, optional
Force a copy of the data, irrespective of its current dtype.
Returns
-------
out : ndarray of bool (`bool_`)
Output image.
Notes
-----
The upper half of the input dtype's positive range is True, and the lower
half is False. All negative values (if present) are False.
"""
return _convert(image, bool, force_copy)

View File

@@ -1,5 +1,8 @@
import bpy import bpy
import mathutils import mathutils
from pathlib import Path
import pyopenvdb as vdb
from uuid import uuid4
def get_type(cls): def get_type(cls):
@@ -9,6 +12,7 @@ def get_type(cls):
def get_node_by_type(nodes, type_name: str): def get_node_by_type(nodes, type_name: str):
return [node for node in nodes if get_type(node) == type_name] return [node for node in nodes if get_type(node) == type_name]
def show_message(message="", title="Message Box", icon='INFO'): def show_message(message="", title="Message Box", icon='INFO'):
def draw(self, context): def draw(self, context):
@@ -67,33 +71,82 @@ def calc_bbox_verts(origin, size):
return bbox_verts return bbox_verts
def get_bioxels_obj(current_obj): def lock_transform(obj):
bioxels_obj = None obj.lock_location[0] = True
if current_obj.get('bioxels_container'): obj.lock_location[1] = True
bioxels_values = [] obj.lock_location[2] = True
obj.lock_rotation[0] = True
obj.lock_rotation[1] = True
obj.lock_rotation[2] = True
obj.lock_scale[0] = True
obj.lock_scale[1] = True
obj.lock_scale[2] = True
def hide_in_ray(obj):
obj.visible_camera = False
obj.visible_diffuse = False
obj.visible_glossy = False
obj.visible_transmission = False
obj.visible_volume_scatter = False
obj.visible_shadow = False
def save_vdb(grids, context):
preferences = context.preferences.addons[__package__].preferences
cache_dir = Path(preferences.cache_dir, 'VDBs')
cache_dir.mkdir(parents=True, exist_ok=True)
vdb_path = Path(cache_dir, f"{uuid4()}.vdb")
print(f"Storing the VDB file ({str(vdb_path)})...")
vdb.write(str(vdb_path), grids=grids)
return vdb_path
def get_container_from_selection():
containers = []
for obj in bpy.context.selected_objects:
if get_container(obj):
containers.append(obj)
return containers
def get_container(current_obj):
if current_obj:
if current_obj.get('bioxel_container'):
return current_obj
elif current_obj.get('bioxel_layer'):
parent = current_obj.parent
return parent if parent.get('bioxel_container') else None
return None
def get_layer(current_obj):
if current_obj:
if current_obj.get('bioxel_layer') and current_obj.parent:
if current_obj.parent.get('bioxel_container'):
return current_obj
return None
def get_container_layers(container):
layers = []
for obj in bpy.data.objects: for obj in bpy.data.objects:
if obj.parent == current_obj and obj.get('bioxels'): if obj.parent == container and get_layer(obj):
bioxels_values.append(obj) layers.append(obj)
if len(bioxels_values) > 0: return layers
bioxels_obj = bioxels_values[0]
elif current_obj.get('bioxels') and current_obj.parent:
if current_obj.parent.get('bioxels_container'):
bioxels_obj = current_obj
return bioxels_obj
def get_all_bioxels_objs(): def get_all_layers():
bioxels_objs = [] layers = []
for obj in bpy.data.objects: for obj in bpy.data.objects:
if obj.parent: if get_layer(obj):
if obj.parent.get('bioxels_container') and obj.get('bioxels'): layers.append(obj)
bioxels_objs.append(obj)
return list(set(bioxels_objs)) return layers
def get_text_index_str(text): def get_text_index_str(text):

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 220 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 50 KiB

BIN
docs/assets/cover.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 MiB

View File

Before

Width:  |  Height:  |  Size: 9.1 KiB

After

Width:  |  Height:  |  Size: 9.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 148 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 423 KiB

View File

Before

Width:  |  Height:  |  Size: 8.6 KiB

After

Width:  |  Height:  |  Size: 8.6 KiB

View File

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 19 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 126 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 126 KiB

View File

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 96 KiB

View File

Before

Width:  |  Height:  |  Size: 252 KiB

After

Width:  |  Height:  |  Size: 252 KiB

View File

Before

Width:  |  Height:  |  Size: 770 KiB

After

Width:  |  Height:  |  Size: 770 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 44 KiB

BIN
docs/assets/nodes_bake.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 174 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 45 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 66 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 71 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 77 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 81 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 75 KiB

BIN
docs/assets/nodes_cut.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 45 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 140 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 62 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 57 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 96 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 86 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 53 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 41 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 75 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 75 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 75 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 108 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 17 KiB

View File

@@ -1,45 +1,81 @@
# Features & Options # Features & Options
## Import Volume Data as Biovels ## Bioxel Design Concept
File > Import > Volume Data as Biovels According to Bioxel design concept, Bioxel Nodes imports volume data and put it into a **Container** as a **Layer**. One container may has more than one layer, and each layer stores the information of different fields under the same location, which is similar to the view layers in map app, except that here it is in 3D space. In order to render the volume the way we want it to, we need to build renderable objects from layers. We call those objects **Component**. The following diagram shows the relationship of **Container**, **Layer**, and **Component**:
![alt text](assets/features_concept.png)
Bioxel Nodes staging the layer as an openvdb file. The process of building from layers to a component is taking place in blender geometry nodes graph with blender native geometry nodes. Therefore, **the blender file works without Bioxel Nodes.**
## Container Structure
In Blender, container structure is like this:
```bash
Case_0000 # Container
|-- Case_0000_CT # Layer
|-- Case_0000_Label_1 # Layer
`-- Case_0000_Label_2 # Layer
```
The container also stores the build process in geometry nodes:
![alt text](assets/features_container.png)
The layer is categorized into these by data type:
- Scalar
- Label
- Vector (Not implemented yet)
- Color (Not implemented yet)
## First Time Import Volume Data
File > Import > Volume Data as Bioxel Layer
### Resample ### Resample
![alt text](assets/resample.png) ![alt text](assets/features_resample.png)
Sometimes the original data is too big, or the spacing in the original data is not reasonable, you can modify the `Bioxel Size` and `Original Spacing` to adjust the Shape of the Bixoels. Sometimes the original data is too big, or the spacing in the original data is not reasonable, you can modify the `Bioxel Size` and `Original Spacing` to adjust the Shape of the layer.
A bioxel is like a pixel, the larger the `Bioxel Size`, the lower the resolution of the image, Original Spacing will be read from the original data record, but sometimes the image doesn't have original spacing, you may need to input it manually to get the correct shape. A bioxel is like a pixel, the larger the `Bioxel Size`, the lower the resolution of the image, Original Spacing will be read from the original data record, but sometimes the image doesn't have original spacing, you may need to input it manually to get the correct shape.
### Read as ### Read as
#### as Scalar - as Scalar
![alt text](assets/as-scalar.png) ![alt text](assets/features_as-scalar.png)
In some cases the environment value is higher than the value of the target object, you can check `Invert Scalar` to adjust the value for better result. In some cases the environment value is higher than the value of the target object, you can check `Invert Scalar` to adjust the value for better result.
#### as Labels - as Labels
![alt text](assets/as-labels.png) Many AI segmentation task datasets, provide segmentation data, which are often an integer value representing a layer of segmentation labels. You can set it to `Labels` to load them.
Many AI segmentation task datasets, provide segmentation data, which are often an integer value representing a layer of segmentation labels. You can set the Label Index to determine exactly which labels to load. - _as Vector (Not implemented yet)_
#### as Vector (Not implemented) - _as Color (Not implemented yet)_
#### as Color (Not implemented)
### Others ### Others
![alt text](assets/import-others.png) ![alt text](assets/features_import-others.png)
## Convert Bioxels to Mesh `Scene Scale` determines how many units of length in the Blender world correspond to one unit of length in the Bioxel world. Since Blender defaults to meters, and the default size of blender primitives are around 1 blender unit. Therefore `Scene Scale` set to 0.01 is appropriate.
In 3D view, select bioxels and right-click, Bioxels > Bioxels To Mesh `Orient to RAS` determines whether the layer should be converted to the RAS coordinate system. Regardless of the format of the medical image data, the coordinate system is mostly the LPS coordinate system. Bioxel, however, are in the RAS coordinate system and therefore need to be transformed in most cases.
![alt text](assets/to-mesh.png) ## Adding Volume Data to an existing container
## Export Biovels as VDB In 3D view or outliner panel, select the container and right click, Bioxel Nodes > Add Volume Data to Container.
The import settings are the same as for the first time import.
File > Export > Biovels as VDB ## Convert Bioxel Components to Mesh
In 3D view or outliner panel, select the container and right click, Bioxel Nodes > Bioxel Components To Mesh
Once it has been turned into a mesh model, you can perform any traditional 3D editing operations on it, such as sculpting, boolean, etc.
## Export Biovel Layer as VDB
File > Export > Biovel Layer as VDB

View File

@@ -4,18 +4,31 @@ Currently only support Blender 4.0 or above, make sure you have the correct vers
## Add-on Installation ## Add-on Installation
Download the latest version https://github.com/OmooLab/BioxelNodes/releases/latest #### For Blender 4.2 or higher
In Blender, Edit > Preferences > Add-ons > Install, select the `BioxelNodes_{version}.zip` you just downloaded.
Download the **Extension** version `BioxelNodes_Extension_{version}.zip` from https://github.com/OmooLab/BioxelNodes/releases/latest
In Blender, Edit > Preferences > Extensions > Install from Disk, select the zip file you just downloaded.
Thats it!
> If it cannot be enable, just reboot blender.
#### For Blender 4.0 or 4.1
Download the **Addon** version `BioxelNodes_Addon_{version}.zip` from https://github.com/OmooLab/BioxelNodes/releases/latest
In Blender, Edit > Preferences > Add-ons > Install, select the zip file you just downloaded.
The add-on requires a third-party python dependency called SimpleITK, click `Install SimpleITK` button below to install the dependency. After clicking, blender may get stuck, it is downloading and installing, just wait for a moment. After that, click `Reboot Blender` button. The add-on requires a third-party python dependency called SimpleITK, click `Install SimpleITK` button below to install the dependency. After clicking, blender may get stuck, it is downloading and installing, just wait for a moment. After that, click `Reboot Blender` button.
![dependency](assets/dependency.png) ![dependency](assets/getting-started_dependency.png)
This step may have failed due to network factors, just click "Set PyPI Mirror" to change the mirror. This step may have failed due to network factors, just click "Set PyPI Mirror" to change the mirror.
## Prepare Your Data ## Prepare Your Data
First you need to have your volumetric data ready. If not, you can access open research data from list below: First you need to have your volumetric data ready. If not, you can access open research data from list below.
> Note that just because they are open and available for download does not mean you can use them for anything! Be sure to look at the description of the available scopes from website.
| Source | Object | | Source | Object |
| ------------------------------------------------------------------------------------ | ------------------ | | ------------------------------------------------------------------------------------ | ------------------ |
@@ -30,34 +43,30 @@ First you need to have your volumetric data ready. If not, you can access open r
## Import Volume Data ## Import Volume Data
File > Import > Volume Data as Bioxels, select **one** of the .dcm files and click on "Volume Data as Bioxels" (you can also drag one of the .dcm files directly into the 3D viewport to trigger the import) File > Import > Volume Data as Bioxel Layer, select **one** of the .dcm files and click on "Volume Data as Bioxel Layer" (you can also drag one of the .dcm files directly into the 3D viewport to trigger the import)
![importing](assets/importing.png) ![importing](assets/getting-started_importing.png)
It may take a while to read data. After finishing reading, it will pop up a dialog box It may take a while to read data. After finishing reading, it will pop up a dialog box. Ignore all the options, just click OK (we will tell about these options later).
![import dialog](assets/import-dialog.png) After importing the data, the add-on will automatically add the necessary nodes to build the component. Click on the new created object in outliner, open the geometry nodes panel, set `Threshold` in "Mask by Threshold" node to 200, and then connect a Slime Shader node (Add > Bioxel Nodes > Slime Shader) after it. The node graph should be as following:
Ignore the options, just click OK! ![alt text](assets/getting-started_graph.png)
After importing, the necessary nodes are automatically added, the reconstruction and shader are created. Click select Bioxels Object, and open the Geometry Nodes panel, change the "Threshold" in segment node.
![segment node](assets/segment-node.png)
and then turned on the cycles rendering to directly see the result. and then turned on the cycles rendering to directly see the result.
![result](assets/result.png) ![result](assets/getting-started_result.png)
You can change the "Threshold" to modify the reconstruction model, or change the "Color", "Density" to modify the shader effect. All the parameters are straightforward, you can understand them by changing the values. You can change the "Threshold" to modify the preview model, or change the "Color", "Density" to modify the shader effect. All the parameters are straightforward, you can understand them by changing the values.
## Share Your File ## Share Your File
The VDB cache and the Bioxel nodes are not reachable to computers if you don't save them. If you need to give your blender file to someone else, you will need to perform the following steps: The VDB cache and the Bioxel nodes are not reachable to other computers if you don't save them. If you want to give your blender file to someone else, you will need to perform the following steps first:
1. Save your blender file 1. Save your blender file
2. Click Scene > Bioxels > Save All Bioxels in the Properties panel. 2. Click Scene > Bioxels > Save All Bioxels in the properties panel.
3. Click Scene > Custom Nodes > Save All Custom Nodes under the Properties panel. 3. Click Scene > Custom Nodes > Save All Custom Nodes in the properties panel.
![before sharin](assets/before-sharing.png) ![alt text](assets/getting-started_share-file.png)
After that, both the VDB cache and the Bioxel nodes are stored in relative locations. When you share a file with someone, pack the entire directory so that the resources are not lost. The other person will be able to load correctly, regardless of whether they have BioxelNodes installed. After that, both the VDB cache and the Bioxel nodes are restored in relative locations. When you share this file with someone, pack the entire directory so that the resources will be not lost. The other person will be able to open it correctly, regardless of whether they have Bioxel Nodes installed or not.

View File

@@ -1,5 +1,3 @@
[中文文档](https://uj6xfhbzp0.feishu.cn/wiki/Qx3VwHuNPimeI8kr6nDcvl1DnHf?from=from_copylink)
# Bioxel Nodes # Bioxel Nodes
![Static Badge](https://img.shields.io/badge/Blender-orange?style=for-the-badge&logo=blender&logoColor=white) ![Static Badge](https://img.shields.io/badge/Blender-orange?style=for-the-badge&logo=blender&logoColor=white)
@@ -9,17 +7,17 @@
Bioxel Nodes is a Blender add-on for scientific volumetric data visualization. It using Blender's powerful Geometry Nodes | Cycles to process and render volumetric data. Bioxel Nodes is a Blender add-on for scientific volumetric data visualization. It using Blender's powerful Geometry Nodes | Cycles to process and render volumetric data.
# About ## About
Before us, there have been many tutorials and add-ons for importing volumetric data into Blender. However, we found that there were many details that were not addressed in place, some scientific facts were ignored, and the volume rendering was not pretty enough. With Bioxel Nodes, you can easily import the volumetric data into Blender, and more importantly, it can quickly make a beautiful realistic rendering of it. Before us, there have been many tutorials and add-ons for importing volumetric data into Blender. However, we found that there were many details that were not addressed in place, some scientific facts were ignored, and the volume rendering was not pretty enough. With Bioxel Nodes, you can easily import the volumetric data into Blender, and more importantly, it can quickly make a beautiful realistic rendering of it.
Below are some examples with Bioxel Nodes. Thanks to Cycles Render, the volumetric data can be rendered with great detail: Below are some examples with Bioxel Nodes. Thanks to Cycles Render, the volumetric data can be rendered with great detail:
![gallery](assets/gallery.png) ![cover](assets/cover.png)
The "Bioxel" in "BioxelNodes", is a combination of the words "Bio-" and "Voxel". Bioxel is a voxel that stores biological data. The volumetric data made up of Bioxel is called Bioxels. We are developing a toolkit around Bioxels for better biological data visualization. but before its release, we made this Blender version of bioxels toolkit first, in order to let more people to have fun with volumetric data. [Getting Started](https://omoolab.github.io/BioxelNodes/latest/getting-started) The "Bioxel" in "Bioxel Nodes", is a combination of the words "Bio-" and "Voxel". Bioxel is a voxel that stores biological data. We are developing a toolkit around Bioxel for better biological data visualization. but before its release, we made this Blender version of bioxels toolkit first, in order to let more people to have fun with volumetric data. [Getting Started](https://omoolab.github.io/BioxelNodes/latest/getting-started)
# Supported Format ## Supported Format
| Format | EXT | Test | | Format | EXT | Test |
| ------ | ---------------------------------------- | ------- | | ------ | ---------------------------------------- | ------- |
@@ -39,7 +37,32 @@ The "Bioxel" in "BioxelNodes", is a combination of the words "Bio-" and "Voxel".
| MINC | .mnc, .MNC | yet | | MINC | .mnc, .MNC | yet |
| MRC | .mrc, .rec | yet | | MRC | .mrc, .rec | yet |
# Known limitations ## Known Limitations
- Sections cannot be generated - Sections cannot be generated (will be supported soon)
- Time sequence volume not supported (will be supported soon) - Time sequence volume not supported (will be supported soon)
## To Upgrade Add-on
To upgrade from an older version of the add-on to the latest, you need to do the following:
1. Remove the old version of Bioxel Nodes at Preferences > Add-ons
2. Add the new version and restart Blender.
It is not support editing the same blender file across add-on versions. In order to make sure that the previous file works properly. You need to save the staged data before upgrading ( read the last section of [Getting Started](https://omoolab.github.io/BioxelNodes/latest/getting-started/#share-your-file) ).
But even then, there is still no guarantee that the new version of the add-on will work on the old blender file. Therefore, it is highly recommended to open a new blender file to start the creating, not based on the old one.
Alternatively, objects from the old file that have nothing to do with Bioxel Nodes could be append to the new blender file.
## About EEVEE Render
Bioxel Nodes is designed for Cycles Render. However, it does support eevee render partially. "Solid Shader" node and "Volume Shader" node have a toggle called "EEVEE Render". If you want to render Bioxel Component in real-time, turn it on.
Also, there are some limitations:
1. Only one cutter supported.
2. You cannot use "Color Ramp" over 2 colors.
3. EEVEE Render result is not that great as Cycles does.
> "Volume Shader" node is not work properly in EEVEE Next since 4.2. It is because EEVEE Next is not support attributes from instances of volume shader by now. But the Blender 4.2 docs still say attributes reading is ok, so I suppose this feature will eventually be implemented.

View File

@@ -1,19 +1,391 @@
# Geometry Nodes # Nodes
The node, that named "Segment", is a preset node that combines the steps of 3D reconstruction process and shading process. In general, you need to add one of the segmentation node to reconstruction first, and followed by one of the shader node to set the shader. As you can see in the following figure: ## Nodes Design Concept
![general graph](assets/general-graph.png) In order to build a component, the general process is to first use a "Mask Method" node to build the surface of the component based on its layers, and then connect to a "Assign Shader" node to add the material physical properties. Finally, if you need to cut the cross-section, then connect to a "Cut" node. The whole process is shown in the following diagram
Currently there are 3 types of nodes ![alt text](assets/nodes_concept.png)
- Segmentation nodes, responsible for splitting the volume into a reconstructed model (we call them "Segment"). A typical example looks like this:
- Shader nodes, responsible for giving shader to the Segment.
- Slicer nodes, responsible for partially cutting the Segment.
For example: ![alt text](assets/nodes_example.png)
![general graph example](assets/general-graph-example.png) The "Mask Method" node tends to be very computationally intensive, and if it consumes too much time, then you can bake it with a "Bake" node after it (but you need to save the Blender file first).
You can add a "Bake" node between segmentation node and shader node, if the reconstruction process consumes too much computing time. But be sure, you are selecting the volume object, not the container object. ![alt text](assets/nodes_bake.png)
![bake node](assets/bake-node.png) ## Mask Methods
This type of node is responsible for culling out the extent of the component that does not need to be rendered, forming the interface between the object and the object, or the surface of the object (i.e., the interface between the object and the air)
### ⬆️ Mask by Threshold
<div class="grid cards" markdown>
- ![alt text](assets/nodes_mask-by-threshold.png)
- Generate a mask by keeping only the positions that exceed the threshold (this only works with scalar)
***
Node Parameter:
- **Layer**, _the input scalar_
- **Threshold**, _the threshold value_
- Preview
- **Detail Factor**, _the fineness of the preview, the larger the factor, the coarser preview is_
- (Label Mask)
- **Layer**, _the input label_
- **Invert**, _invert mask_
- **Sample Size**, _the mask sample size_
- (Replacement)
- **Joined**, _the joined layer_
</div>
### ↕ Mask by Range
<div class="grid cards" markdown>
- ![alt text](assets/nodes_mask-by-range.png)
- Generate a mask by keeping only the positions that in range (this only works with scalar)
***
Node Parameter:
- **Layer**, _the input scalar_
- **Fram Min**, _the lower limit_
- **Fram Max**, _the upper limit_
- Preview
- **Detail Factor**, _the fineness of the preview, the larger the factor, the coarser preview is_
- (Label Mask)
- **Layer**, _the input label_
- **Invert**, _invert mask_
- **Sample Size**, _the mask sample size_
- (Replacement)
- **Joined**, _the joined layer_
</div>
### 🔤 Mask by Label
<div class="grid cards" markdown>
- ![alt text](assets/nodes_mask-by-label.png)
- Generate a mask by keeping only the positions that in label (this only works with label)
***
Node Parameter:
- **Layer**, _the input label_
- Preview
- **Detail Factor**, _the fineness of the preview, the larger the factor, the coarser preview is_
- (Replacement)
- **Joined**, _the joined layer_
</div>
## Shaders
This type of node is responsible for setting material physical properties to the component to reflect the differences in rendering effects of different components.
### 🥚 Solid Shader
<div class="grid cards" markdown>
- ![alt text](assets/nodes_solid-shader.png)
- Assign a opaque shader based on a preview mesh with no inclusions visible. Fastest rendering speed. Does not support cross-section and color ramp.
***
Node Parameter:
- **Component**, _the upstream component_
- Base
- **Color**, _albedo or emission color_
- **Subsurface**, _the subsurface scale_
- **Opacity**, _the opacity of all_
- Specular
- **Specular**, _the specular of surface_
- **Roughness**, _the roughness of surface_
- Emission
- **Emission**, _the emission strength_
</div>
### 🦠 Slime Shader
<div class="grid cards" markdown>
- ![alt text](assets/nodes_slime-shader.png)
- Assign a semi-transparent shader based on the preview mesh with visible inclusions. Does not support cross-section and color ramp.
***
Node Parameter:
- **Component**, _the upstream component_
- Base
- **Color**, _albedo or emission color_
- **Density**, _the degree of solidity_
- **Anisotropy**, _the anisotropy of scatting_
- Specular
- **Specular**, _the specular of surface_
- **Roughness**, _the roughness of surface_
- Emission
- **Emission**, _the emission strength_
</div>
### ☁️ Volume Shader
<div class="grid cards" markdown>
- ![alt text](assets/nodes_volume-shader.png)
- Assign a volume-based shader with support for cross-section and color ramp.
***
Node Parameter:
- **Component**, _the upstream component_
- Base
- **Color**, _albedo or emission color_
- **Density**, _the degree of solidity_
- **Anisotropy**, _the anisotropy of scatting_
- Emission
- **Emission**, _the emission strength_
</div>
### 🔬 Universal Shader
<div class="grid cards" markdown>
- ![alt text](assets/nodes_universal-shader.png)
- Assign a ultimate shader, supporting all features of Bioxel Nodes. Of course, the price is slow rendering, which can be greatly improved by adjusting the Volumes > Step Rate to 100 in the Render Settings Panel.
***
Node Parameter:
- **Component**, _the upstream component_
- Base
- **Color**, _albedo or emission color_
- **Density**, _the degree of solidity_
- **Anisotropy**, _the anisotropy of scatting_
- Specular
- **Specular**, _the specular of surface_
- **Roughness**, _the roughness of surface_
- Emission
- **Emission**, _the emission strength_
</div>
## Cutters
This type of node is responsible for cutting components to present cross-section
### 🪚 Cut
<div class="grid cards" markdown>
- ![alt text](assets/nodes_cut.png)
- Execute all cutters on one component.
***
Node Parameter:
- **Component**, _the upstream component_
- **Cutter 0~4**, _the cutters_
- **Hide Guide**, _hide the cutter guide_
</div>
### 🧀 Plane Cutter
<div class="grid cards" markdown>
- ![alt text](assets/nodes_plane-cutter.png)
- Flat plane cutter, cuts off above Z-axis in local.
***
Node Parameter:
- **Origin**, _plane cutter position_
- **Direction**, _plane cutter orientation_
- Guide
- **Show**, _show the cutter guide_
- **Scale**, _scale the cutter guide_
</div>
### 🧀 Plane Object Cutter
<div class="grid cards" markdown>
- ![alt text](assets/nodes_plane-object-cutter.png)
- Also a plane cutter, but origin and direction are based on exist object.
***
Node Parameter:
- **Plane**, _the plane object_
- Guide
- **Show**, _show the cutter guide_
- **Scale**, _scale the cutter guide_
</div>
## Colors
This type of node is responsible for setting the color properties of the shader
### 🎨 Color Presents
<div class="grid cards" markdown>
- ![alt text](assets/nodes_color-presets.png)
- Set color from presets.
***
Node Parameter:
- **Component**, _the upstream component_
- **Presets**, _select color presents_
- **Fram Min**, _ramp factor lower limit_
- **Fram Max**, _ramp factor upper limit_
</div>
### 2️⃣ Color Ramp 2
<div class="grid cards" markdown>
- ![alt text](assets/nodes_color-ramp-2.png)
- Set color ramp base on scalar value.
***
Node Parameter:
- **Component**, _the upstream component_
- **Fram Min**, _ramp factor lower limit_
- **Fram Max**, _ramp factor upper limit_
- Ramp
- **Pos0 Color**, _position 0% Color_
- **Pos1 Color**, _position 100% Color_
- **Gamma**, _non-linear coefficient, the larger the coefficient, the more lower value color_
- **Contrast**, _the larger the contrast, the harder color ramp will be_
</div>
### 3️⃣ Color Ramp 3
<div class="grid cards" markdown>
- ![alt text](assets/nodes_color-ramp-3.png)
- Set color ramp base on scalar value.
***
Node Parameter:
- **Component**, _the upstream component_
- **Fram Min**, _ramp factor lower limit_
- **Fram Max**, _ramp factor upper limit_
- Ramp
- **Pos0 Color**, _position 0% Color_
- **Pos1 Color**, _position 50% Color_
- **Pos2 Color**, _position 100% Color_
- **Gamma**, _non-linear coefficient, the larger the coefficient, the more lower value color_
- **Contrast**, _the larger the contrast, the harder color ramp will be_
</div>
### 4️⃣ Color Ramp 4
<div class="grid cards" markdown>
- ![alt text](assets/nodes_color-ramp-4.png)
- Set color ramp base on scalar value.
***
Node Parameter:
- **Component**, _the upstream component_
- **Fram Min**, _ramp factor lower limit_
- **Fram Max**, _ramp factor upper limit_
- Ramp
- **Pos0 Color**, _position 0% Color_
- **Pos1 Color**, _position 33.3% Color_
- **Pos2 Color**, _position 66.6% Color_
- **Pos3 Color**, _position 100% Color_
- **Gamma**, _non-linear coefficient, the larger the coefficient, the more lower value color_
- **Contrast**, _the larger the contrast, the harder color ramp will be_
</div>
### 5️⃣ Color Ramp 5
<div class="grid cards" markdown>
- ![alt text](assets/nodes_color-ramp-5.png)
- Set color ramp base on scalar value.
***
Node Parameter:
- **Component**, _the upstream component_
- **Fram Min**, _ramp factor lower limit_
- **Fram Max**, _ramp factor upper limit_
- Ramp
- **Pos0 Color**, _position 0% Color_
- **Pos1 Color**, _position 25% Color_
- **Pos2 Color**, _position 50% Color_
- **Pos3 Color**, _position 75% Color_
- **Pos4 Color**, _position 100% Color_
- **Gamma**, _non-linear coefficient, the larger the coefficient, the more lower value color_
- **Contrast**, _the larger the contrast, the harder color ramp will be_
</div>
## Utils
### 📦 Join Component
<div class="grid cards" markdown>
- ![alt text](assets/nodes_join-component.png)
- Components' combination should not be done by "Join Geometry" node because Blender Cycles can't render volumes in the same position, so the node will slightly offset all components randomly to avoid this problem.
***
Node Parameter:
- **Component 0~4**, _the components_
</div>

22
extension/__init__.py Normal file
View File

@@ -0,0 +1,22 @@
import bpy
from . import auto_load
from . import menus
auto_load.init()
def register():
auto_load.register()
menus.add()
bpy.types.Scene.bioxel_layer_dir = bpy.props.StringProperty(
name="Layer Directory",
subtype='DIR_PATH',
default="//"
)
def unregister():
menus.remove()
auto_load.unregister()

View File

@@ -0,0 +1,69 @@
schema_version = "1.0.0"
# Example of manifest file for a Blender extension
# Change the values according to your extension
id = "bioxelnodes"
version = "0.2.4"
name = "Bioxel Nodes"
tagline = "For scientific volumetric data visualization in Blender"
maintainer = "Ma Nan <icrdr2010@outlook.com>"
# Supported types: "add-on", "theme"
type = "add-on"
# Optional link to documentation, support, source files, etc
website = "https://omoolab.github.io/BioxelNodes/latest"
# Optional list defined by Blender and server, see:
# https://docs.blender.org/manual/en/dev/advanced/extensions/tags.html
tags = ["Geometry Nodes", "Render"]
blender_version_min = "4.2.0"
# Optional: maximum supported Blender version
# blender_version_max = "5.1.0"
# License conforming to https://spdx.org/licenses/ (use "SPDX: prefix)
# https://docs.blender.org/manual/en/dev/advanced/extensions/licenses.html
license = [
"SPDX:MIT",
]
# Optional: required by some licenses.
copyright = [
"2024 OmooLab"
]
# Optional list of supported platforms. If omitted, the extension will be available in all operating systems.
platforms = ["windows-x64"]
# Other supported platforms: "windows-arm64", "macos-x64"
# Optional: bundle 3rd party Python modules.
# https://docs.blender.org/manual/en/dev/advanced/extensions/python_wheels.html
wheels = [
"./wheels/SimpleITK-2.3.1-cp311-cp311-win_amd64.whl"
]
## Optional: add-ons can list which resources they will require:
## * files (for access of any filesystem operations)
## * network (for internet access)
## * clipboard (to read and/or write the system clipboard)
## * camera (to capture photos and videos)
## * microphone (to capture audio)
##
## If using network, remember to also check `bpy.app.online_access`
## https://docs.blender.org/manual/en/dev/advanced/extensions/addons.html#internet-access
##
## For each permission it is important to also specify the reason why it is required.
## Keep this a single short sentence without a period (.) at the end.
## For longer explanations use the documentation or detail page.
#
[permissions]
files = "Import/export volume data from/to disk"
# Optional: build settings.
# https://docs.blender.org/manual/en/dev/advanced/extensions/command_line_arguments.html#command-line-args-extension-build
# [build]
# paths_exclude_pattern = [
# "__pycache__/",
# "/.git/",
# "/*.zip",
# ]

23
extension/preferences.py Normal file
View File

@@ -0,0 +1,23 @@
import bpy
from pathlib import Path
class BioxelNodesPreferences(bpy.types.AddonPreferences):
bl_idname = __package__
cache_dir: bpy.props.StringProperty(
name="Set Cache Directory",
subtype='DIR_PATH',
default=str(Path(Path.home(), '.bioxelnodes'))
) # type: ignore
do_change_render_setting: bpy.props.BoolProperty(
name="Change Render Setting",
default=True,
) # type: ignore
def draw(self, context):
layout = self.layout
layout.label(text="Configuration")
layout.prop(self, 'cache_dir')
layout.prop(self, "do_change_render_setting")

View File

@@ -11,7 +11,7 @@ nav:
- index.md - index.md
- Getting Started: getting-started.md - Getting Started: getting-started.md
- Features & Options: features.md - Features & Options: features.md
- Geometry Nodes: nodes.md - Nodes: nodes.md
- Future Features: misc.md - Future Features: misc.md
theme: theme:
@@ -57,6 +57,7 @@ theme:
extra: extra:
version: version:
provider: mike provider: mike
default: latest
extra_css: extra_css:
- stylesheets/extra.css - stylesheets/extra.css
@@ -68,6 +69,8 @@ plugins:
- mkdocstrings - mkdocstrings
markdown_extensions: markdown_extensions:
- attr_list
- md_in_html
- mkdocs-click - mkdocs-click
- admonition - admonition
- pymdownx.highlight: - pymdownx.highlight:

264
poetry.lock generated
View File

@@ -539,6 +539,38 @@ files = [
{file = "idna-3.7.tar.gz", hash = "sha256:028ff3aadf0609c1fd278d8ea3089299412a7a8b9bd005dd08b9f8285bcb5cfc"}, {file = "idna-3.7.tar.gz", hash = "sha256:028ff3aadf0609c1fd278d8ea3089299412a7a8b9bd005dd08b9f8285bcb5cfc"},
] ]
[[package]]
name = "imageio"
version = "2.34.2"
description = "Library for reading and writing a wide range of image, video, scientific, and volumetric data formats."
optional = false
python-versions = ">=3.8"
files = [
{file = "imageio-2.34.2-py3-none-any.whl", hash = "sha256:a0bb27ec9d5bab36a9f4835e51b21d2cb099e1f78451441f94687ff3404b79f8"},
{file = "imageio-2.34.2.tar.gz", hash = "sha256:5c0c0ee8faa018a1c42f649b90395dd4d3bb6187c09053a0cd6f1fdd51bbff5e"},
]
[package.dependencies]
numpy = "*"
pillow = ">=8.3.2"
[package.extras]
all-plugins = ["astropy", "av", "imageio-ffmpeg", "pillow-heif", "psutil", "tifffile"]
all-plugins-pypy = ["av", "imageio-ffmpeg", "pillow-heif", "psutil", "tifffile"]
build = ["wheel"]
dev = ["black", "flake8", "fsspec[github]", "pytest", "pytest-cov"]
docs = ["numpydoc", "pydata-sphinx-theme", "sphinx (<6)"]
ffmpeg = ["imageio-ffmpeg", "psutil"]
fits = ["astropy"]
full = ["astropy", "av", "black", "flake8", "fsspec[github]", "gdal", "imageio-ffmpeg", "itk", "numpydoc", "pillow-heif", "psutil", "pydata-sphinx-theme", "pytest", "pytest-cov", "sphinx (<6)", "tifffile", "wheel"]
gdal = ["gdal"]
itk = ["itk"]
linting = ["black", "flake8"]
pillow-heif = ["pillow-heif"]
pyav = ["av"]
test = ["fsspec[github]", "pytest", "pytest-cov"]
tifffile = ["tifffile"]
[[package]] [[package]]
name = "importlib-metadata" name = "importlib-metadata"
version = "7.1.0" version = "7.1.0"
@@ -733,6 +765,25 @@ traitlets = ">=5.3"
docs = ["myst-parser", "pydata-sphinx-theme", "sphinx-autodoc-typehints", "sphinxcontrib-github-alt", "sphinxcontrib-spelling", "traitlets"] docs = ["myst-parser", "pydata-sphinx-theme", "sphinx-autodoc-typehints", "sphinxcontrib-github-alt", "sphinxcontrib-spelling", "traitlets"]
test = ["ipykernel", "pre-commit", "pytest (<8)", "pytest-cov", "pytest-timeout"] test = ["ipykernel", "pre-commit", "pytest (<8)", "pytest-cov", "pytest-timeout"]
[[package]]
name = "lazy-loader"
version = "0.4"
description = "Makes it easy to load subpackages and functions on demand."
optional = false
python-versions = ">=3.7"
files = [
{file = "lazy_loader-0.4-py3-none-any.whl", hash = "sha256:342aa8e14d543a154047afb4ba8ef17f5563baad3fc610d7b15b213b0f119efc"},
{file = "lazy_loader-0.4.tar.gz", hash = "sha256:47c75182589b91a4e1a85a136c074285a5ad4d9f39c63e0d7fb76391c4574cd1"},
]
[package.dependencies]
packaging = "*"
[package.extras]
dev = ["changelist (==0.5)"]
lint = ["pre-commit (==3.7.0)"]
test = ["pytest (>=7.4)", "pytest-cov (>=4.1)"]
[[package]] [[package]]
name = "markdown" name = "markdown"
version = "3.6" version = "3.6"
@@ -1035,6 +1086,24 @@ files = [
{file = "nest_asyncio-1.6.0.tar.gz", hash = "sha256:6f172d5449aca15afd6c646851f4e31e02c598d553a667e38cafa997cfec55fe"}, {file = "nest_asyncio-1.6.0.tar.gz", hash = "sha256:6f172d5449aca15afd6c646851f4e31e02c598d553a667e38cafa997cfec55fe"},
] ]
[[package]]
name = "networkx"
version = "3.3"
description = "Python package for creating and manipulating graphs and networks"
optional = false
python-versions = ">=3.10"
files = [
{file = "networkx-3.3-py3-none-any.whl", hash = "sha256:28575580c6ebdaf4505b22c6256a2b9de86b316dc63ba9e93abde3d78dfdbcf2"},
{file = "networkx-3.3.tar.gz", hash = "sha256:0c127d8b2f4865f59ae9cb8aafcd60b5c70f3241ebd66f7defad7c4ab90126c9"},
]
[package.extras]
default = ["matplotlib (>=3.6)", "numpy (>=1.23)", "pandas (>=1.4)", "scipy (>=1.9,!=1.11.0,!=1.11.1)"]
developer = ["changelist (==0.5)", "mypy (>=1.1)", "pre-commit (>=3.2)", "rtoml"]
doc = ["myst-nb (>=1.0)", "numpydoc (>=1.7)", "pillow (>=9.4)", "pydata-sphinx-theme (>=0.14)", "sphinx (>=7)", "sphinx-gallery (>=0.14)", "texext (>=0.6.7)"]
extra = ["lxml (>=4.6)", "pydot (>=2.0)", "pygraphviz (>=1.12)", "sympy (>=1.10)"]
test = ["pytest (>=7.2)", "pytest-cov (>=4.0)"]
[[package]] [[package]]
name = "numpy" name = "numpy"
version = "1.26.4" version = "1.26.4"
@@ -1141,6 +1210,92 @@ files = [
[package.dependencies] [package.dependencies]
ptyprocess = ">=0.5" ptyprocess = ">=0.5"
[[package]]
name = "pillow"
version = "10.3.0"
description = "Python Imaging Library (Fork)"
optional = false
python-versions = ">=3.8"
files = [
{file = "pillow-10.3.0-cp310-cp310-macosx_10_10_x86_64.whl", hash = "sha256:90b9e29824800e90c84e4022dd5cc16eb2d9605ee13f05d47641eb183cd73d45"},
{file = "pillow-10.3.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:a2c405445c79c3f5a124573a051062300936b0281fee57637e706453e452746c"},
{file = "pillow-10.3.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:78618cdbccaa74d3f88d0ad6cb8ac3007f1a6fa5c6f19af64b55ca170bfa1edf"},
{file = "pillow-10.3.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:261ddb7ca91fcf71757979534fb4c128448b5b4c55cb6152d280312062f69599"},
{file = "pillow-10.3.0-cp310-cp310-manylinux_2_28_aarch64.whl", hash = "sha256:ce49c67f4ea0609933d01c0731b34b8695a7a748d6c8d186f95e7d085d2fe475"},
{file = "pillow-10.3.0-cp310-cp310-manylinux_2_28_x86_64.whl", hash = "sha256:b14f16f94cbc61215115b9b1236f9c18403c15dd3c52cf629072afa9d54c1cbf"},
{file = "pillow-10.3.0-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:d33891be6df59d93df4d846640f0e46f1a807339f09e79a8040bc887bdcd7ed3"},
{file = "pillow-10.3.0-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:b50811d664d392f02f7761621303eba9d1b056fb1868c8cdf4231279645c25f5"},
{file = "pillow-10.3.0-cp310-cp310-win32.whl", hash = "sha256:ca2870d5d10d8726a27396d3ca4cf7976cec0f3cb706debe88e3a5bd4610f7d2"},
{file = "pillow-10.3.0-cp310-cp310-win_amd64.whl", hash = "sha256:f0d0591a0aeaefdaf9a5e545e7485f89910c977087e7de2b6c388aec32011e9f"},
{file = "pillow-10.3.0-cp310-cp310-win_arm64.whl", hash = "sha256:ccce24b7ad89adb5a1e34a6ba96ac2530046763912806ad4c247356a8f33a67b"},
{file = "pillow-10.3.0-cp311-cp311-macosx_10_10_x86_64.whl", hash = "sha256:5f77cf66e96ae734717d341c145c5949c63180842a545c47a0ce7ae52ca83795"},
{file = "pillow-10.3.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:e4b878386c4bf293578b48fc570b84ecfe477d3b77ba39a6e87150af77f40c57"},
{file = "pillow-10.3.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:fdcbb4068117dfd9ce0138d068ac512843c52295ed996ae6dd1faf537b6dbc27"},
{file = "pillow-10.3.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:9797a6c8fe16f25749b371c02e2ade0efb51155e767a971c61734b1bf6293994"},
{file = "pillow-10.3.0-cp311-cp311-manylinux_2_28_aarch64.whl", hash = "sha256:9e91179a242bbc99be65e139e30690e081fe6cb91a8e77faf4c409653de39451"},
{file = "pillow-10.3.0-cp311-cp311-manylinux_2_28_x86_64.whl", hash = "sha256:1b87bd9d81d179bd8ab871603bd80d8645729939f90b71e62914e816a76fc6bd"},
{file = "pillow-10.3.0-cp311-cp311-musllinux_1_1_aarch64.whl", hash = "sha256:81d09caa7b27ef4e61cb7d8fbf1714f5aec1c6b6c5270ee53504981e6e9121ad"},
{file = "pillow-10.3.0-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:048ad577748b9fa4a99a0548c64f2cb8d672d5bf2e643a739ac8faff1164238c"},
{file = "pillow-10.3.0-cp311-cp311-win32.whl", hash = "sha256:7161ec49ef0800947dc5570f86568a7bb36fa97dd09e9827dc02b718c5643f09"},
{file = "pillow-10.3.0-cp311-cp311-win_amd64.whl", hash = "sha256:8eb0908e954d093b02a543dc963984d6e99ad2b5e36503d8a0aaf040505f747d"},
{file = "pillow-10.3.0-cp311-cp311-win_arm64.whl", hash = "sha256:4e6f7d1c414191c1199f8996d3f2282b9ebea0945693fb67392c75a3a320941f"},
{file = "pillow-10.3.0-cp312-cp312-macosx_10_10_x86_64.whl", hash = "sha256:e46f38133e5a060d46bd630faa4d9fa0202377495df1f068a8299fd78c84de84"},
{file = "pillow-10.3.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:50b8eae8f7334ec826d6eeffaeeb00e36b5e24aa0b9df322c247539714c6df19"},
{file = "pillow-10.3.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:9d3bea1c75f8c53ee4d505c3e67d8c158ad4df0d83170605b50b64025917f338"},
{file = "pillow-10.3.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:19aeb96d43902f0a783946a0a87dbdad5c84c936025b8419da0a0cd7724356b1"},
{file = "pillow-10.3.0-cp312-cp312-manylinux_2_28_aarch64.whl", hash = "sha256:74d28c17412d9caa1066f7a31df8403ec23d5268ba46cd0ad2c50fb82ae40462"},
{file = "pillow-10.3.0-cp312-cp312-manylinux_2_28_x86_64.whl", hash = "sha256:ff61bfd9253c3915e6d41c651d5f962da23eda633cf02262990094a18a55371a"},
{file = "pillow-10.3.0-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:d886f5d353333b4771d21267c7ecc75b710f1a73d72d03ca06df49b09015a9ef"},
{file = "pillow-10.3.0-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:4b5ec25d8b17217d635f8935dbc1b9aa5907962fae29dff220f2659487891cd3"},
{file = "pillow-10.3.0-cp312-cp312-win32.whl", hash = "sha256:51243f1ed5161b9945011a7360e997729776f6e5d7005ba0c6879267d4c5139d"},
{file = "pillow-10.3.0-cp312-cp312-win_amd64.whl", hash = "sha256:412444afb8c4c7a6cc11a47dade32982439925537e483be7c0ae0cf96c4f6a0b"},
{file = "pillow-10.3.0-cp312-cp312-win_arm64.whl", hash = "sha256:798232c92e7665fe82ac085f9d8e8ca98826f8e27859d9a96b41d519ecd2e49a"},
{file = "pillow-10.3.0-cp38-cp38-macosx_10_10_x86_64.whl", hash = "sha256:4eaa22f0d22b1a7e93ff0a596d57fdede2e550aecffb5a1ef1106aaece48e96b"},
{file = "pillow-10.3.0-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:cd5e14fbf22a87321b24c88669aad3a51ec052eb145315b3da3b7e3cc105b9a2"},
{file = "pillow-10.3.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:1530e8f3a4b965eb6a7785cf17a426c779333eb62c9a7d1bbcf3ffd5bf77a4aa"},
{file = "pillow-10.3.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:5d512aafa1d32efa014fa041d38868fda85028e3f930a96f85d49c7d8ddc0383"},
{file = "pillow-10.3.0-cp38-cp38-manylinux_2_28_aarch64.whl", hash = "sha256:339894035d0ede518b16073bdc2feef4c991ee991a29774b33e515f1d308e08d"},
{file = "pillow-10.3.0-cp38-cp38-manylinux_2_28_x86_64.whl", hash = "sha256:aa7e402ce11f0885305bfb6afb3434b3cd8f53b563ac065452d9d5654c7b86fd"},
{file = "pillow-10.3.0-cp38-cp38-musllinux_1_1_aarch64.whl", hash = "sha256:0ea2a783a2bdf2a561808fe4a7a12e9aa3799b701ba305de596bc48b8bdfce9d"},
{file = "pillow-10.3.0-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:c78e1b00a87ce43bb37642c0812315b411e856a905d58d597750eb79802aaaa3"},
{file = "pillow-10.3.0-cp38-cp38-win32.whl", hash = "sha256:72d622d262e463dfb7595202d229f5f3ab4b852289a1cd09650362db23b9eb0b"},
{file = "pillow-10.3.0-cp38-cp38-win_amd64.whl", hash = "sha256:2034f6759a722da3a3dbd91a81148cf884e91d1b747992ca288ab88c1de15999"},
{file = "pillow-10.3.0-cp39-cp39-macosx_10_10_x86_64.whl", hash = "sha256:2ed854e716a89b1afcedea551cd85f2eb2a807613752ab997b9974aaa0d56936"},
{file = "pillow-10.3.0-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:dc1a390a82755a8c26c9964d457d4c9cbec5405896cba94cf51f36ea0d855002"},
{file = "pillow-10.3.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:4203efca580f0dd6f882ca211f923168548f7ba334c189e9eab1178ab840bf60"},
{file = "pillow-10.3.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:3102045a10945173d38336f6e71a8dc71bcaeed55c3123ad4af82c52807b9375"},
{file = "pillow-10.3.0-cp39-cp39-manylinux_2_28_aarch64.whl", hash = "sha256:6fb1b30043271ec92dc65f6d9f0b7a830c210b8a96423074b15c7bc999975f57"},
{file = "pillow-10.3.0-cp39-cp39-manylinux_2_28_x86_64.whl", hash = "sha256:1dfc94946bc60ea375cc39cff0b8da6c7e5f8fcdc1d946beb8da5c216156ddd8"},
{file = "pillow-10.3.0-cp39-cp39-musllinux_1_1_aarch64.whl", hash = "sha256:b09b86b27a064c9624d0a6c54da01c1beaf5b6cadfa609cf63789b1d08a797b9"},
{file = "pillow-10.3.0-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:d3b2348a78bc939b4fed6552abfd2e7988e0f81443ef3911a4b8498ca084f6eb"},
{file = "pillow-10.3.0-cp39-cp39-win32.whl", hash = "sha256:45ebc7b45406febf07fef35d856f0293a92e7417ae7933207e90bf9090b70572"},
{file = "pillow-10.3.0-cp39-cp39-win_amd64.whl", hash = "sha256:0ba26351b137ca4e0db0342d5d00d2e355eb29372c05afd544ebf47c0956ffeb"},
{file = "pillow-10.3.0-cp39-cp39-win_arm64.whl", hash = "sha256:50fd3f6b26e3441ae07b7c979309638b72abc1a25da31a81a7fbd9495713ef4f"},
{file = "pillow-10.3.0-pp310-pypy310_pp73-macosx_10_10_x86_64.whl", hash = "sha256:6b02471b72526ab8a18c39cb7967b72d194ec53c1fd0a70b050565a0f366d355"},
{file = "pillow-10.3.0-pp310-pypy310_pp73-macosx_11_0_arm64.whl", hash = "sha256:8ab74c06ffdab957d7670c2a5a6e1a70181cd10b727cd788c4dd9005b6a8acd9"},
{file = "pillow-10.3.0-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:048eeade4c33fdf7e08da40ef402e748df113fd0b4584e32c4af74fe78baaeb2"},
{file = "pillow-10.3.0-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:9e2ec1e921fd07c7cda7962bad283acc2f2a9ccc1b971ee4b216b75fad6f0463"},
{file = "pillow-10.3.0-pp310-pypy310_pp73-manylinux_2_28_aarch64.whl", hash = "sha256:4c8e73e99da7db1b4cad7f8d682cf6abad7844da39834c288fbfa394a47bbced"},
{file = "pillow-10.3.0-pp310-pypy310_pp73-manylinux_2_28_x86_64.whl", hash = "sha256:16563993329b79513f59142a6b02055e10514c1a8e86dca8b48a893e33cf91e3"},
{file = "pillow-10.3.0-pp310-pypy310_pp73-win_amd64.whl", hash = "sha256:dd78700f5788ae180b5ee8902c6aea5a5726bac7c364b202b4b3e3ba2d293170"},
{file = "pillow-10.3.0-pp39-pypy39_pp73-macosx_10_10_x86_64.whl", hash = "sha256:aff76a55a8aa8364d25400a210a65ff59d0168e0b4285ba6bf2bd83cf675ba32"},
{file = "pillow-10.3.0-pp39-pypy39_pp73-macosx_11_0_arm64.whl", hash = "sha256:b7bc2176354defba3edc2b9a777744462da2f8e921fbaf61e52acb95bafa9828"},
{file = "pillow-10.3.0-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:793b4e24db2e8742ca6423d3fde8396db336698c55cd34b660663ee9e45ed37f"},
{file = "pillow-10.3.0-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d93480005693d247f8346bc8ee28c72a2191bdf1f6b5db469c096c0c867ac015"},
{file = "pillow-10.3.0-pp39-pypy39_pp73-manylinux_2_28_aarch64.whl", hash = "sha256:c83341b89884e2b2e55886e8fbbf37c3fa5efd6c8907124aeb72f285ae5696e5"},
{file = "pillow-10.3.0-pp39-pypy39_pp73-manylinux_2_28_x86_64.whl", hash = "sha256:1a1d1915db1a4fdb2754b9de292642a39a7fb28f1736699527bb649484fb966a"},
{file = "pillow-10.3.0-pp39-pypy39_pp73-win_amd64.whl", hash = "sha256:a0eaa93d054751ee9964afa21c06247779b90440ca41d184aeb5d410f20ff591"},
{file = "pillow-10.3.0.tar.gz", hash = "sha256:9d2455fbf44c914840c793e89aa82d0e1763a14253a000743719ae5946814b2d"},
]
[package.extras]
docs = ["furo", "olefile", "sphinx (>=2.4)", "sphinx-copybutton", "sphinx-inline-tabs", "sphinx-removed-in", "sphinxext-opengraph"]
fpx = ["olefile"]
mic = ["olefile"]
tests = ["check-manifest", "coverage", "defusedxml", "markdown2", "olefile", "packaging", "pyroma", "pytest", "pytest-cov", "pytest-timeout"]
typing = ["typing-extensions"]
xmp = ["defusedxml"]
[[package]] [[package]]
name = "platformdirs" name = "platformdirs"
version = "4.2.1" version = "4.2.1"
@@ -1680,6 +1835,96 @@ urllib3 = ">=1.21.1,<3"
socks = ["PySocks (>=1.5.6,!=1.5.7)"] socks = ["PySocks (>=1.5.6,!=1.5.7)"]
use-chardet-on-py3 = ["chardet (>=3.0.2,<6)"] use-chardet-on-py3 = ["chardet (>=3.0.2,<6)"]
[[package]]
name = "scikit-image"
version = "0.24.0"
description = "Image processing in Python"
optional = false
python-versions = ">=3.9"
files = [
{file = "scikit_image-0.24.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:cb3bc0264b6ab30b43c4179ee6156bc18b4861e78bb329dd8d16537b7bbf827a"},
{file = "scikit_image-0.24.0-cp310-cp310-macosx_12_0_arm64.whl", hash = "sha256:9c7a52e20cdd760738da38564ba1fed7942b623c0317489af1a598a8dedf088b"},
{file = "scikit_image-0.24.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:93f46e6ce42e5409f4d09ce1b0c7f80dd7e4373bcec635b6348b63e3c886eac8"},
{file = "scikit_image-0.24.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:39ee0af13435c57351a3397eb379e72164ff85161923eec0c38849fecf1b4764"},
{file = "scikit_image-0.24.0-cp310-cp310-win_amd64.whl", hash = "sha256:7ac7913b028b8aa780ffae85922894a69e33d1c0bf270ea1774f382fe8bf95e7"},
{file = "scikit_image-0.24.0-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:272909e02a59cea3ed4aa03739bb88df2625daa809f633f40b5053cf09241831"},
{file = "scikit_image-0.24.0-cp311-cp311-macosx_12_0_arm64.whl", hash = "sha256:190ebde80b4470fe8838764b9b15f232a964f1a20391663e31008d76f0c696f7"},
{file = "scikit_image-0.24.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:59c98cc695005faf2b79904e4663796c977af22586ddf1b12d6af2fa22842dc2"},
{file = "scikit_image-0.24.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:fa27b3a0dbad807b966b8db2d78da734cb812ca4787f7fbb143764800ce2fa9c"},
{file = "scikit_image-0.24.0-cp311-cp311-win_amd64.whl", hash = "sha256:dacf591ac0c272a111181afad4b788a27fe70d213cfddd631d151cbc34f8ca2c"},
{file = "scikit_image-0.24.0-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:6fccceb54c9574590abcddc8caf6cefa57c13b5b8b4260ab3ff88ad8f3c252b3"},
{file = "scikit_image-0.24.0-cp312-cp312-macosx_12_0_arm64.whl", hash = "sha256:ccc01e4760d655aab7601c1ba7aa4ddd8b46f494ac46ec9c268df6f33ccddf4c"},
{file = "scikit_image-0.24.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:18836a18d3a7b6aca5376a2d805f0045826bc6c9fc85331659c33b4813e0b563"},
{file = "scikit_image-0.24.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:8579bda9c3f78cb3b3ed8b9425213c53a25fa7e994b7ac01f2440b395babf660"},
{file = "scikit_image-0.24.0-cp312-cp312-win_amd64.whl", hash = "sha256:82ab903afa60b2da1da2e6f0c8c65e7c8868c60a869464c41971da929b3e82bc"},
{file = "scikit_image-0.24.0-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:ef04360eda372ee5cd60aebe9be91258639c86ae2ea24093fb9182118008d009"},
{file = "scikit_image-0.24.0-cp39-cp39-macosx_12_0_arm64.whl", hash = "sha256:e9aadb442360a7e76f0c5c9d105f79a83d6df0e01e431bd1d5757e2c5871a1f3"},
{file = "scikit_image-0.24.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:5e37de6f4c1abcf794e13c258dc9b7d385d5be868441de11c180363824192ff7"},
{file = "scikit_image-0.24.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:4688c18bd7ec33c08d7bf0fd19549be246d90d5f2c1d795a89986629af0a1e83"},
{file = "scikit_image-0.24.0-cp39-cp39-win_amd64.whl", hash = "sha256:56dab751d20b25d5d3985e95c9b4e975f55573554bd76b0aedf5875217c93e69"},
{file = "scikit_image-0.24.0.tar.gz", hash = "sha256:5d16efe95da8edbeb363e0c4157b99becbd650a60b77f6e3af5768b66cf007ab"},
]
[package.dependencies]
imageio = ">=2.33"
lazy-loader = ">=0.4"
networkx = ">=2.8"
numpy = ">=1.23"
packaging = ">=21"
pillow = ">=9.1"
scipy = ">=1.9"
tifffile = ">=2022.8.12"
[package.extras]
build = ["Cython (>=3.0.4)", "build", "meson-python (>=0.15)", "ninja", "numpy (>=2.0.0rc1)", "packaging (>=21)", "pythran", "setuptools (>=67)", "spin (==0.8)", "wheel"]
data = ["pooch (>=1.6.0)"]
developer = ["ipython", "pre-commit", "tomli"]
docs = ["PyWavelets (>=1.1.1)", "dask[array] (>=2022.9.2)", "ipykernel", "ipywidgets", "kaleido", "matplotlib (>=3.6)", "myst-parser", "numpydoc (>=1.7)", "pandas (>=1.5)", "plotly (>=5.10)", "pooch (>=1.6)", "pydata-sphinx-theme (>=0.15.2)", "pytest-doctestplus", "pytest-runner", "scikit-learn (>=1.1)", "seaborn (>=0.11)", "sphinx (>=7.3)", "sphinx-copybutton", "sphinx-gallery (>=0.14)", "sphinx_design (>=0.5)", "tifffile (>=2022.8.12)"]
optional = ["PyWavelets (>=1.1.1)", "SimpleITK", "astropy (>=5.0)", "cloudpickle (>=0.2.1)", "dask[array] (>=2021.1.0)", "matplotlib (>=3.6)", "pooch (>=1.6.0)", "pyamg", "scikit-learn (>=1.1)"]
test = ["asv", "numpydoc (>=1.7)", "pooch (>=1.6.0)", "pytest (>=7.0)", "pytest-cov (>=2.11.0)", "pytest-doctestplus", "pytest-faulthandler", "pytest-localserver"]
[[package]]
name = "scipy"
version = "1.14.0"
description = "Fundamental algorithms for scientific computing in Python"
optional = false
python-versions = ">=3.10"
files = [
{file = "scipy-1.14.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:7e911933d54ead4d557c02402710c2396529540b81dd554fc1ba270eb7308484"},
{file = "scipy-1.14.0-cp310-cp310-macosx_12_0_arm64.whl", hash = "sha256:687af0a35462402dd851726295c1a5ae5f987bd6e9026f52e9505994e2f84ef6"},
{file = "scipy-1.14.0-cp310-cp310-macosx_14_0_arm64.whl", hash = "sha256:07e179dc0205a50721022344fb85074f772eadbda1e1b3eecdc483f8033709b7"},
{file = "scipy-1.14.0-cp310-cp310-macosx_14_0_x86_64.whl", hash = "sha256:6a9c9a9b226d9a21e0a208bdb024c3982932e43811b62d202aaf1bb59af264b1"},
{file = "scipy-1.14.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:076c27284c768b84a45dcf2e914d4000aac537da74236a0d45d82c6fa4b7b3c0"},
{file = "scipy-1.14.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:42470ea0195336df319741e230626b6225a740fd9dce9642ca13e98f667047c0"},
{file = "scipy-1.14.0-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:176c6f0d0470a32f1b2efaf40c3d37a24876cebf447498a4cefb947a79c21e9d"},
{file = "scipy-1.14.0-cp310-cp310-win_amd64.whl", hash = "sha256:ad36af9626d27a4326c8e884917b7ec321d8a1841cd6dacc67d2a9e90c2f0359"},
{file = "scipy-1.14.0-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:6d056a8709ccda6cf36cdd2eac597d13bc03dba38360f418560a93050c76a16e"},
{file = "scipy-1.14.0-cp311-cp311-macosx_12_0_arm64.whl", hash = "sha256:f0a50da861a7ec4573b7c716b2ebdcdf142b66b756a0d392c236ae568b3a93fb"},
{file = "scipy-1.14.0-cp311-cp311-macosx_14_0_arm64.whl", hash = "sha256:94c164a9e2498e68308e6e148646e486d979f7fcdb8b4cf34b5441894bdb9caf"},
{file = "scipy-1.14.0-cp311-cp311-macosx_14_0_x86_64.whl", hash = "sha256:a7d46c3e0aea5c064e734c3eac5cf9eb1f8c4ceee756262f2c7327c4c2691c86"},
{file = "scipy-1.14.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:9eee2989868e274aae26125345584254d97c56194c072ed96cb433f32f692ed8"},
{file = "scipy-1.14.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:9e3154691b9f7ed73778d746da2df67a19d046a6c8087c8b385bc4cdb2cfca74"},
{file = "scipy-1.14.0-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:c40003d880f39c11c1edbae8144e3813904b10514cd3d3d00c277ae996488cdb"},
{file = "scipy-1.14.0-cp311-cp311-win_amd64.whl", hash = "sha256:5b083c8940028bb7e0b4172acafda6df762da1927b9091f9611b0bcd8676f2bc"},
{file = "scipy-1.14.0-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:bff2438ea1330e06e53c424893ec0072640dac00f29c6a43a575cbae4c99b2b9"},
{file = "scipy-1.14.0-cp312-cp312-macosx_12_0_arm64.whl", hash = "sha256:bbc0471b5f22c11c389075d091d3885693fd3f5e9a54ce051b46308bc787e5d4"},
{file = "scipy-1.14.0-cp312-cp312-macosx_14_0_arm64.whl", hash = "sha256:64b2ff514a98cf2bb734a9f90d32dc89dc6ad4a4a36a312cd0d6327170339eb0"},
{file = "scipy-1.14.0-cp312-cp312-macosx_14_0_x86_64.whl", hash = "sha256:7d3da42fbbbb860211a811782504f38ae7aaec9de8764a9bef6b262de7a2b50f"},
{file = "scipy-1.14.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:d91db2c41dd6c20646af280355d41dfa1ec7eead235642178bd57635a3f82209"},
{file = "scipy-1.14.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:a01cc03bcdc777c9da3cfdcc74b5a75caffb48a6c39c8450a9a05f82c4250a14"},
{file = "scipy-1.14.0-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:65df4da3c12a2bb9ad52b86b4dcf46813e869afb006e58be0f516bc370165159"},
{file = "scipy-1.14.0-cp312-cp312-win_amd64.whl", hash = "sha256:4c4161597c75043f7154238ef419c29a64ac4a7c889d588ea77690ac4d0d9b20"},
{file = "scipy-1.14.0.tar.gz", hash = "sha256:b5923f48cb840380f9854339176ef21763118a7300a88203ccd0bdd26e58527b"},
]
[package.dependencies]
numpy = ">=1.23.5,<2.3"
[package.extras]
dev = ["cython-lint (>=0.12.2)", "doit (>=0.36.0)", "mypy (==1.10.0)", "pycodestyle", "pydevtool", "rich-click", "ruff (>=0.0.292)", "types-psutil", "typing_extensions"]
doc = ["jupyterlite-pyodide-kernel", "jupyterlite-sphinx (>=0.13.1)", "jupytext", "matplotlib (>=3.5)", "myst-nb", "numpydoc", "pooch", "pydata-sphinx-theme (>=0.15.2)", "sphinx (>=5.0.0)", "sphinx-design (>=0.4.0)"]
test = ["Cython", "array-api-strict", "asv", "gmpy2", "hypothesis (>=6.30)", "meson", "mpmath", "ninja", "pooch", "pytest", "pytest-cov", "pytest-timeout", "pytest-xdist", "scikit-umfpack", "threadpoolctl"]
[[package]] [[package]]
name = "simpleitk" name = "simpleitk"
version = "2.3.1" version = "2.3.1"
@@ -1744,6 +1989,23 @@ pure-eval = "*"
[package.extras] [package.extras]
tests = ["cython", "littleutils", "pygments", "pytest", "typeguard"] tests = ["cython", "littleutils", "pygments", "pytest", "typeguard"]
[[package]]
name = "tifffile"
version = "2024.6.18"
description = "Read and write TIFF files"
optional = false
python-versions = ">=3.9"
files = [
{file = "tifffile-2024.6.18-py3-none-any.whl", hash = "sha256:67299c0445fc47463bbc71f3cb4676da2ab0242b0c6c6542a0680801b4b97d8a"},
{file = "tifffile-2024.6.18.tar.gz", hash = "sha256:57e0d2a034bcb6287ea3155d8716508dfac86443a257f6502b57ee7f8a33b3b6"},
]
[package.dependencies]
numpy = "*"
[package.extras]
all = ["defusedxml", "fsspec", "imagecodecs (>=2023.8.12)", "lxml", "matplotlib", "zarr"]
[[package]] [[package]]
name = "tomli" name = "tomli"
version = "2.0.1" version = "2.0.1"
@@ -1963,4 +2225,4 @@ cffi = ["cffi (>=1.11)"]
[metadata] [metadata]
lock-version = "2.0" lock-version = "2.0"
python-versions = "~=3.10.0" python-versions = "~=3.10.0"
content-hash = "cd962cdf6abefe2eda6b33aa1ccaab485de7c30aaf4f8d9515c49f45a8dcaefb" content-hash = "e9980867106af8e9e7524ff319d3c0785906b359022595732260fd4b3ca135ca"

View File

@@ -1,6 +1,6 @@
[tool.poetry] [tool.poetry]
name = "bioxelnodes" name = "bioxelnodes"
version = "0.1.1" version = "0.2.4"
description = "" description = ""
authors = ["Ma Nan <icrdr2010@outlook.com>"] authors = ["Ma Nan <icrdr2010@outlook.com>"]
license = "MIT" license = "MIT"
@@ -10,6 +10,7 @@ readme = "README.md"
python = "~=3.10.0" python = "~=3.10.0"
bpy = "~=4.0" bpy = "~=4.0"
simpleitk = "^2.3.1" simpleitk = "^2.3.1"
scikit-image = "^0.24.0"
[tool.poetry.group.dev.dependencies] [tool.poetry.group.dev.dependencies]
ipykernel = "^6.25.2" ipykernel = "^6.25.2"