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

Feature/modularize statismo io for better composition #425

Conversation

Andreas-Forster
Copy link
Member

This is a proposal for a change. Please comment or suggest freely.

Currently it is not possible to write two models into one hdf5file. One place where this is used is the ASM model. But having intensity models and volume models, it could also be interesting to write two models into one file.

This PR splits the functions into the file handling part and the actual writing of the data. Like this one could also open a file to write and write two models at different locations. The decision to make them private was to guard them somehow against accidental use due to IDE suggestion.

@Andreas-Forster Andreas-Forster changed the base branch from main to release-1.0 February 1, 2024 21:48
@madsendennis madsendennis marked this pull request as draft February 2, 2024 07:01
@madsendennis
Copy link
Collaborator

Good idea. This would allow us to write a group of models to the same file, or just store different resolution versions of the same model in the same file, I see that this could be useful.

I was wondering if it could be made more abstract such that each model could have a separate [D, DDomain]. Then the .5 could for instance contain different variants of the same model. Intensity, 2D/3D, tetrahedral, triangle mesh, low-res/high-res etc.

@Andreas-Forster
Copy link
Member Author

Note sure if I misunderstood something, but I think this is already possible. You just have to keep track of your model paths yourself at the moment. There would be the model catalogue which was maybe intended to do so somewhen, but it is never written anywhere.

I guess the following should work:

  val linePDM2d: PointDistributionModel[_2D, LineMesh] = ???
  val linePDM3d: PointDistributionModel[_3D, LineMesh] = ???
  val triangleModel3d: StatisticalMeshModel = ???
  val trianglePDM3d: PointDistributionModel[_3D, TriangleMesh] = PointDistributionModel(
    triangleModel3d.gp
  )
  val tetrahedralPDM3d: PointDistributionModel[_3D, TetrahedralMesh] = ???
  val imageIntensityModel3d: DiscreteLowRankGaussianProcess[_3D, DiscreteImageDomain, Float] = ???

  val file: File = ???
  Using(StatisticalModelIOUtils.openFileForWriting(file).get) { h5file =>
    for {
      _ <- StatismoIO.writeStatismoPDM(linePDM2d, h5file, HDFPath("/2d-line-model/"))
      _ <- StatismoIO.writeStatismoPDM(linePDM3d, h5file, HDFPath("/3d-line-model/"))
      _ <- StatismoIO.writeStatismoPDM(trianglePDM3d, h5file, HDFPath("/3d-mesh-model/"))
      _ <- StatismoIO.writeStatismoPDM(tetrahedralPDM3d, h5file, HDFPath("/3d-tetra-model/"))
      _ <- StatismoIO.writeStatismoImageModel(imageIntensityModel3d, h5file, HDFPath("/image-model/"))
    } yield ()
  }

@Andreas-Forster Andreas-Forster changed the title [DISCUSSION] Feature/modularize statismo io for better composition Feature/modularize statismo io for better composition Feb 2, 2024
@Andreas-Forster
Copy link
Member Author

We the recent commit, also an ASM (shape and appearance) can be written at a customizable path.

@madsendennis
Copy link
Collaborator

For the example above, I was thinking if it would be possible to have a function like:

def writeStatisticalShapeModels(models: Seq[(PointDistributionModel[D, Domain], path)], file: File)

And then inside the function match the type of model (D, Domain) with specific writers.

Then in your example above you wouldn't need to manually open the file and specify the paths, but just create a Seq of all the models and apply those to the write function.

But even the suggested update, I also like. I'm just throwing ideas around. :)

@Andreas-Forster Andreas-Forster force-pushed the feature/modularize-statismo-io-for-better-composition branch from 8b51027 to ad460ad Compare February 2, 2024 19:44
@Andreas-Forster Andreas-Forster marked this pull request as ready for review February 2, 2024 19:44
@Andreas-Forster
Copy link
Member Author

Thank you for the clarification. I got now your idea. Using this PR one could start experimenting around. As there are aside of PDMs also intensity and image models, I am not sure if we can easily provide a useful function that is not too generic or complex.

@madsendennis
Copy link
Collaborator

That is true. In that case, I'm fine with merging in the MR as there is no change in the interface. Then it can be extended later if/when needed.

Copy link
Contributor

@marcelluethi marcelluethi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding this feature. Would be happy to merge it.

@Andreas-Forster Andreas-Forster merged commit e59696f into release-1.0 Feb 5, 2024
2 checks passed
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.

3 participants