Merge pull request #5 from OmooLab/feature/dev

fix: get no group input node
This commit is contained in:
Ma Nan
2024-04-23 15:12:38 +08:00
committed by GitHub
4 changed files with 26 additions and 32 deletions

View File

@@ -78,7 +78,7 @@ You can add a "Bake" node between segmentation node and shader node, if the reco
# Known limitations # Known limitations
- Cannot read DICOM with multiple sequences. - Cannot read DICOM with multiple series.
- Sections cannot be generated - Sections cannot be generated
- Only sequence files are supported, packed volume data formats are not supported yet (will be supported soon) - Only sequence files are supported, packed volume data formats are not supported yet (will be supported soon)

View File

@@ -6,7 +6,7 @@ import numpy as np
from pathlib import Path from pathlib import Path
from uuid import uuid4 from uuid import uuid4
import mathutils import mathutils
from .utils import calc_bbox_verts, extract_last_number, get_bioxels_obj, show_message from .utils import calc_bbox_verts, extract_last_number, get_bioxels_obj, get_node_by_type, show_message
from .nodes import custom_nodes from .nodes import custom_nodes
SUPPORT_EXTS = ['.dcm', '.tif', '.tiff', '.png', '.bmp', '', '.jpg'] SUPPORT_EXTS = ['.dcm', '.tif', '.tiff', '.png', '.bmp', '', '.jpg']
@@ -79,7 +79,7 @@ class ImportDICOMDialog(bpy.types.Operator):
) # type: ignore ) # type: ignore
bioxels_shape: bpy.props.IntVectorProperty( bioxels_shape: bpy.props.IntVectorProperty(
name="Bioxels Shape", name="Bioxels Shape (ReadOnly)",
min=0, min=0,
default=(100, 100, 100) default=(100, 100, 100)
) # type: ignore ) # type: ignore
@@ -128,15 +128,6 @@ class ImportDICOMDialog(bpy.types.Operator):
) # type: ignore ) # type: ignore
def execute(self, context): def execute(self, context):
if not self.filepath:
self.report({"WARNING"}, "Get no file path.")
return {'CANCELLED'}
if Path(self.filepath).suffix not in SUPPORT_EXTS:
self.report({"WARNING"}, "Not Supported extension.")
return {'CANCELLED'}
files = get_data_files(self.filepath) files = get_data_files(self.filepath)
name = Path(self.filepath).parent.name name = Path(self.filepath).parent.name
@@ -160,9 +151,6 @@ class ImportDICOMDialog(bpy.types.Operator):
int(image_shape[2] / bioxel_size * orig_spacing[2]), int(image_shape[2] / bioxel_size * orig_spacing[2]),
) )
print("Bioxel Size:", bioxel_size)
print("Bioxels Shape:", bioxels_shape)
print("Resampling...") print("Resampling...")
image = sitk.Resample( image = sitk.Resample(
image1=image, image1=image,
@@ -176,14 +164,12 @@ class ImportDICOMDialog(bpy.types.Operator):
outputPixelType=image.GetPixelID(), outputPixelType=image.GetPixelID(),
) )
try: print("Orienting to RAS...")
image = sitk.DICOMOrient(image, 'RAS') image = sitk.DICOMOrient(image, 'RAS')
except:
...
array = sitk.GetArrayFromImage(image) array = sitk.GetArrayFromImage(image)
orig_dtype = str(array.dtype) orig_dtype = str(array.dtype)
print(f"Coverting Dtype {orig_dtype} -> float") print(f"Coverting Dtype from {orig_dtype} to float...")
array = array.astype(float) array = array.astype(float)
# ITK indices, by convention, are [i,j,k] while NumPy indices are [k,j,i] # ITK indices, by convention, are [i,j,k] while NumPy indices are [k,j,i]
@@ -197,6 +183,10 @@ class ImportDICOMDialog(bpy.types.Operator):
array = np.transpose(array) array = np.transpose(array)
bioxels_max = float(np.max(array)) bioxels_max = float(np.max(array))
bioxels_min = float(np.min(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 bioxels_offset = 0.0
if bioxels_min < 0 and orig_dtype[0] != "u": if bioxels_min < 0 and orig_dtype[0] != "u":
@@ -273,7 +263,6 @@ class ImportDICOMDialog(bpy.types.Operator):
) )
bioxels_obj.matrix_world = mat_ras2blender @ mat_scene_scale bioxels_obj.matrix_world = mat_ras2blender @ mat_scene_scale
bioxels_obj.lock_location[0] = True bioxels_obj.lock_location[0] = True
bioxels_obj.lock_location[1] = True bioxels_obj.lock_location[1] = True
bioxels_obj.lock_location[2] = True bioxels_obj.lock_location[2] = True
@@ -296,10 +285,8 @@ class ImportDICOMDialog(bpy.types.Operator):
container_obj = bpy.context.active_object container_obj = bpy.context.active_object
bbox_verts = calc_bbox_verts((0, 0, 0), bioxels_shape) bbox_verts = calc_bbox_verts((0, 0, 0), bioxels_shape)
for index, vert in enumerate(container_obj.data.vertices): for index, vert in enumerate(container_obj.data.vertices):
co = transfrom @ mathutils.Vector(bbox_verts[index]) bbox_transform = mat_ras2blender @ mat_scene_scale @ transfrom
co = mat_ras2blender @ co vert.co = bbox_transform @ mathutils.Vector(bbox_verts[index])
co = mat_scene_scale @ co
vert.co = co
bioxels_obj.parent = container_obj bioxels_obj.parent = container_obj
container_obj.name = name container_obj.name = name
@@ -332,10 +319,11 @@ class ImportDICOMDialog(bpy.types.Operator):
nodes = node_tree.nodes nodes = node_tree.nodes
links = node_tree.links links = node_tree.links
input_node = nodes.get("Group Input") input_node = get_node_by_type(nodes, 'NodeGroupInput')[0]
output_node = nodes.get("Group Output") output_node = get_node_by_type(nodes, 'NodeGroupOutput')[0]
segment_node = custom_nodes.add_node(nodes, 'BioxelNodes_Segment')
segment_node = custom_nodes.add_node(
nodes, 'BioxelNodes_Segment')
links.new(input_node.outputs[0], segment_node.inputs[0]) links.new(input_node.outputs[0], segment_node.inputs[0])
links.new(segment_node.outputs[0], output_node.inputs[0]) links.new(segment_node.outputs[0], output_node.inputs[0])
@@ -372,9 +360,14 @@ class ReadDICOM(bpy.types.Operator):
) # type: ignore ) # type: ignore
def execute(self, context): def execute(self, context):
if Path(self.filepath).suffix not in SUPPORT_EXTS:
self.report({"WARNING"}, "Not Supported extension.")
return {'CANCELLED'}
files = get_data_files(self.filepath) files = get_data_files(self.filepath)
import SimpleITK as sitk import SimpleITK as sitk
image = sitk.ReadImage(files) image = sitk.ReadImage(files)
print("Collecting Meta Data...") print("Collecting Meta Data...")
@@ -402,9 +395,6 @@ class ReadDICOM(bpy.types.Operator):
if not self.filepath: if not self.filepath:
return {'CANCELLED'} return {'CANCELLED'}
if Path(self.filepath).suffix not in SUPPORT_EXTS:
return {'CANCELLED'}
show_message('Reading image data, it may take a while', show_message('Reading image data, it may take a while',
'Please be patient...') 'Please be patient...')
context.window_manager.modal_handler_add(self) context.window_manager.modal_handler_add(self)
@@ -481,7 +471,7 @@ class ExportVDB(bpy.types.Operator):
# print('output_path', output_path) # print('output_path', output_path)
# print('source_path', source_path) # print('source_path', source_path)
shutil.copy(source_path, output_path) shutil.copy(source_path, output_path)
self.report({"INFO"}, "Successfully Exported") self.report({"INFO"}, "Successfully Exported")
return {'FINISHED'} return {'FINISHED'}

View File

@@ -2,6 +2,10 @@ import bpy
import mathutils import mathutils
def get_node_by_type(nodes, type_name: str):
return [node for node in nodes if type(node).__name__ == 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):

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.3 MiB

After

Width:  |  Height:  |  Size: 2.5 MiB