-
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): python wasi mz3 support
- Loading branch information
Showing
14 changed files
with
401 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
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
1 change: 1 addition & 0 deletions
1
...ges/mesh-io/python/itkwasm-mesh-io-wasi/itkwasm_mesh_io_wasi/extension_to_point_set_io.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
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 |
---|---|---|
|
@@ -3,6 +3,8 @@ | |
'byu', | ||
'free_surfer_ascii', | ||
'free_surfer_binary', | ||
'mz3', | ||
'obj', | ||
'obj', | ||
'off', | ||
'stl', | ||
|
76 changes: 76 additions & 0 deletions
76
packages/mesh-io/python/itkwasm-mesh-io-wasi/itkwasm_mesh_io_wasi/mz3_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 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 | ||
|
76 changes: 76 additions & 0 deletions
76
packages/mesh-io/python/itkwasm-mesh-io-wasi/itkwasm_mesh_io_wasi/mz3_read_point_set.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, | ||
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 | ||
|
86 changes: 86 additions & 0 deletions
86
packages/mesh-io/python/itkwasm-mesh-io-wasi/itkwasm_mesh_io_wasi/mz3_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 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 | ||
|
86 changes: 86 additions & 0 deletions
86
packages/mesh-io/python/itkwasm-mesh-io-wasi/itkwasm_mesh_io_wasi/mz3_write_point_set.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, | ||
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 | ||
|
1 change: 1 addition & 0 deletions
1
packages/mesh-io/python/itkwasm-mesh-io-wasi/itkwasm_mesh_io_wasi/point_set_io_index.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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
point_set_io_index = [ | ||
'vtk_poly_data', | ||
'mz3', | ||
'obj', | ||
'off', | ||
'wasm', | ||
|
Oops, something went wrong.