Frame<P> singleFrame = actualFrames.get(0);
Matrix<? extends PArray> m = singleFrame.matrix();
FramePosition p = singleFrame.position();
if (integerShiftPositions) {
// System.out.println("1 frame branch: integer coordinates");
Point o = p.area().min();
IPoint localOffset = o.toRoundedPoint();
assert o.equals(localOffset.toPoint());
Matrix<T> casted = Matrices.asFuncMatrix(Func.IDENTITY, requiredType, m);
// - must be before subMatr, if requiredType allows outsideValue, but the source matrix does not
return casted.subMatr(localOffset.symmetric().coordinates(), dimensions,
Matrix.ContinuationMode.getConstantMode(outsideValue(actualFrames)));
}
if (p instanceof UniversalFramePosition
&& ((UniversalFramePosition)p).inverseTransform() instanceof LinearOperator)
{
LinearOperator inverseTransform = (LinearOperator)((UniversalFramePosition)p).inverseTransform();
// System.out.println("1 frame branch: linear operator " + inverseTransform);
LinearOperator shift = LinearOperator.getShiftInstance(area.min().coordinates());
LinearOperator lo = shift.superposition(inverseTransform);
Func f = Matrices.asInterpolationFunc(m, Matrices.InterpolationMethod.POLYLINEAR_FUNCTION,
outsideValue(actualFrames));
f = lo.apply(f);
return Matrices.asCoordFuncMatrix(f, requiredType, dimensions);
}
}
if (integerShiftPositions && stitchingMethod instanceof CoordinateFreeStitchingMethod<?>) {
// System.out.println("coordinate free branch: combining submatrices");
// optimization: here we can just create corresponded submatrices
List<Matrix<? extends PArray>> expandedMatrices =
new ArrayList<Matrix<? extends PArray>>(actualFrames.size());
for (Frame<P> localFrame : actualFrames) {
Point o = localFrame.position().area().min();
IPoint localOffset = o.toRoundedPoint();
assert o.equals(localOffset.toPoint());
Matrix<? extends PArray> m = localFrame.matrix();
m = Matrices.asFuncMatrix(Func.IDENTITY, DoubleArray.class, m);
// - we need Double virtual matrix to provide correct NaN values to the combining function
m = m.subMatr(localOffset.symmetric().coordinates(), dimensions, Matrix.ContinuationMode.NAN_CONSTANT);
expandedMatrices.add(m);