-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
1,733 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# itkwasm-mesh-io-wasi | ||
|
||
[![PyPI version](https://badge.fury.io/py/itkwasm-mesh-io-wasi.svg)](https://badge.fury.io/py/itkwasm-mesh-io-wasi) | ||
|
||
Input and output for scientific and medical image file formats. WASI implementation. | ||
|
||
This package provides the WASI WebAssembly implementation. It is usually not called directly. Please use [`itkwasm-mesh-io`](https://pypi.org/project/itkwasm-mesh-io/) instead. | ||
|
||
|
||
## Installation | ||
|
||
```sh | ||
pip install itkwasm-mesh-io-wasi | ||
``` | ||
|
||
## Development | ||
|
||
```sh | ||
pip install pytest | ||
pip install -e . | ||
pytest | ||
|
||
# or | ||
pip install hatch | ||
hatch run test | ||
``` |
26 changes: 26 additions & 0 deletions
26
packages/mesh-io/python/itkwasm-mesh-io-wasi/itkwasm_mesh_io_wasi/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Generated file. To retain edits, remove this comment. | ||
|
||
"""itkwasm-mesh-io-wasi: Input and output for scientific and medical image file formats. WASI implementation.""" | ||
|
||
from .byu_read_mesh import byu_read_mesh | ||
from .byu_write_mesh import byu_write_mesh | ||
from .free_surfer_ascii_read_mesh import free_surfer_ascii_read_mesh | ||
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 .obj_read_mesh import obj_read_mesh | ||
from .obj_write_mesh import obj_write_mesh | ||
from .off_read_mesh import off_read_mesh | ||
from .off_write_mesh import off_write_mesh | ||
from .stl_read_mesh import stl_read_mesh | ||
from .stl_write_mesh import stl_write_mesh | ||
from .swc_read_mesh import swc_read_mesh | ||
from .swc_write_mesh import swc_write_mesh | ||
from .vtk_poly_data_read_mesh import vtk_poly_data_read_mesh | ||
from .vtk_poly_data_write_mesh import vtk_poly_data_write_mesh | ||
from .wasm_read_mesh import wasm_read_mesh | ||
from .wasm_write_mesh import wasm_write_mesh | ||
from .wasm_zstd_read_mesh import wasm_zstd_read_mesh | ||
from .wasm_zstd_write_mesh import wasm_zstd_write_mesh | ||
|
||
from ._version import __version__ |
1 change: 1 addition & 0 deletions
1
packages/mesh-io/python/itkwasm-mesh-io-wasi/itkwasm_mesh_io_wasi/_version.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
__version__ = "0.1.0" |
76 changes: 76 additions & 0 deletions
76
packages/mesh-io/python/itkwasm-mesh-io-wasi/itkwasm_mesh_io_wasi/byu_read_mesh.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 byu_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 image 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('byu-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 | ||
|
86 changes: 86 additions & 0 deletions
86
packages/mesh-io/python/itkwasm-mesh-io-wasi/itkwasm_mesh_io_wasi/byu_write_mesh.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 byu_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 image 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('byu-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 | ||
|
76 changes: 76 additions & 0 deletions
76
...s/mesh-io/python/itkwasm-mesh-io-wasi/itkwasm_mesh_io_wasi/free_surfer_ascii_read_mesh.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 free_surfer_ascii_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 image 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('free-surfer-ascii-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 | ||
|
86 changes: 86 additions & 0 deletions
86
.../mesh-io/python/itkwasm-mesh-io-wasi/itkwasm_mesh_io_wasi/free_surfer_ascii_write_mesh.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 free_surfer_ascii_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 image 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('free-surfer-ascii-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 | ||
|
Oops, something went wrong.