Open bogovicj opened 1 year ago
I called this a RealStackCompositeView
, but don't like that name.
maybe RealListCompositeView
?
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:
RealRandomAccessible<T> unstackRealComposite( RealRandomAccessible<Composite<T>> stack, int component )
but also with a better name
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 DisplacementFieldTransform
s, and I believe they still could be because somehow needs to build a RealRandomAccessible<RealLocalizable>
to create a DisplacementFieldTransform
.
We left this PR for a year because one (common) way to create the RealRandomAccessible<RealLocalizable>
is by collapsing then interpolating. That works because some interpolators (specifically NLinearInterpolator
s can work on Composite
s, because Composite
s are NumericType
s
Other interpolators will not work today, for example:
because they use RealType
s. and even RealComposite
types are not RealType
s.
We might choose to make some composite types RealType
s, but that would sacrifice some nice behavior, for example clipping. Clipping requires a min and max value, and there's no ordering of vectors. There are at least three clipping interpolators: Lanczos Bspline and ClampingNLinearInterpolator
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 BiConverter
s, but it's very verbose:
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