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

SSM with no triangulation - read-write inconsistency #332

Open
madsendennis opened this issue Feb 14, 2020 · 7 comments
Open

SSM with no triangulation - read-write inconsistency #332

madsendennis opened this issue Feb 14, 2020 · 7 comments
Labels

Comments

@madsendennis
Copy link
Collaborator

There is some inconsistency to the StatisticalModelIO when reading and writing an SSM without the reference mesh having a triangulation (empty TriangleList).
A file can successfully be written. But when read, it fails due to the processing of missing items in "representer/cells".

Below is a small example which will show the error:

object ModelSaveLoadTest extends App {
  implicit val Random: Random = scalismo.utils.Random(1024)

  println("starting app...")
  scalismo.initialize()

  val zeroMean = VectorField(RealSpace[_3D], (_: Point[_3D]) => EuclideanVector.zeros[_3D])

  val cov: MatrixValuedPDKernel[_3D] = new MatrixValuedPDKernel[_3D]() {
    private val kernel = DiagonalKernel(GaussianKernel[_3D](1), 3)

    override protected def k(x: Point[_3D], y: Point[_3D]): DenseMatrix[Double] = {
      kernel(x, y)
    }
    override def outputDim = 3
    override def domain: Domain[_3D] = RealSpace[_3D]
  }

  val gp = GaussianProcess[_3D, EuclideanVector[_3D]](zeroMean, cov)

  val pointDomain = UnstructuredPointsDomain[_3D](IndexedSeq(Point3D(0, 0, 0), Point3D(1, 0, 0), Point3D(0, 1, 0)))
  val mesh = TriangleMesh3D(pointDomain, TriangleList(IndexedSeq()))

  val sampler = RandomMeshSampler3D(mesh, 10, 1024)
  val lowRankGP = LowRankGaussianProcess.approximateGPNystrom(gp, sampler, numBasisFunctions = 100)

  val ssm = StatisticalMeshModel(mesh, lowRankGP)

  val modelFile = new File("/tmp/dummy.h5")
  StatisticalModelIO.writeStatisticalMeshModel(ssm, modelFile)
  println("File written")
  StatisticalModelIO.readStatisticalMeshModel(modelFile).get
  println("File read")
}

Exception in thread "main" ncsa.hdf.hdf5lib.exceptions.HDF5Exception: ncsa.hdf.hdf5lib.exceptions.HDF5Exception: No data to read.

The error traces back to line 312 in the StatisticalModelIO.scala file.

@madsendennis
Copy link
Collaborator Author

Closing issue as the discussion/issue will continue in #426

@Andreas-Forster
Copy link
Member

This issue goes futher than #426. #426 is needed to write and read back in UnstructuredPointsDomains. But fixing #426 will facilitate fixing this issue. It will remain to change StatismoDomainIO to allow the construction of the different domains also without cells. Currently this fails with a Throwable.

If it makes sense to write/read TriangleMeshes without cells is for me something we should agree on in the community. I have not a too strong opionion in either direction.

@madsendennis
Copy link
Collaborator Author

Thank you for looking more into this @Andreas-Forster. I'm okay with the solution as long as it is consistent with reading and writing. However, I lean more towards keeping the flexibility of writing a triangleMesh with no cells (and even no points) - since this is a valid triangleMesh in Scalismo, I don't see why we then shouldn't be able to read/write it.

@Andreas-Forster
Copy link
Member

I would not block the additional flexibility, if we think it's the strategy in scalismo to allow that.

I think the discussion is, is a TriangleMesh with no cells, and maybe no points still a TriangleMesh? In case we say this is a valid TriangleMesh, even that it is maybe not a very usefull one, we should change the handling of the situation where no cells are read. Otherwise we should make the type TriangleMesh stricter.

@marcelluethi What do you think? Do you have any preference?

@marcelluethi
Copy link
Contributor

Thanks for starting this discussion. We should allow for triangle meshes, where not all the vertices are connected with triangles, as this situation can occur if we clip with a predicate. If we allow some vertices to be not connected with others, I would find it consistent to allow all vertices have no triangles.

@Andreas-Forster
Copy link
Member

Ok this sounds reasonable. I will then update the PR #427 to fix also this issue.

@Andreas-Forster
Copy link
Member

I update the PR #427, so this issue should also be fixed when we merge the PR.

Andreas-Forster added a commit that referenced this issue Mar 21, 2024
…g-and-writing-in-statismoio

Fix/426 inconsitent reading and writing in statismoio

- fixes #426
- fixes #332
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants