unibas-gravis / scalismo

Scalable Image Analysis and Shape Modelling
https://scalismo.org
Apache License 2.0
247 stars 65 forks source link

Inconsistent reading and writing in StatismoIO #426

Closed Andreas-Forster closed 7 months ago

Andreas-Forster commented 8 months ago

There is an inconsistency in writing and reading data. This makes it possible to write models which can't be read in again. The concrete problem is: If no cells are present, nothing is written, but reading a file where no cells are written fails. The following lines show the issue:

Nothing is written if cells are empty here: https://github.com/unibas-gravis/scalismo/blob/main/src/main/scala/scalismo/io/statisticalmodel/StatismoIO.scala#L162

Reading throws if cells are not present here: https://github.com/unibas-gravis/scalismo/blob/main/src/main/scala/scalismo/io/statisticalmodel/StatismoIO.scala#L296 and for-comprehension does not handle the error but simply fails here: https://github.com/unibas-gravis/scalismo/blob/main/src/main/scala/scalismo/io/statisticalmodel/StatismoIO.scala#L279

Proposal, we make sure that:

madsendennis commented 8 months ago

This seems to be the problem mentioned in https://github.com/unibas-gravis/scalismo/issues/332 as well. I'll close the other issue as it wasn't as specific, and we can continue the bug in this issue. I like the proposal, don't fail when no cells are available, but return None. Then when creating the domain, we could use createDomainWithCells instead of createDomainWithCells as in the readPointSetRepresentation function.