ImgMath: math operations can now be viewed without having to copy the result into an image #76
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The first two commits are cosmetic changes that can be ignored.
The second commit updates the
IFunction
interface with 3 new methods, all calledview
. These methods return anIterableRandomAccessibleFunction
, which is both anIterableInterval
and aRandomAccessible
, and also aView
given that its data should be cached when planning to do multiple accesses on the same positions. When iterating its data withIterableRandomAccessibleFunction.cursor()
orIterableRandomAccessibleFunction.randomAccess()
, the computation described by theIFunction
is done on the fly, returning the result as the numeric content of theRealType outputType
. Underlying thecursor
andrandomAccess
methods are the corresponding methods in theCompute
class, which does the validation of operations and included images.The 3 new
view
methods ofIFunction
are:view()
, returning aView
(anIterableRandomAccessibleFunction
) of the sameType
as the firstRandomAccessibleInterval
found wrapped in theIFunction
and its nestedIFunction
instances, if any.view(RealType outputType)
, like above but specifies theRealType
to use for the computations, as well as for the return valueRealType
. An implict genericConverter
usesRealType.setReal(RealType.getRealDouble())
for the conversion from input to output.view(RealType outputType, Converter converter)
, where a explicitConverter
mediates the transformation from anyRealType
subclass in the input "images" (RandomAccessibleInterval
) wrapped in theIFunction
.In other words, the
view
methods enable code such as:... without altering the original
img
image in anyway.Before, one had to copy the result of the computation into a new image in order to see it.
Along with the changes in the
IFunction
interface, there're several related changes in e.g.OFunction
(newchildren()
method to collect nestedOFunction
instances), and to ease the implementation, most classes implementingIFunction
also extendViewableFunction
, an abstract class that implements these 3 methods.The
IFunction
subclassesNumberSource
andVar
do not extendViewableFunction
and theirview
methods throwUnsupportedOperationException
. These two classes represent single values. If anIFunction
is constructed to compute using onlyNumberSource
andVar
, invokingview
will throw anException
.