diff --git a/packages/mesh-io/python/itkwasm-mesh-io-wasi/itkwasm_mesh_io_wasi/__init__.py b/packages/mesh-io/python/itkwasm-mesh-io-wasi/itkwasm_mesh_io_wasi/__init__.py index 5616e343e..8dc2698ac 100644 --- a/packages/mesh-io/python/itkwasm-mesh-io-wasi/itkwasm_mesh_io_wasi/__init__.py +++ b/packages/mesh-io/python/itkwasm-mesh-io-wasi/itkwasm_mesh_io_wasi/__init__.py @@ -12,6 +12,8 @@ from .free_surfer_ascii_write_mesh import free_surfer_ascii_write_mesh from .free_surfer_binary_read_mesh import free_surfer_binary_read_mesh from .free_surfer_binary_write_mesh import free_surfer_binary_write_mesh +from .mz3_read_mesh import mz3_read_mesh +from .mz3_write_mesh import mz3_write_mesh from .obj_read_mesh import obj_read_mesh from .obj_write_mesh import obj_write_mesh from .off_read_mesh import off_read_mesh @@ -27,6 +29,8 @@ from .wasm_zstd_read_mesh import wasm_zstd_read_mesh from .wasm_zstd_write_mesh import wasm_zstd_write_mesh +from .mz3_read_point_set import mz3_read_point_set +from .mz3_write_point_set import mz3_write_point_set from .obj_read_point_set import obj_read_point_set from .obj_write_point_set import obj_write_point_set from .off_read_point_set import off_read_point_set diff --git a/packages/mesh-io/python/itkwasm-mesh-io-wasi/itkwasm_mesh_io_wasi/extension_to_mesh_io.py b/packages/mesh-io/python/itkwasm-mesh-io-wasi/itkwasm_mesh_io_wasi/extension_to_mesh_io.py index 700b2a892..30548e85f 100644 --- a/packages/mesh-io/python/itkwasm-mesh-io-wasi/itkwasm_mesh_io_wasi/extension_to_mesh_io.py +++ b/packages/mesh-io/python/itkwasm-mesh-io-wasi/itkwasm_mesh_io_wasi/extension_to_mesh_io.py @@ -5,6 +5,7 @@ ('.byu', 'byu'), ('.fsa', 'free_surfer_ascii'), ('.fsb', 'free_surfer_binary'), + ('.mz3', 'mz3'), ('.obj', 'obj'), ('.off', 'off'), ('.stl', 'stl'), diff --git a/packages/mesh-io/python/itkwasm-mesh-io-wasi/itkwasm_mesh_io_wasi/extension_to_point_set_io.py b/packages/mesh-io/python/itkwasm-mesh-io-wasi/itkwasm_mesh_io_wasi/extension_to_point_set_io.py index 965bc4016..6700bed7d 100644 --- a/packages/mesh-io/python/itkwasm-mesh-io-wasi/itkwasm_mesh_io_wasi/extension_to_point_set_io.py +++ b/packages/mesh-io/python/itkwasm-mesh-io-wasi/itkwasm_mesh_io_wasi/extension_to_point_set_io.py @@ -1,6 +1,7 @@ from collections import OrderedDict extension_to_point_set_io = OrderedDict([ + ('.mz3', 'mz3'), ('.vtk', 'vtk_poly_data'), ('.obj', 'obj'), ('.off', 'off'), diff --git a/packages/mesh-io/python/itkwasm-mesh-io-wasi/itkwasm_mesh_io_wasi/mesh_io_index.py b/packages/mesh-io/python/itkwasm-mesh-io-wasi/itkwasm_mesh_io_wasi/mesh_io_index.py index 6137bdbc2..c5a8c0690 100644 --- a/packages/mesh-io/python/itkwasm-mesh-io-wasi/itkwasm_mesh_io_wasi/mesh_io_index.py +++ b/packages/mesh-io/python/itkwasm-mesh-io-wasi/itkwasm_mesh_io_wasi/mesh_io_index.py @@ -3,6 +3,8 @@ 'byu', 'free_surfer_ascii', 'free_surfer_binary', + 'mz3', + 'obj', 'obj', 'off', 'stl', diff --git a/packages/mesh-io/python/itkwasm-mesh-io-wasi/itkwasm_mesh_io_wasi/mz3_read_mesh.py b/packages/mesh-io/python/itkwasm-mesh-io-wasi/itkwasm_mesh_io_wasi/mz3_read_mesh.py new file mode 100644 index 000000000..4bc3e86b2 --- /dev/null +++ b/packages/mesh-io/python/itkwasm-mesh-io-wasi/itkwasm_mesh_io_wasi/mz3_read_mesh.py @@ -0,0 +1,76 @@ +# 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, + Mesh, +) + +def mz3_read_mesh( + serialized_mesh: os.PathLike, + information_only: bool = False, +) -> Tuple[Any, Mesh]: + """Read a mesh file format and convert it to the itk-wasm file format + + :param serialized_mesh: Input mesh serialized in the file format + :type serialized_mesh: os.PathLike + + :param information_only: Only read mesh metadata -- do not read pixel data. + :type information_only: bool + + :return: Whether the input could be read. If false, the output mesh is not valid. + :rtype: Any + + :return: Output mesh + :rtype: Mesh + """ + global _pipeline + if _pipeline is None: + _pipeline = Pipeline(file_resources('itkwasm_mesh_io_wasi').joinpath(Path('wasm_modules') / Path('mz3-read-mesh.wasi.wasm'))) + + pipeline_outputs: List[PipelineOutput] = [ + PipelineOutput(InterfaceTypes.JsonCompatible), + PipelineOutput(InterfaceTypes.Mesh), + ] + + pipeline_inputs: List[PipelineInput] = [ + PipelineInput(InterfaceTypes.BinaryFile, BinaryFile(PurePosixPath(serialized_mesh))), + ] + + args: List[str] = ['--memory-io',] + # Inputs + if not Path(serialized_mesh).exists(): + raise FileNotFoundError("serialized_mesh does not exist") + args.append(str(PurePosixPath(serialized_mesh))) + # Outputs + could_read_name = '0' + args.append(could_read_name) + + mesh_name = '1' + args.append(mesh_name) + + # Options + input_count = len(pipeline_inputs) + if information_only: + args.append('--information-only') + + + outputs = _pipeline.run(args, pipeline_outputs, pipeline_inputs) + + result = ( + outputs[0].data, + outputs[1].data, + ) + return result + diff --git a/packages/mesh-io/python/itkwasm-mesh-io-wasi/itkwasm_mesh_io_wasi/mz3_read_point_set.py b/packages/mesh-io/python/itkwasm-mesh-io-wasi/itkwasm_mesh_io_wasi/mz3_read_point_set.py new file mode 100644 index 000000000..4a4ab3b5d --- /dev/null +++ b/packages/mesh-io/python/itkwasm-mesh-io-wasi/itkwasm_mesh_io_wasi/mz3_read_point_set.py @@ -0,0 +1,76 @@ +# 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, + PointSet, +) + +def mz3_read_point_set( + serialized_point_set: os.PathLike, + information_only: bool = False, +) -> Tuple[Any, PointSet]: + """Read a point set file format and convert it to the itk-wasm file format + + :param serialized_point_set: Input point set serialized in the file format + :type serialized_point_set: os.PathLike + + :param information_only: Only read point set metadata -- do not read pixel data. + :type information_only: bool + + :return: Whether the input could be read. If false, the output point set is not valid. + :rtype: Any + + :return: Output point set + :rtype: PointSet + """ + global _pipeline + if _pipeline is None: + _pipeline = Pipeline(file_resources('itkwasm_mesh_io_wasi').joinpath(Path('wasm_modules') / Path('mz3-read-point-set.wasi.wasm'))) + + pipeline_outputs: List[PipelineOutput] = [ + PipelineOutput(InterfaceTypes.JsonCompatible), + PipelineOutput(InterfaceTypes.PointSet), + ] + + pipeline_inputs: List[PipelineInput] = [ + PipelineInput(InterfaceTypes.BinaryFile, BinaryFile(PurePosixPath(serialized_point_set))), + ] + + args: List[str] = ['--memory-io',] + # Inputs + if not Path(serialized_point_set).exists(): + raise FileNotFoundError("serialized_point_set does not exist") + args.append(str(PurePosixPath(serialized_point_set))) + # Outputs + could_read_name = '0' + args.append(could_read_name) + + point_set_name = '1' + args.append(point_set_name) + + # Options + input_count = len(pipeline_inputs) + if information_only: + args.append('--information-only') + + + outputs = _pipeline.run(args, pipeline_outputs, pipeline_inputs) + + result = ( + outputs[0].data, + outputs[1].data, + ) + return result + diff --git a/packages/mesh-io/python/itkwasm-mesh-io-wasi/itkwasm_mesh_io_wasi/mz3_write_mesh.py b/packages/mesh-io/python/itkwasm-mesh-io-wasi/itkwasm_mesh_io_wasi/mz3_write_mesh.py new file mode 100644 index 000000000..b1e0fcd46 --- /dev/null +++ b/packages/mesh-io/python/itkwasm-mesh-io-wasi/itkwasm_mesh_io_wasi/mz3_write_mesh.py @@ -0,0 +1,86 @@ +# 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, + Mesh, + BinaryFile, +) + +def mz3_write_mesh( + mesh: Mesh, + serialized_mesh: str, + information_only: bool = False, + use_compression: bool = False, + binary_file_type: bool = False, +) -> Tuple[Any]: + """Write an itk-wasm file format converted to an mesh file format + + :param mesh: Input mesh + :type mesh: Mesh + + :param serialized_mesh: Output mesh + :type serialized_mesh: str + + :param information_only: Only write mesh metadata -- do not write pixel data. + :type information_only: bool + + :param use_compression: Use compression in the written file, if supported + :type use_compression: bool + + :param binary_file_type: Use a binary file type in the written file, if supported + :type binary_file_type: bool + + :return: Whether the input could be written. If false, the output mesh is not valid. + :rtype: Any + """ + global _pipeline + if _pipeline is None: + _pipeline = Pipeline(file_resources('itkwasm_mesh_io_wasi').joinpath(Path('wasm_modules') / Path('mz3-write-mesh.wasi.wasm'))) + + pipeline_outputs: List[PipelineOutput] = [ + PipelineOutput(InterfaceTypes.JsonCompatible), + PipelineOutput(InterfaceTypes.BinaryFile, BinaryFile(PurePosixPath(serialized_mesh))), + ] + + pipeline_inputs: List[PipelineInput] = [ + PipelineInput(InterfaceTypes.Mesh, mesh), + ] + + args: List[str] = ['--memory-io',] + # Inputs + args.append('0') + # Outputs + could_write_name = '0' + args.append(could_write_name) + + serialized_mesh_name = str(PurePosixPath(serialized_mesh)) + args.append(serialized_mesh_name) + + # Options + input_count = len(pipeline_inputs) + if information_only: + args.append('--information-only') + + if use_compression: + args.append('--use-compression') + + if binary_file_type: + args.append('--binary-file-type') + + + outputs = _pipeline.run(args, pipeline_outputs, pipeline_inputs) + + result = outputs[0].data + return result + diff --git a/packages/mesh-io/python/itkwasm-mesh-io-wasi/itkwasm_mesh_io_wasi/mz3_write_point_set.py b/packages/mesh-io/python/itkwasm-mesh-io-wasi/itkwasm_mesh_io_wasi/mz3_write_point_set.py new file mode 100644 index 000000000..c5a9a6aeb --- /dev/null +++ b/packages/mesh-io/python/itkwasm-mesh-io-wasi/itkwasm_mesh_io_wasi/mz3_write_point_set.py @@ -0,0 +1,86 @@ +# 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, + PointSet, + BinaryFile, +) + +def mz3_write_point_set( + point_set: PointSet, + serialized_point_set: str, + information_only: bool = False, + use_compression: bool = False, + binary_file_type: bool = False, +) -> Tuple[Any]: + """Write an ITK-Wasm file format converted to a point set file format + + :param point_set: Input point set + :type point_set: PointSet + + :param serialized_point_set: Output point set + :type serialized_point_set: str + + :param information_only: Only write point set metadata -- do not write pixel data. + :type information_only: bool + + :param use_compression: Use compression in the written file, if supported + :type use_compression: bool + + :param binary_file_type: Use a binary file type in the written file, if supported + :type binary_file_type: bool + + :return: Whether the input could be written. If false, the output mesh is not valid. + :rtype: Any + """ + global _pipeline + if _pipeline is None: + _pipeline = Pipeline(file_resources('itkwasm_mesh_io_wasi').joinpath(Path('wasm_modules') / Path('mz3-write-point-set.wasi.wasm'))) + + pipeline_outputs: List[PipelineOutput] = [ + PipelineOutput(InterfaceTypes.JsonCompatible), + PipelineOutput(InterfaceTypes.BinaryFile, BinaryFile(PurePosixPath(serialized_point_set))), + ] + + pipeline_inputs: List[PipelineInput] = [ + PipelineInput(InterfaceTypes.PointSet, point_set), + ] + + args: List[str] = ['--memory-io',] + # Inputs + args.append('0') + # Outputs + could_write_name = '0' + args.append(could_write_name) + + serialized_point_set_name = str(PurePosixPath(serialized_point_set)) + args.append(serialized_point_set_name) + + # Options + input_count = len(pipeline_inputs) + if information_only: + args.append('--information-only') + + if use_compression: + args.append('--use-compression') + + if binary_file_type: + args.append('--binary-file-type') + + + outputs = _pipeline.run(args, pipeline_outputs, pipeline_inputs) + + result = outputs[0].data + return result + diff --git a/packages/mesh-io/python/itkwasm-mesh-io-wasi/itkwasm_mesh_io_wasi/point_set_io_index.py b/packages/mesh-io/python/itkwasm-mesh-io-wasi/itkwasm_mesh_io_wasi/point_set_io_index.py index 1428adbbc..4a71fcca6 100644 --- a/packages/mesh-io/python/itkwasm-mesh-io-wasi/itkwasm_mesh_io_wasi/point_set_io_index.py +++ b/packages/mesh-io/python/itkwasm-mesh-io-wasi/itkwasm_mesh_io_wasi/point_set_io_index.py @@ -1,5 +1,6 @@ point_set_io_index = [ 'vtk_poly_data', + 'mz3', 'obj', 'off', 'wasm', diff --git a/packages/mesh-io/python/itkwasm-mesh-io-wasi/tests/test_mz3.py b/packages/mesh-io/python/itkwasm-mesh-io-wasi/tests/test_mz3.py new file mode 100644 index 000000000..f8a3bd6fa --- /dev/null +++ b/packages/mesh-io/python/itkwasm-mesh-io-wasi/tests/test_mz3.py @@ -0,0 +1,36 @@ +from pathlib import Path + +from itkwasm import FloatTypes, IntTypes, PixelTypes + +from itkwasm_mesh_io_wasi import mz3_read_mesh, mz3_write_mesh + +from .common import test_input_path, test_output_path + +test_input_file_path = test_input_path / "11ScalarMesh.mz3" +test_output_file_path = test_output_path / "mz3-test-11ScalarMesh.mz3" + +def verify_mesh(mesh): + assert mesh.meshType.dimension == 3 + assert mesh.meshType.pointComponentType == FloatTypes.Float32 + assert mesh.meshType.cellComponentType == IntTypes.UInt32 + assert mesh.meshType.pointPixelType == PixelTypes.Scalar + assert mesh.meshType.cellPixelType == PixelTypes.Scalar + assert mesh.numberOfPoints == 6 + assert mesh.numberOfCells == 8 + +def test_mz3_read_mesh(): + could_read, mesh = mz3_read_mesh(test_input_file_path) + assert could_read + verify_mesh(mesh) + +def test_mz3_write_mesh(): + could_read, mesh = mz3_read_mesh(test_input_file_path) + assert could_read + + use_compression = False + could_write = mz3_write_mesh(mesh, test_output_file_path, use_compression=use_compression) + assert could_write + + could_read, mesh = mz3_read_mesh(test_output_file_path) + assert could_read + verify_mesh(mesh) \ No newline at end of file diff --git a/packages/mesh-io/python/itkwasm-mesh-io-wasi/tests/test_mz3_read_mesh.py b/packages/mesh-io/python/itkwasm-mesh-io-wasi/tests/test_mz3_read_mesh.py new file mode 100644 index 000000000..8f7671d33 --- /dev/null +++ b/packages/mesh-io/python/itkwasm-mesh-io-wasi/tests/test_mz3_read_mesh.py @@ -0,0 +1,8 @@ +# Generated file. To retain edits, remove this comment. + +from itkwasm_mesh_io_wasi import mz3_read_mesh + +from .common import test_input_path, test_output_path + +def test_mz3_read_mesh(): + pass diff --git a/packages/mesh-io/python/itkwasm-mesh-io-wasi/tests/test_mz3_read_point_set.py b/packages/mesh-io/python/itkwasm-mesh-io-wasi/tests/test_mz3_read_point_set.py new file mode 100644 index 000000000..b46f3f58c --- /dev/null +++ b/packages/mesh-io/python/itkwasm-mesh-io-wasi/tests/test_mz3_read_point_set.py @@ -0,0 +1,8 @@ +# Generated file. To retain edits, remove this comment. + +from itkwasm_mesh_io_wasi import mz3_read_point_set + +from .common import test_input_path, test_output_path + +def test_mz3_read_point_set(): + pass diff --git a/packages/mesh-io/python/itkwasm-mesh-io-wasi/tests/test_mz3_write_mesh.py b/packages/mesh-io/python/itkwasm-mesh-io-wasi/tests/test_mz3_write_mesh.py new file mode 100644 index 000000000..f95cc0e04 --- /dev/null +++ b/packages/mesh-io/python/itkwasm-mesh-io-wasi/tests/test_mz3_write_mesh.py @@ -0,0 +1,8 @@ +# Generated file. To retain edits, remove this comment. + +from itkwasm_mesh_io_wasi import mz3_write_mesh + +from .common import test_input_path, test_output_path + +def test_mz3_write_mesh(): + pass diff --git a/packages/mesh-io/python/itkwasm-mesh-io-wasi/tests/test_mz3_write_point_set.py b/packages/mesh-io/python/itkwasm-mesh-io-wasi/tests/test_mz3_write_point_set.py new file mode 100644 index 000000000..b52210ab3 --- /dev/null +++ b/packages/mesh-io/python/itkwasm-mesh-io-wasi/tests/test_mz3_write_point_set.py @@ -0,0 +1,8 @@ +# Generated file. To retain edits, remove this comment. + +from itkwasm_mesh_io_wasi import mz3_write_point_set + +from .common import test_input_path, test_output_path + +def test_mz3_write_point_set(): + pass