-
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.
feat(mesh-io): add mesh-io-emscripten bindgen output
- Loading branch information
Showing
31 changed files
with
1,643 additions
and
0 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
packages/mesh-io/python/itkwasm-mesh-io-emscripten/README.md
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,23 @@ | ||
# itkwasm-mesh-io-emscripten | ||
|
||
[![PyPI version](https://badge.fury.io/py/itkwasm-mesh-io-emscripten.svg)](https://badge.fury.io/py/itkwasm-mesh-io-emscripten) | ||
|
||
Input and output for scientific and medical image file formats. Emscripten implementation. | ||
|
||
This package provides the Emscripten WebAssembly implementation. It is usually not called directly. Please use the [`itkwasm-mesh-io`](https://pypi.org/project/itkwasm-mesh-io/) instead. | ||
|
||
|
||
## Installation | ||
|
||
```sh | ||
import micropip | ||
await micropip.install('itkwasm-mesh-io-emscripten') | ||
``` | ||
|
||
## Development | ||
|
||
```sh | ||
pip install hatch | ||
hatch run download-pyodide | ||
hatch run test | ||
``` |
26 changes: 26 additions & 0 deletions
26
packages/mesh-io/python/itkwasm-mesh-io-emscripten/itkwasm_mesh_io_emscripten/__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-emscripten: Input and output for scientific and medical image file formats. Emscripten implementation.""" | ||
|
||
from .byu_read_mesh_async import byu_read_mesh_async | ||
from .byu_write_mesh_async import byu_write_mesh_async | ||
from .free_surfer_ascii_read_mesh_async import free_surfer_ascii_read_mesh_async | ||
from .free_surfer_ascii_write_mesh_async import free_surfer_ascii_write_mesh_async | ||
from .free_surfer_binary_read_mesh_async import free_surfer_binary_read_mesh_async | ||
from .free_surfer_binary_write_mesh_async import free_surfer_binary_write_mesh_async | ||
from .obj_read_mesh_async import obj_read_mesh_async | ||
from .obj_write_mesh_async import obj_write_mesh_async | ||
from .off_read_mesh_async import off_read_mesh_async | ||
from .off_write_mesh_async import off_write_mesh_async | ||
from .stl_read_mesh_async import stl_read_mesh_async | ||
from .stl_write_mesh_async import stl_write_mesh_async | ||
from .swc_read_mesh_async import swc_read_mesh_async | ||
from .swc_write_mesh_async import swc_write_mesh_async | ||
from .vtk_poly_data_read_mesh_async import vtk_poly_data_read_mesh_async | ||
from .vtk_poly_data_write_mesh_async import vtk_poly_data_write_mesh_async | ||
from .wasm_read_mesh_async import wasm_read_mesh_async | ||
from .wasm_write_mesh_async import wasm_write_mesh_async | ||
from .wasm_zstd_read_mesh_async import wasm_zstd_read_mesh_async | ||
from .wasm_zstd_write_mesh_async import wasm_zstd_write_mesh_async | ||
|
||
from ._version import __version__ |
1 change: 1 addition & 0 deletions
1
packages/mesh-io/python/itkwasm-mesh-io-emscripten/itkwasm_mesh_io_emscripten/_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" |
60 changes: 60 additions & 0 deletions
60
...sh-io/python/itkwasm-mesh-io-emscripten/itkwasm_mesh_io_emscripten/byu_read_mesh_async.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,60 @@ | ||
# 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, | ||
Mesh, | ||
) | ||
|
||
async def byu_read_mesh_async( | ||
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 | ||
""" | ||
js_module = await js_package.js_module | ||
web_worker = js_resources.web_worker | ||
|
||
kwargs = {} | ||
if information_only: | ||
kwargs["informationOnly"] = to_js(information_only) | ||
|
||
outputs = await js_module.byuReadMesh(web_worker, to_js(BinaryFile(serialized_mesh)), **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) |
73 changes: 73 additions & 0 deletions
73
...h-io/python/itkwasm-mesh-io-emscripten/itkwasm_mesh_io_emscripten/byu_write_mesh_async.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,73 @@ | ||
# 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, | ||
Mesh, | ||
BinaryFile, | ||
) | ||
|
||
async def byu_write_mesh_async( | ||
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 | ||
""" | ||
js_module = await js_package.js_module | ||
web_worker = js_resources.web_worker | ||
|
||
kwargs = {} | ||
if information_only: | ||
kwargs["informationOnly"] = to_js(information_only) | ||
if use_compression: | ||
kwargs["useCompression"] = to_js(use_compression) | ||
if binary_file_type: | ||
kwargs["binaryFileType"] = to_js(binary_file_type) | ||
|
||
outputs = await js_module.byuWriteMesh(web_worker, to_js(mesh), to_js(serialized_mesh), **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) |
60 changes: 60 additions & 0 deletions
60
...tkwasm-mesh-io-emscripten/itkwasm_mesh_io_emscripten/free_surfer_ascii_read_mesh_async.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,60 @@ | ||
# 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, | ||
Mesh, | ||
) | ||
|
||
async def free_surfer_ascii_read_mesh_async( | ||
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 | ||
""" | ||
js_module = await js_package.js_module | ||
web_worker = js_resources.web_worker | ||
|
||
kwargs = {} | ||
if information_only: | ||
kwargs["informationOnly"] = to_js(information_only) | ||
|
||
outputs = await js_module.freeSurferAsciiReadMesh(web_worker, to_js(BinaryFile(serialized_mesh)), **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) |
73 changes: 73 additions & 0 deletions
73
...kwasm-mesh-io-emscripten/itkwasm_mesh_io_emscripten/free_surfer_ascii_write_mesh_async.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,73 @@ | ||
# 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, | ||
Mesh, | ||
BinaryFile, | ||
) | ||
|
||
async def free_surfer_ascii_write_mesh_async( | ||
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 | ||
""" | ||
js_module = await js_package.js_module | ||
web_worker = js_resources.web_worker | ||
|
||
kwargs = {} | ||
if information_only: | ||
kwargs["informationOnly"] = to_js(information_only) | ||
if use_compression: | ||
kwargs["useCompression"] = to_js(use_compression) | ||
if binary_file_type: | ||
kwargs["binaryFileType"] = to_js(binary_file_type) | ||
|
||
outputs = await js_module.freeSurferAsciiWriteMesh(web_worker, to_js(mesh), to_js(serialized_mesh), **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) |
60 changes: 60 additions & 0 deletions
60
...kwasm-mesh-io-emscripten/itkwasm_mesh_io_emscripten/free_surfer_binary_read_mesh_async.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,60 @@ | ||
# 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, | ||
Mesh, | ||
) | ||
|
||
async def free_surfer_binary_read_mesh_async( | ||
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 | ||
""" | ||
js_module = await js_package.js_module | ||
web_worker = js_resources.web_worker | ||
|
||
kwargs = {} | ||
if information_only: | ||
kwargs["informationOnly"] = to_js(information_only) | ||
|
||
outputs = await js_module.freeSurferBinaryReadMesh(web_worker, to_js(BinaryFile(serialized_mesh)), **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) |
Oops, something went wrong.