Skip to content

Commit 4dfc374

Browse files
committed
Change CmakeLists to build image-sets-normalization for WASI.
Fix wasi/__init__ to expose image_sets_normalization.
1 parent 4293f03 commit 4dfc374

12 files changed

+188
-23
lines changed

packages/dicom/CMakeLists.txt

+11
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,14 @@ set(CMAKE_CXX_STANDARD 17)
55

66
add_subdirectory(gdcm)
77
add_subdirectory(dcmtk)
8+
9+
enable_testing()
10+
11+
add_test(NAME image-sets-normalization-help COMMAND image-sets-normalization --help)
12+
13+
add_test(NAME image-sets-normalization-smoke
14+
COMMAND image-sets-normalization image-sets.json --files
15+
${CMAKE_CURRENT_SOURCE_DIR}/test/data/input/DicomImageOrientationTest/ImageOrientation.1.dcm
16+
${CMAKE_CURRENT_SOURCE_DIR}/test/data/input/DicomImageOrientationTest/ImageOrientation.2.dcm
17+
${CMAKE_CURRENT_SOURCE_DIR}/test/data/input/DicomImageOrientationTest/ImageOrientation.3.dcm
18+
)

packages/dicom/gdcm/CMakeLists.txt

+3-16
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ include(${ITK_USE_FILE})
1010
add_executable(read-image-dicom-file-series read-image-dicom-file-series.cxx)
1111
target_link_libraries(read-image-dicom-file-series PUBLIC ${ITK_LIBRARIES})
1212

13+
add_executable(image-sets-normalization image-sets-normalization.cxx)
14+
target_link_libraries(image-sets-normalization PUBLIC ${ITK_LIBRARIES})
15+
1316
if (WASI)
1417
return()
1518
endif()
@@ -63,22 +66,6 @@ add_dependencies(${Iconv} ${Iconv_LIBRARY})
6366
add_executable(read-dicom-tags read-dicom-tags.cxx)
6467
target_link_libraries(read-dicom-tags PUBLIC ${ITK_LIBRARIES} ${Iconv_LIBRARIES} ${Iconv})
6568

66-
67-
add_executable(image-sets-normalization image-sets-normalization.cxx)
68-
target_link_libraries(image-sets-normalization PUBLIC ${ITK_LIBRARIES})
69-
70-
enable_testing()
71-
72-
add_test(NAME image-sets-normalization-help COMMAND image-sets-normalization --help)
73-
74-
add_test(NAME image-sets-normalization-smoke
75-
COMMAND image-sets-normalization image-sets.json --files
76-
${CMAKE_CURRENT_SOURCE_DIR}/test/data/input/DicomImageOrientationTest/ImageOrientation.1.dcm
77-
${CMAKE_CURRENT_SOURCE_DIR}/test/data/input/DicomImageOrientationTest/ImageOrientation.2.dcm
78-
${CMAKE_CURRENT_SOURCE_DIR}/test/data/input/DicomImageOrientationTest/ImageOrientation.3.dcm
79-
)
80-
81-
8269
if (EMSCRIPTEN)
8370
foreach(dicom_io_module
8471
read-image-dicom-file-series
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Generated file. To retain edits, remove this comment.
2+
3+
from pathlib import Path
4+
import os
5+
from typing import Dict, Tuple, Optional, List, Any
6+
7+
from .js_package import js_package
8+
9+
from itkwasm.pyodide import (
10+
to_js,
11+
to_py,
12+
js_resources
13+
)
14+
from itkwasm import (
15+
InterfaceTypes,
16+
BinaryFile,
17+
)
18+
19+
async def image_sets_normalization_async(
20+
files: List[os.PathLike] = [],
21+
) -> Any:
22+
"""Group DICOM files into image sets
23+
24+
:param files: DICOM files
25+
:type files: os.PathLike
26+
27+
:return: Image sets JSON
28+
:rtype: Any
29+
"""
30+
js_module = await js_package.js_module
31+
web_worker = js_resources.web_worker
32+
33+
kwargs = {}
34+
if files is not None:
35+
kwargs["files"] = to_js(BinaryFile(files))
36+
37+
outputs = await js_module.imageSetsNormalization(webWorker=web_worker, noCopy=True, **kwargs)
38+
39+
output_web_worker = None
40+
output_list = []
41+
outputs_object_map = outputs.as_object_map()
42+
for output_name in outputs.object_keys():
43+
if output_name == 'webWorker':
44+
output_web_worker = outputs_object_map[output_name]
45+
else:
46+
output_list.append(to_py(outputs_object_map[output_name]))
47+
48+
js_resources.web_worker = output_web_worker
49+
50+
if len(output_list) == 1:
51+
return output_list[0]
52+
return tuple(output_list)

packages/dicom/python/itkwasm-dicom-emscripten/itkwasm_dicom_emscripten/js_package.py

+1-1
Large diffs are not rendered by default.

packages/dicom/python/itkwasm-dicom-wasi/itkwasm_dicom_wasi/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
from .structured_report_to_html import structured_report_to_html
66
from .structured_report_to_text import structured_report_to_text
77
from .read_image_dicom_file_series import read_image_dicom_file_series
8+
from .image_sets_normalization import image_sets_normalization
89

910
from ._version import __version__
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
# Generated file. To retain edits, remove this comment.
2+
3+
from pathlib import Path, PurePosixPath
4+
import os
5+
from typing import Dict, Tuple, Optional, List, Any
6+
7+
from importlib_resources import files as file_resources
8+
9+
_pipeline = None
10+
11+
from itkwasm import (
12+
InterfaceTypes,
13+
PipelineOutput,
14+
PipelineInput,
15+
Pipeline,
16+
BinaryFile,
17+
)
18+
19+
def image_sets_normalization(
20+
files: List[os.PathLike] = [],
21+
) -> Any:
22+
"""Group DICOM files into image sets
23+
24+
:param files: DICOM files
25+
:type files: os.PathLike
26+
27+
:return: Image sets JSON
28+
:rtype: Any
29+
"""
30+
global _pipeline
31+
if _pipeline is None:
32+
_pipeline = Pipeline(file_resources('itkwasm_dicom_wasi').joinpath(Path('wasm_modules') / Path('image-sets-normalization.wasi.wasm')))
33+
34+
pipeline_outputs: List[PipelineOutput] = [
35+
PipelineOutput(InterfaceTypes.JsonCompatible),
36+
]
37+
38+
pipeline_inputs: List[PipelineInput] = [
39+
]
40+
41+
args: List[str] = ['--memory-io',]
42+
# Inputs
43+
# Outputs
44+
image_sets_metadata_name = '0'
45+
args.append(image_sets_metadata_name)
46+
47+
# Options
48+
input_count = len(pipeline_inputs)
49+
if len(files) < 1:
50+
raise ValueError('"files" kwarg must have a length > 1')
51+
if len(files) > 0:
52+
args.append('--files')
53+
for value in files:
54+
input_file = str(PurePosixPath(value))
55+
pipeline_inputs.append(PipelineInput(InterfaceTypes.BinaryFile, BinaryFile(value)))
56+
args.append(input_file)
57+
58+
59+
outputs = _pipeline.run(args, pipeline_outputs, pipeline_inputs)
60+
61+
result = outputs[0].data
62+
return result
63+
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
1-
# Generated file. To retain edits, remove this comment.
1+
from itkwasm_dicom_wasi import image_sets_normalization
22

33
from .common import test_input_path, test_output_path
44

5-
def test_sort_dicom_series():
6-
from itkwasm_dicom_wasi import image_sets_normalization
75

8-
test_file_path = test_input_path / "DicomImageOrientationTest" / "ImageOrientation.1.dcm"
6+
def test_image_sets_normalization():
7+
files = [
8+
test_input_path / "DicomImageOrientationTest" / "ImageOrientation.1.dcm",
9+
test_input_path / "DicomImageOrientationTest" / "ImageOrientation.2.dcm",
10+
test_input_path / "DicomImageOrientationTest" / "ImageOrientation.3.dcm",
11+
]
912

10-
assert test_file_path.exists()
13+
assert files[0].exists()
1114

12-
output_text = image_sets_normalization([test_file_path])
15+
output_text = image_sets_normalization(files)
1316
assert output_text
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Generated file. Do not edit.
2+
3+
import os
4+
from typing import Dict, Tuple, Optional, List, Any
5+
6+
from itkwasm import (
7+
environment_dispatch,
8+
BinaryFile,
9+
)
10+
11+
def image_sets_normalization(
12+
files: List[os.PathLike] = [],
13+
) -> Any:
14+
"""Group DICOM files into image sets
15+
16+
:param files: DICOM files
17+
:type files: os.PathLike
18+
19+
:return: Image sets JSON
20+
:rtype: Any
21+
"""
22+
func = environment_dispatch("itkwasm_dicom", "image_sets_normalization")
23+
output = func(files=files)
24+
return output
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Generated file. Do not edit.
2+
3+
import os
4+
from typing import Dict, Tuple, Optional, List, Any
5+
6+
from itkwasm import (
7+
environment_dispatch,
8+
BinaryFile,
9+
)
10+
11+
async def image_sets_normalization_async(
12+
files: List[os.PathLike] = [],
13+
) -> Any:
14+
"""Group DICOM files into image sets
15+
16+
:param files: DICOM files
17+
:type files: os.PathLike
18+
19+
:return: Image sets JSON
20+
:rtype: Any
21+
"""
22+
func = environment_dispatch("itkwasm_dicom", "image_sets_normalization_async")
23+
output = await func(files=files)
24+
return output

0 commit comments

Comments
 (0)