InsightSoftwareConsortium / ITK-Wasm

High performance spatial analysis in a web browser and across programming languages and hardware architectures
https://wasm.itk.org
Apache License 2.0
194 stars 48 forks source link

IWM format specification #1235

Open neurolabusc opened 1 day ago

neurolabusc commented 1 day ago

The docs provide an example of converting that is a Serialization of a Mesh . However, the definition of the Cell is never specified, even in the section 4.3.2 Inserting Cells. To make my question concrete, consider the provided example of the 'cow.vtk' format converted to 'cow.iwm.cbor':

The cow.vtk provides vertex indices for quads (4 vertices) and triangles (3 vertices)

POLYGONS 3263 15593
4 250 251 210 252 
4 252 210 201 253 
3 253 201 254 
4 254 255 256 253 

However, the cow.iwm.cbor cells includes an additional element that in this example is always 4 for quads and 2 for triangles. What is the purpose of the element - for this example it just makes the file size larger, but presumably it has the potential to have other values. While I can write a reader for the provided example, I fear it will be fragile if I do not know what this value is supposed to mean. Is 2 a constant for TriangleCell

4 4 250 251 210 252 
4 4 252 210 201 253 
2 3 253 201 254 
4 4 254 255 256 253 

Based on 4.3.8 Iterating Through Cells my best guess is that this is the enum for cell type:

0 VERTEX_CELL
1 LINE_CELL
2 TRIANGLE_CELL
3 QUADRILATERAL_CELL
4 POLYGON_CELL
...

If this is the case, is there any reason the quads are not listed as QUADRILATERAL_CELL and not POLYGON_CELL types? It does seem that for VERTEX_CELL...QUADRILATERAL_CELL the number of indices is explicit, so this seems to lead to large file sizes than necessary. I understand there are always tradeoffs in file formats for consistency across types versus efficiency, I just want to make sure I understand the logic.

iwm

thewtex commented 1 day ago

@neurolabusc thanks for the report. I will provide more documentation.