Lazy-load ImageServer from ImageData#1489
Conversation
Rough draft at an alternative approach to address the issue raised in qupath#1488
|
This approach is much more elegant than #1488, i like it! Perhaps this could be done by exposing a |
We no longer permit an ImageData with a null server.
Support accessing the metadata for an ImageServer directly for the `ImageData`. This is a step towards making metadata accessible without having to load the full image.
|
Thank you for the big work on the metadata as well! I will test this PR thoroughly as soon as i can. In the mean time i have a spotted a couple of typos for which i hope i won't pass as annoying if i point them out |
|
Thanks, I've fixed two of the typos but not sure about the other. This is still a draft PR and I'll need to work on it some more. It is a slightly scary change to make since it is so core, and there are (at least) three things I haven't really thought through:
At the moment, I doubt this PR does the right thing in those cases. I'll mark it was ready to review when I think it's ok - that's probably the better time for thorough testing. |
Yes, i get it. It's better being cautious here!
what I would say that in that case it would load the server, read the metadata and write them in the
Again, if
What's wrong in behaving the same as when an exception occurs while creating an |
Avoid deprecated `setLenient()` and add `getPrettyPrintInstance()` to avoid relying on the mysterious `getInstance(boolean)`.
Fix (hopefully) but whereby the wrong thumbnail image could sometimes be shown.
Serialize the `ServerBuilder` and not the `ImageServer`, which means we can serialize without needing to build the server itself. Also support creating an `ImageServer` from a `ServerBuilder` JSON representation directly. This means that an`ImageServer` can be created with `fromJson(json, ImageServer.class)` applied to the output of both `toJson(obj, ServerBuilder.class)` and `toJson(obj, ImageServer.class)`
This includes setting the server name when the project entry is being loaded. Usually, this should already have been set previously - but could be out of sync if the name was changed and the data not saved.
|
I've flagged this as ready for review now. It definitely needs more testing. As described by @carlocastoldi the server is loaded whenever any change to the metadata is made. The server can be loaded more often might be expected, sometimes for subtle, hard-to-address reasons. Some relevant facts:
This basically means that lazy-loading only works if the data for an image has been saved at least once, and the user hasn't messed around too much with image names within their project. The 'easy' way to trigger an image to be saved once is to do a 'Run for project' script - even if the script doesn't do anything. This should be enough to prompt the |
Make clearer that this is permitted to return null.
|
I'll merge this now to avoid having too many conflicts to resolve, and to have more time to try it in combination with all the other v0.6.0 changes. I'd still be grateful for anyone interested to test this! |
|
Thank you, this was pretty fast! Accordingly to my testing it works all okay and pretty safe. I think the idea to write as soon as something is being modified is worth it. The fact that now it requires that the images are opened & modified at least once is not a problem. I think we can put up with it for the time being and leave it for some future adjustment, if needed. However i think you got something off: it should be possible to write the imagedata if the server was never loaded. The problem is not that the image name is always written to the ImageData's file, as that does not make the metadata different from the old ones when the name was kept as is. |
|
One more thing: should we expose the builders in |
|
I'd rather not expose more than necessary. What would it solve? (I seem to have introduced a big bug in |
|
I am sorry, I must have missed this message! In my case, I was thinking to help extensions I use to take full advantage of this new feature. Specifically, I was looking into I guess interrogating specific image server is unfeasible (i.e. using |
Rough draft at an alternative approach to address the issue raised in #1488