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
IFunctioninterface with 3 new methods, all calledview. These methods return anIterableRandomAccessibleFunction, which is both anIterableIntervaland aRandomAccessible, and also aViewgiven 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 theIFunctionis done on the fly, returning the result as the numeric content of theRealType outputType. Underlying thecursorandrandomAccessmethods are the corresponding methods in theComputeclass, which does the validation of operations and included images.The 3 new
viewmethods ofIFunctionare:view(), returning aView(anIterableRandomAccessibleFunction) of the sameTypeas the firstRandomAccessibleIntervalfound wrapped in theIFunctionand its nestedIFunctioninstances, if any.view(RealType outputType), like above but specifies theRealTypeto use for the computations, as well as for the return valueRealType. An implict genericConverterusesRealType.setReal(RealType.getRealDouble())for the conversion from input to output.view(RealType outputType, Converter converter), where a explicitConvertermediates the transformation from anyRealTypesubclass in the input "images" (RandomAccessibleInterval) wrapped in theIFunction.In other words, the
viewmethods enable code such as:... without altering the original
imgimage 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
IFunctioninterface, there're several related changes in e.g.OFunction(newchildren()method to collect nestedOFunctioninstances), and to ease the implementation, most classes implementingIFunctionalso extendViewableFunction, an abstract class that implements these 3 methods.The
IFunctionsubclassesNumberSourceandVardo not extendViewableFunctionand theirviewmethods throwUnsupportedOperationException. These two classes represent single values. If anIFunctionis constructed to compute using onlyNumberSourceandVar, invokingviewwill throw anException.