imglib / imglib2

A generic next-generation Java library for image processing
http://imglib2.net/
Other
293 stars 93 forks source link

Add LocalizableRandomAccess that provides access to the position and value supplier #324

Closed cmhulbert closed 1 year ago

cmhulbert commented 1 year ago

Reference: Localizables

Should provide the position without a copy, and the value supplier should not be evalutated unless explicitly called after the get on the LocalizableRandomAcess

tpietzsch commented 1 year ago

this is a bit too cryptic for me ... what is a usage example you envision for this LocalizableRandomAccess?

cmhulbert commented 1 year ago

Sorry I was a bit hasty when I wrote this. I wrote this with @axtimwalde, so he may be able to provide additional context as well.

Wanting something like this came up when trying to use LoopBuilder over a set of images, and have access to both the values, and the positions they are at. Using the current LocalizableRandomAccess should make this possible, but then you are moving two cursors for each pixel, one for the values, and one for the positions. This proposal was to provide a variant of LocalizableRandomAcess which would have a get that returns a Pair<Localizable, Supplier<T>>. This allows us to use the position without having to move a duplicate cursor, as well as have access to the value at that location, but only if needed, hence the supplier.

axtimwalde commented 1 year ago

We will implement this next week, it's a reminder to self.