Skip to content

Commit

Permalink
Change CmakeLists to build image-sets-normalization for WASI.
Browse files Browse the repository at this point in the history
Fix wasi/__init__ to expose image_sets_normalization.
  • Loading branch information
PaulHax committed Mar 13, 2024
1 parent 3f292c1 commit 0c19952
Show file tree
Hide file tree
Showing 10 changed files with 180 additions and 20 deletions.
30 changes: 14 additions & 16 deletions packages/dicom/gdcm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,20 @@ include(${ITK_USE_FILE})
add_executable(read-image-dicom-file-series read-image-dicom-file-series.cxx)
target_link_libraries(read-image-dicom-file-series PUBLIC ${ITK_LIBRARIES})

add_executable(image-sets-normalization image-sets-normalization.cxx)
target_link_libraries(image-sets-normalization PUBLIC ${ITK_LIBRARIES})

enable_testing()

add_test(NAME image-sets-normalization-help COMMAND image-sets-normalization --help)

add_test(NAME image-sets-normalization-smoke
COMMAND image-sets-normalization image-sets.json --files
${CMAKE_CURRENT_SOURCE_DIR}/test/data/input/DicomImageOrientationTest/ImageOrientation.1.dcm
${CMAKE_CURRENT_SOURCE_DIR}/test/data/input/DicomImageOrientationTest/ImageOrientation.2.dcm
${CMAKE_CURRENT_SOURCE_DIR}/test/data/input/DicomImageOrientationTest/ImageOrientation.3.dcm
)

if (WASI)
return()
endif()
Expand Down Expand Up @@ -63,22 +77,6 @@ add_dependencies(${Iconv} ${Iconv_LIBRARY})
add_executable(read-dicom-tags read-dicom-tags.cxx)
target_link_libraries(read-dicom-tags PUBLIC ${ITK_LIBRARIES} ${Iconv_LIBRARIES} ${Iconv})


add_executable(image-sets-normalization image-sets-normalization.cxx)
target_link_libraries(image-sets-normalization PUBLIC ${ITK_LIBRARIES})

enable_testing()

add_test(NAME image-sets-normalization-help COMMAND image-sets-normalization --help)

add_test(NAME image-sets-normalization-smoke
COMMAND image-sets-normalization image-sets.json --files
${CMAKE_CURRENT_SOURCE_DIR}/test/data/input/DicomImageOrientationTest/ImageOrientation.1.dcm
${CMAKE_CURRENT_SOURCE_DIR}/test/data/input/DicomImageOrientationTest/ImageOrientation.2.dcm
${CMAKE_CURRENT_SOURCE_DIR}/test/data/input/DicomImageOrientationTest/ImageOrientation.3.dcm
)


if (EMSCRIPTEN)
foreach(dicom_io_module
read-image-dicom-file-series
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Generated file. To retain edits, remove this comment.

from pathlib import Path
import os
from typing import Dict, Tuple, Optional, List, Any

from .js_package import js_package

from itkwasm.pyodide import (
to_js,
to_py,
js_resources
)
from itkwasm import (
InterfaceTypes,
BinaryFile,
)

async def image_sets_normalization_async(
files: List[os.PathLike] = [],
) -> Any:
"""Group DICOM files into image sets
:param files: DICOM files
:type files: os.PathLike
:return: Image sets JSON
:rtype: Any
"""
js_module = await js_package.js_module
web_worker = js_resources.web_worker

kwargs = {}
if files is not None:
kwargs["files"] = to_js(BinaryFile(files))

outputs = await js_module.imageSetsNormalization(webWorker=web_worker, noCopy=True, **kwargs)

output_web_worker = None
output_list = []
outputs_object_map = outputs.as_object_map()
for output_name in outputs.object_keys():
if output_name == 'webWorker':
output_web_worker = outputs_object_map[output_name]
else:
output_list.append(to_py(outputs_object_map[output_name]))

js_resources.web_worker = output_web_worker

if len(output_list) == 1:
return output_list[0]
return tuple(output_list)
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
from .structured_report_to_html import structured_report_to_html
from .structured_report_to_text import structured_report_to_text
from .read_image_dicom_file_series import read_image_dicom_file_series
from .image_sets_normalization import image_sets_normalization

from ._version import __version__
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Generated file. To retain edits, remove this comment.

from pathlib import Path, PurePosixPath
import os
from typing import Dict, Tuple, Optional, List, Any

from importlib_resources import files as file_resources

_pipeline = None

from itkwasm import (
InterfaceTypes,
PipelineOutput,
PipelineInput,
Pipeline,
BinaryFile,
)

def image_sets_normalization(
files: List[os.PathLike] = [],
) -> Any:
"""Group DICOM files into image sets
:param files: DICOM files
:type files: os.PathLike
:return: Image sets JSON
:rtype: Any
"""
global _pipeline
if _pipeline is None:
_pipeline = Pipeline(file_resources('itkwasm_dicom_wasi').joinpath(Path('wasm_modules') / Path('image-sets-normalization.wasi.wasm')))

pipeline_outputs: List[PipelineOutput] = [
PipelineOutput(InterfaceTypes.JsonCompatible),
]

pipeline_inputs: List[PipelineInput] = [
]

args: List[str] = ['--memory-io',]
# Inputs
# Outputs
image_sets_metadata_name = '0'
args.append(image_sets_metadata_name)

# Options
input_count = len(pipeline_inputs)
if len(files) < 1:
raise ValueError('"files" kwarg must have a length > 1')
if len(files) > 0:
args.append('--files')
for value in files:
input_file = str(PurePosixPath(value))
pipeline_inputs.append(PipelineInput(InterfaceTypes.BinaryFile, BinaryFile(value)))
args.append(input_file)


outputs = _pipeline.run(args, pipeline_outputs, pipeline_inputs)

result = outputs[0].data
return result

Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
# Generated file. To retain edits, remove this comment.
from itkwasm_dicom_wasi import image_sets_normalization

from .common import test_input_path, test_output_path

def test_sort_dicom_series():
from itkwasm_dicom_wasi import image_sets_normalization

def test_image_sets_normalization():
test_file_path = test_input_path / "DicomImageOrientationTest" / "ImageOrientation.1.dcm"

assert test_file_path.exists()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated file. Do not edit.

import os
from typing import Dict, Tuple, Optional, List, Any

from itkwasm import (
environment_dispatch,
BinaryFile,
)

def image_sets_normalization(
files: List[os.PathLike] = [],
) -> Any:
"""Group DICOM files into image sets
:param files: DICOM files
:type files: os.PathLike
:return: Image sets JSON
:rtype: Any
"""
func = environment_dispatch("itkwasm_dicom", "image_sets_normalization")
output = func(files=files)
return output
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Generated file. Do not edit.

import os
from typing import Dict, Tuple, Optional, List, Any

from itkwasm import (
environment_dispatch,
BinaryFile,
)

async def image_sets_normalization_async(
files: List[os.PathLike] = [],
) -> Any:
"""Group DICOM files into image sets
:param files: DICOM files
:type files: os.PathLike
:return: Image sets JSON
:rtype: Any
"""
func = environment_dispatch("itkwasm_dicom", "image_sets_normalization_async")
output = await func(files=files)
return output

0 comments on commit 0c19952

Please sign in to comment.