/** * @param affineGet {@link AffineGet} to be checked * @return true, if the given {@link AffineGet} affineGet only scales. */ public static boolean isExclusiveScale( final AffineGet affineGet ) { if ( affineGet instanceof ScaleGet ) { return true; } final int n = affineGet.numDimensions(); for ( int r = 0; r < n; ++r ) { for ( int c = 0; c < n + 1; ++c ) { if ( affineGet.get( r, c ) != 0.0 && r != c ) { return false; } } } return true; }
public static String printAffine3D( final AffineGet model ) { final double[] m = model.getRowPackedCopy(); return "(" + f.format( m[ 0 ] ) + ", " + f.format( m[ 1 ] ) + ", " + f.format( m[ 2 ] ) + ", " + f.format( m[ 3 ] ) + "), " + "(" + f.format( m[ 4 ] ) + ", " + f.format( m[ 5 ] ) + ", " + f.format( m[ 6 ] ) + ", " + f.format( m[ 7 ] ) + "), " + "(" + f.format( m[ 8 ] ) + ", " + f.format( m[ 9 ] ) + ", " + f.format( m[ 10 ] )+ ", " + f.format( m[ 11 ] )+ ")"; }
/** * See a {@link RealRandomAccessible} as transformed by an {@link AffineGet} * . The {@link AffineGet} is interpreted according to the natural * understanding that the source is transformed by it. E.g. a positive * translation of dimension <em>x</em> would shift the source to the right. * Therefore, the samples need to be generated by the inverse of the * {@link AffineGet}. Here, the {@link AffineGet} is inverted using it's * {@link AffineGet#inverse()} method that is expected to generate an * inverse that changes with the original transformation accordingly. That * way, changing the state of the {@link AffineGet} will immediately change * the state of any new {@link RealRandomAccess} generated by the view. * * @param source * the {@link RealRandomAccessible} to be transformed * @param transformFromSource * the {@link InvertibleRealTransform} transforming source * coordinates to coordinates of the returned * {@link RealRandomAccessible} * @param <T> the type * * @return {@link AffineRealRandomAccessible} representing the transformed * source */ public static < T > AffineRealRandomAccessible< T, AffineGet > affineReal( final RealRandomAccessible< T > source, final AffineGet transformFromSource ) { return new AffineRealRandomAccessible< >( source, transformFromSource.inverse() ); }
@Override final public AffineTransform2D preConcatenate( final AffineGet affine ) { assert affine.numSourceDimensions() >= 2: "Only >=2d affine transformations can be pre-concatenated to a 2d affine transformation."; final double am00 = affine.get( 0, 0 ); final double am01 = affine.get( 0, 1 ); final double am02 = affine.get( 0, 2 ); final double am10 = affine.get( 1, 0 ); final double am11 = affine.get( 1, 1 ); final double am12 = affine.get( 1, 2 ); final double a00 = am00 * a.m00 + am01 * a.m10; final double a01 = am00 * a.m01 + am01 * a.m11; final double a02 = am00 * a.m02 + am01 * a.m12 + am02; final double a10 = am10 * a.m00 + am11 * a.m10; final double a11 = am10 * a.m01 + am11 * a.m11; final double a12 = am10 * a.m02 + am11 * a.m12 + am12; a.m00 = a00; a.m01 = a01; a.m02 = a02; a.m10 = a10; a.m11 = a11; a.m12 = a12; invert(); updateDs(); inverse.updateDs(); return this; }
assert plane.numDimensions() == transform.numDimensions(); final int n = transform.numDimensions(); transform.apply( O, tO ); m[ r ][ c ] = transform.inverse().get( c, r ); final double[] tN = new double[ n ]; LinAlgHelpers.mult( m, plane.getNormal(), tN );
private static AffineGet simplifyAffineGet( final AffineGet affineGet ) final int n = affineGet.numDimensions(); translations[ d ] = affineGet.get( d, n ); scalings[ d ] = affineGet.get( d, d ); for ( int d = 0; d < n; d++ ) t[ d ] = affineGet.get( d, n ); s[ d ] = affineGet.get( d, d ); return ( AffineGet ) affineGet.copy();
@Override final public AffineTransform3D concatenate( final AffineGet affine ) { assert affine.numSourceDimensions() >= 3: "Only >=3d affine transformations can be concatenated to a 3d affine transformation."; a.concatenate( affine.getRowPackedCopy() ); invert(); updateDs(); inverse.updateDs(); return this; }
@Override public ObservableValue< String > call(CellDataFeatures< RegistrationExplorerRow, String > param) { RegistrationExplorerRow row = param.getValue().getValue(); // single transform -> return matrix element if (row.rowType == RegistrationExplorerRowType.REGISTRATION) return new ReadOnlyStringWrapper(Double.toString( viewRegistrations.getViewRegistration( row.vd).getTransformList().get( row.transformIndex ).asAffine3D().get( matRow, matColumn ))); // else return empty String else return new ReadOnlyStringWrapper(); }
public ArrayList< Double > getErrors(Set<ViewId> vid) { List<PairwiseStitchingResult<ViewId>> psrs = getAllPairwiseResultsForViewId( vid ); ArrayList< Double > res = new ArrayList<>(); for (PairwiseStitchingResult <ViewId>psr : psrs) { if (globalShifts.containsKey( psr.pair().getA()) && globalShifts.containsKey( psr.pair().getB() )) { double[] vGlobal1 = new double[3]; double[] vGLobal2 = new double[3]; double[] vPairwise = new double[3]; globalShifts.get( psr.pair().getA() ).apply( vGlobal1, vGlobal1 ); globalShifts.get( psr.pair().getB() ).apply( vGLobal2, vGLobal2 ); psr.getTransform().apply( vPairwise, vPairwise ); double[] relativeGlobal = VectorUtil.getVectorDiff( vGlobal1, vGLobal2 ); res.add( new Double(VectorUtil.getVectorLength( VectorUtil.getVectorDiff( relativeGlobal, vPairwise ) )) ); } } return res; }
link.getTransform().applyInverse( pb[i], pa[i] ); pointsA.add( new Point( pa[i] ) ); pointsB.add( new Point( pb[i] ) );
assert polytope.numDimensions() == transform.numDimensions(); final int n = transform.numDimensions(); for ( int r = 0; r < n; ++r ) for ( int c = 0; c < n; ++c ) m[r][c] = transform.inverse().get( c, r ); transform.apply( O, tO ); LinAlgHelpers.mult( m, plane.getNormal(), tN ); LinAlgHelpers.normalize( tN );
@Override final public AffineTransform2D concatenate( final AffineGet affine ) { assert affine.numSourceDimensions() >= 2: "Only >=2d affine transformations can be concatenated to a 2d affine transformation."; final double am00 = affine.get( 0, 0 ); final double am01 = affine.get( 0, 1 ); final double am02 = affine.get( 0, 2 ); final double am10 = affine.get( 1, 0 ); final double am11 = affine.get( 1, 1 ); final double am12 = affine.get( 1, 2 ); final double a00 = a.m00 * am00 + a.m01 * am10; final double a01 = a.m00 * am01 + a.m01 * am11; final double a02 = a.m00 * am02 + a.m01 * am12 + a.m02; final double a10 = a.m10 * am00 + a.m11 * am10; final double a11 = a.m10 * am01 + a.m11 * am11; final double a12 = a.m10 * am02 + a.m11 * am12 + a.m12; a.m00 = a00; a.m01 = a01; a.m02 = a02; a.m10 = a10; a.m11 = a11; a.m12 = a12; invert(); updateDs(); inverse.updateDs(); return this; }
@Override final public AffineTransform3D preConcatenate( final AffineGet affine ) { assert affine.numSourceDimensions() == 3: "Only 3d affine transformations can be preconcatenated to a 3d affine transformation."; a.preConcatenate( affine.getRowPackedCopy() ); invert(); updateDs(); inverse.updateDs(); return this; }
translation.set( translation.get( 0, 3 ) * calibration.asAffine3D().get( 0, 0 ), 0, 3 ); translation.set( translation.get( 1, 3 ) * calibration.asAffine3D().get( 1, 1 ), 1, 3 ); translation.set( translation.get( 2, 3 ) * calibration.asAffine3D().get( 2, 2 ), 2, 3 ); vr.preconcatenateTransform( new ViewTransformAffine( "Translation to Regular Grid", translation ));
public static double[] getCenterOfMass(Collection< Pair< Dimensions, AffineGet > > views) { if (views.size() < 1) return null; final int nDims = views.iterator().next().getA().numDimensions(); final double[] center = new double[nDims]; final double[] vertex = new double[nDims]; final double[] vertexTransformed = new double[nDims]; int count = 0; for (final Pair< Dimensions, AffineGet > view : views) { for (int i = 0; i< (int) Math.pow( 2, nDims ); i++) { // get i'th vertex of (0, 0, ...) - (dim_0, dim_1, ...) int ii = i; for (int j = 0; j<nDims; j++) { vertex[j] = ii%2 == 0 ? 0 : view.getA().dimension( j ); ii /= 2; } view.getB().apply( vertex, vertexTransformed ); for (int j = 0; j<nDims; j++) center[j] += vertexTransformed[j]; count++; } } for (int i = 0; i<nDims; i++) center[i] /= count; return center; }
/** * @param affineGet {@link AffineGet} to be checked * @return true, if the given {@link AffineGet} only translates. */ public static boolean isExlusiveTranslation( final AffineGet affineGet ) { if ( affineGet instanceof TranslationGet ) { return true; } final int n = affineGet.numDimensions(); for ( int r = 0; r < n; ++r ) { for ( int c = 0; c < n + 1; ++c ) { final double val = affineGet.get( r, c ); if ( val != 0.0 && ( ( r == c && val != 1.0 ) || ( c != n && val != 1.0 ) ) ) { return false; } } } return true; }
public void set( final AffineGet affine ) { assert n == affine.numSourceDimensions(): "Dimensions do not match."; for ( int r = 0; r < n; ++r ) { for ( int c = 0; c < n; ++c ) a.set( r, c, affine.get( r, c ) ); t[ r ] = affine.get( r, n ); } updateDs(); invert(); inverse.updateDs(); }
public static AffineModel3D getModel( final AffineGet affine ) { final double[] m = affine.getRowPackedCopy(); final AffineModel3D model = new AffineModel3D(); model.set( m[ 0 ], m[ 1 ], m[ 2 ], m[ 3 ], m[ 4 ], m[ 5 ], m[ 6 ], m[ 7 ], m[ 8 ], m[ 9 ], m[ 10 ], m[ 11 ] ); return model; }
j /= 2; transform.apply( f, g ); Util.min( rMin, g ); Util.max( rMax, g );
/** * See a {@link RealRandomAccessible} as a {@link RandomAccessible} * transformed by an {@link AffineGet}. The {@link AffineGet} is interpreted * according to the natural understanding that the source is transformed by * it. E.g. a positive translation of dimension <em>x</em> would shift the * source to the right. Therefore, the samples need to be generated by the * inverse of the {@link AffineGet}. Here, the {@link AffineGet} is inverted * using it's {@link AffineGet#inverse()} method that is expected to * generate and inverse that changes with the original transformation * accordingly. That way, changing the state of the {@link AffineGet} will * immediately change the state of any new {@link RandomAccess} generated * by the view. * * @param source * the {@link RealRandomAccessible} to be transformed * @param transformFromSource * the {@link InvertibleRealTransform} transforming source * coordinates to coordinates of the returned * {@link RealRandomAccessible} * @param <T> the type * * @return {@link AffineRandomAccessible} representing the transformed * source */ public static < T > AffineRandomAccessible< T, AffineGet > affine( final RealRandomAccessible< T > source, final AffineGet transformFromSource ) { return new AffineRandomAccessible< >( source, transformFromSource.inverse() ); }