Skip to content

Instantly share code, notes, and snippets.

@bogovicj
Created September 1, 2022 18:54
Show Gist options
  • Save bogovicj/c2e8258ce0b7fa33957e3b8b8c42d387 to your computer and use it in GitHub Desktop.
Save bogovicj/c2e8258ce0b7fa33957e3b8b8c42d387 to your computer and use it in GitHub Desktop.
create an interator over a real interval using an imgli2 converter
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