Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(itk-python): example of file format conversion via wasm io packages #1240

Merged

Conversation

thewtex
Copy link
Member

@thewtex thewtex commented Sep 19, 2024

Also simplify the native example so it is easy to see the
correspondance.

Also simplify the native example so it is easy to see the
correspondance.
@thewtex
Copy link
Member Author

thewtex commented Sep 19, 2024

@neurolabusc please take a look 🙏

@neurolabusc
Copy link

@thewtex thanks for your quick work. These new examples work well, and I am now able to open and save meshes in many formats (e.g. obj, stl). So I think the documentation is fine. It does expose an issue with meshes saved in the popular vtk format - it can load and save some meshes in the popular vtk format (e.g. the cow.vtk). However, it fails on any mesh created with 3DSlicer. I tried several different meshes of different formats that loaded fine in slicer and the slicer output vtk meshes would be read fine by other tools (Slicer, NiiVue, Surfice). However, while meshread does not complain opening these vtk format meshes, it fails whenever your try to save it, regardless of the format (iwm.cbor, vtk, obj, stl):

>>> mesh = meshread('gourd.vtk')
>>> meshwrite(mesh, 'gourd2.iwm.cbor')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/itkwasm_mesh_io/write_mesh.py", line 39, in meshwrite
    return write_mesh(mesh, serialized_mesh, information_only=information_only, use_compression=use_compression)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/itkwasm_mesh_io/write_mesh.py", line 30, in write_mesh
    func(mesh, serialized_mesh, information_only=information_only, use_compression=use_compression)
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/itkwasm_mesh_io_wasi/write_mesh.py", line 54, in write_mesh
    could_write = io(mesh, serialized_mesh, information_only=information_only, use_compression=use_compression)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/itkwasm_mesh_io_wasi/wasm_write_mesh.py", line 82, in wasm_write_mesh
    outputs = _pipeline.run(args, pipeline_outputs, pipeline_inputs)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/itkwasm/pipeline.py", line 354, in run
    return_code = ri.delayed_start()
                  ^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/itkwasm/pipeline.py", line 148, in delayed_start
    return_code = func(self._store)
                  ^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/wasmtime/_func.py", line 93, in __call__
    with enter_wasm(store) as trap:
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/contextlib.py", line 144, in __exit__
    next(self.gen)
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/wasmtime/_func.py", line 265, in enter_wasm
    raise trap_obj
wasmtime._trap.Trap: error while executing at wasm backtrace:
    0: 0x515db - <unknown>!<wasm function 669>
    1: 0xa2d99 - <unknown>!<wasm function 1227>
note: using the `WASMTIME_BACKTRACE_DETAILS=1` environment variable may show more debugging information

Caused by:
    wasm trap: wasm `unreachable` instruction executed
>>> meshwrite(mesh, 'gourd2.stl')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/itkwasm_mesh_io/write_mesh.py", line 39, in meshwrite
    return write_mesh(mesh, serialized_mesh, information_only=information_only, use_compression=use_compression)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/itkwasm_mesh_io/write_mesh.py", line 30, in write_mesh
    func(mesh, serialized_mesh, information_only=information_only, use_compression=use_compression)
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/itkwasm_mesh_io_wasi/write_mesh.py", line 54, in write_mesh
    could_write = io(mesh, serialized_mesh, information_only=information_only, use_compression=use_compression)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/itkwasm_mesh_io_wasi/stl_write_mesh.py", line 82, in stl_write_mesh
    outputs = _pipeline.run(args, pipeline_outputs, pipeline_inputs)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/itkwasm/pipeline.py", line 354, in run
    return_code = ri.delayed_start()
                  ^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/itkwasm/pipeline.py", line 148, in delayed_start
    return_code = func(self._store)
                  ^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/wasmtime/_func.py", line 93, in __call__
    with enter_wasm(store) as trap:
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/contextlib.py", line 144, in __exit__
    next(self.gen)
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/wasmtime/_func.py", line 265, in enter_wasm
    raise trap_obj
wasmtime._trap.Trap: error while executing at wasm backtrace:
    0: 0x5199c - <unknown>!<wasm function 673>
    1: 0xa6af5 - <unknown>!<wasm function 1253>
note: using the `WASMTIME_BACKTRACE_DETAILS=1` environment variable may show more debugging information

Caused by:
    wasm trap: wasm `unreachable` instruction executed

@thewtex
Copy link
Member Author

thewtex commented Sep 24, 2024

@neurolabusc, thank you for the review and testing!

However, it fails on any mesh created with 3DSlicer. I tried several different meshes of different formats that loaded fine in slicer and the slicer output vtk meshes would be read fine by other tools (Slicer, NiiVue, Surfice). However, while meshread does not complain opening these vtk format meshes, it fails whenever your try to save it, regardless of the format (iwm.cbor, vtk, obj, stl):

WIP fix for this is here:

@thewtex thewtex merged commit bf4cb27 into InsightSoftwareConsortium:main Sep 24, 2024
41 of 69 checks passed
@thewtex thewtex deleted the wasi-file-format-example branch September 24, 2024 11:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants