Created
September 1, 2022 18:54
-
-
Save bogovicj/c2e8258ce0b7fa33957e3b8b8c42d387 to your computer and use it in GitHub Desktop.
create an interator over a real interval using an imgli2 converter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static IterableInterval< RealPoint > usingConverters( RealInterval interval, int... numSteps ) | |
{ | |
final int nd = interval.numDimensions(); | |
final double[] steps = stepsFromSamples( interval, fillWithLast( nd, numSteps ) ); | |
final RandomAccessibleInterval< Localizable > samples = Localizables.randomAccessibleInterval( | |
new FinalInterval( Arrays.stream( steps ).mapToLong( x -> (long)x ).toArray() )); | |
RandomAccessibleInterval< RealPoint > positions = Converters.convert2( samples, (x,y) -> { | |
for( int i = 0; i < nd; i++ ) | |
y.setPosition( | |
interval.realMin( i ) + steps[ i ] * x.getDoublePosition( i ), | |
i ); | |
}, () -> new RealPoint(nd)); | |
return Views.flatIterable( positions ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment