InsightSoftwareConsortium / InsightSoftwareConsortium/ITK-Wasm

Issue with WaveFront OBJ meshes

Open
#1,243 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
235
Forks
61
Avg merge
4d 19h
Merged PRs (30d)
4

Description

Here is the same mesh as a [WaveFront .obj file](https://drive.google.com/file/d/1XxPTsie1KagO4peaYyUzOBvSAKvZVAg_/view?usp=drive_link) nd [STL format mesh](https://drive.google.com/file/d/1CKhl80nhYPLS5nnkxWjceY6s0YkN5ujE/view?usp=drive_link). I can easily convert the vtk format file, but the converting the obj file results in a iwm.cbor file that has nonsense values.

```python
from itkwasm_image_io import imread, imwrite
from itkwasm_mesh_io import meshread, meshwrite
mesh = meshread('brain.obj')
meshwrite(mesh, 'brainOBJ.iwm.cbor')
mesh = meshread('brain.stl')
meshwrite(mesh, 'brainSTL.iwm.cbor')
mesh = meshread('brain.vtk')
meshwrite(mesh, 'brainVTK.iwm.cbor')
```

The cells from the STL file are BigUint64Array with each triangle listed as `2 3 i j k` where `2` is indicates a triangle type and 3 indicates that three indices follows, with i j k being the indices:
![Screenshot 2024-09-21 at 6 46 13 PM](https://github.com/user-attachments/assets/4b2460d2-2cc2-4127-b345-d04415178b96)

In contrast, all the values for the converted OBJ files are huge - out of range of all triangles and of invalid cell types:

![Screenshot 2024-09-21 at 6 45 24 PM](https://github.com/user-attachments/assets/d3252046-fdd3-4b33-822a-9417ee64b2d7)

3DSlicer, Meshlab, Surfice and NiiVue all open the OBJ file fine. I note that the [ITK code](https://github.com/InsightSoftwareConsortium/ITK/blob/f43b1b8977fa05d169c14b4c6f44ce35992a3959/Modules/IO/MeshOBJ/src/itkOBJMeshIO.cxx#L163) is designed to read faces (`f`), vertices (`v`) and the [optional](https://en.wikipedia.org/wiki/Wavefront_.obj_file#Vertex_normal_indices) vertex normals (`vn`), while this file only has vertices and faces, so perhaps ITK demands the normals.

Contributor guide

Open the contributing guide

Research direction

Start with the Python reproduction using meshread and meshwrite on the linked OBJ and STL files, then compare the generated iwm.cbor cell arrays. Read the referenced Modules/IO/MeshOBJ/src/itkOBJMeshIO.cxx OBJ reader, focusing on face and vertex handling. Done means OBJ conversion produces valid triangle cell types and in-range indices like the STL conversion.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, wasm
Domain
computer-graphics
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.