"Stack" RealRandomAccessibles as Composite#318
Conversation
* with a test
* enforce at least one source
|
I called this a |
|
I won't keep working on this until there is a more urgent use case but will leave this open in case we'd like to revisit in the future. This needs a better name for the class, and probably would benefit from a view that does the "inverse" operation, something like: |
|
I'd like to revist this. There are at least two specific applications for the code provided by this PR. One I describe below, the other is in paintera - @cmhulbert can point it one if it's of interest. When I initially started this, I thought it might be useful for building We left this PR for a year because one (common) way to create the Other interpolators will not work today, for example: because they use We might choose to make some composite types A straightfoward solution to interpolate each component of the vector independently, then "stack" them. Given a list of vector componets: final RealRandomAccessible<T>[] components It is possible to do this now with final BiConverter<T, T, RealComposite<DoubleType>> conv0 = new BiConverter<T,T,RealComposite<DoubleType>>()
{
@Override
public void convert( T x, T y, RealComposite<DoubleType> output ) {
output.get(0).set(x.getRealDouble());
output.get(1).set(y.getRealDouble());
}
};
final int N = 3;
final RealComposite<DoubleType> v = DoubleType.createVector(N);
final RealRandomAccessible<RealComposite<DoubleType>> img = Converters.convert( components[0], components[1], conv0, v);
RealRandomAccessible<RealComposite<DoubleType>> total = img;
for( int i = 2; i < N; i++ )
{
final int j = i;
total = Converters.convert(
total,
components[i],
new BiConverter<RealComposite<DoubleType>,T,RealComposite<DoubleType>>()
{
@Override
public void convert( RealComposite<DoubleType> part, T x, RealComposite<DoubleType> whole ) {
for( int d = 0; d < j; d++ )
whole.get(d).set(part.get(d));
whole.get(j).set(x.getRealDouble());
}
},
v.copy());
}This PR would RealRandomAccessible<Composite<T>> total2 = Views.realComposite(components); |
see #317