/** * Adds a range of output dimensions to keep in the separated transform. * The {@code lower} and {@code upper} values define a range of <em>target</em> dimension indices * of the transform given to the constructor. * * @param lower the lower dimension, inclusive. Shall not be smaller than 0. * @param upper the upper dimension, exclusive. Shall be smaller than {@link MathTransform#getTargetDimensions()}. * @throws IllegalArgumentException if {@code lower} or {@code upper} are out of bounds. */ public void addTargetDimensionRange(final int lower, final int upper) throws IllegalArgumentException { targetDimensions = add(targetDimensions, lower, upper, transform.getTargetDimensions()); }
0, 0, 0, 1 ); final TransformSeparator s = new TransformSeparator(MathTransforms.linear(matrix)); assertSame("transform", s.transform, s.separate()); assertArrayEquals("sourceDimensions", new int[] {0, 1, 2}, s.getSourceDimensions()); assertArrayEquals("targetDimensions", new int[] {0, 1, 2}, s.getTargetDimensions()); 0, 0, 0, 1 }); s.clear(); s.addTargetDimensions(0, 2); assertMatrixEquals("transform", matrix, ((LinearTransform) s.separate()).getMatrix(), STRICT); assertArrayEquals("sourceDimensions", new int[] {0, 1, 2}, s.getSourceDimensions()); assertArrayEquals("targetDimensions", new int[] {0, 2}, s.getTargetDimensions()); 0, 0, 1 }); s.clear(); s.addSourceDimensions(1, 2); assertMatrixEquals("transform", matrix, ((LinearTransform) s.separate()).getMatrix(), STRICT); assertArrayEquals("sourceDimensions", new int[] {1, 2}, s.getSourceDimensions()); assertArrayEquals("targetDimensions", new int[] {1}, s.getTargetDimensions()); 0, 0, 1 }); s.clear(); s.addSourceDimensions(0, 2); s.addTargetDimensions(0);
final TransformSeparator s = new TransformSeparator(MathTransforms.identity(8)); try { s.getSourceDimensions(); fail("Shall not return unspecified dimensions."); } catch (IllegalStateException e) { s.getTargetDimensions(); fail("Shall not return unspecified dimensions."); } catch (IllegalStateException e) { s.addSourceDimensionRange(1, 4); s.addTargetDimensions(0, 3, 4); assertArrayEquals("sourceDimensions", new int[] {1, 2, 3}, s.getSourceDimensions()); assertArrayEquals("targetDimensions", new int[] {0, 3, 4}, s.getTargetDimensions()); try { s.addSourceDimensions(3, 4, 5); fail("Shall not accept non-increasing value."); } catch (IllegalArgumentException e) { s.addTargetDimensionRange(3, 5); fail("Shall not accept non-increasing value."); } catch (IllegalArgumentException e) { s.addSourceDimensions(4, 6); s.addTargetDimensionRange(6, 8); assertArrayEquals("sourceDimensions", new int[] {1, 2, 3, 4, 6}, s.getSourceDimensions()); assertArrayEquals("targetDimensions", new int[] {0, 3, 4, 6, 7}, s.getTargetDimensions()); try { s.addSourceDimensions(8);
separator = new TransformSeparator(gridToCRS); separator.addSourceDimensionRange(srcDim, srcDim + 1); final Matrix component = MathTransforms.getMatrix(separator.separate()); if (component != null) { final int[] targets = separator.getTargetDimensions(); for (int j=0; j<targets.length; j++) { final int tgtDim = targets[j]; separator.clear();
TransformSeparator s = new TransformSeparator(tr); assertFalse("trimSourceDimensions", s.getTrimSourceDimensions()); assertSame("No source dimensions should be trimmed if not requested.", tr, s.separate()); assertArrayEquals(new int[] {0, 1, 2}, s.getSourceDimensions()); assertArrayEquals(new int[] {0, 1 }, s.getTargetDimensions()); 0.5, 0, -180, 0, 0, 1); s.setTrimSourceDimensions(true); assertTrue("trimSourceDimensions", s.getTrimSourceDimensions()); MathTransform reduced = s.separate(); assertNotEquals("separate()", tr, reduced); assertArrayEquals(new int[] {0, 1}, s.getSourceDimensions()); assertArrayEquals(new int[] {0, 1}, s.getTargetDimensions()); assertMatrixEquals("separate()", expected, MathTransforms.getMatrix(reduced), STRICT); 0, 0, 0, 1})); s = new TransformSeparator(tr); s.setTrimSourceDimensions(true); reduced = s.separate(); assertNotEquals("separate()", tr, reduced); assertArrayEquals(new int[] {1, 2}, s.getSourceDimensions()); assertArrayEquals(new int[] {0, 1}, s.getTargetDimensions()); assertMatrixEquals("separate()", new Matrix3( 0, 0.5, -90,
ArgumentChecks.ensureDimensionMatches("areaOfInterest", modifiedDimensionCount, areaOfInterest); if (modifiedDimensionCount < gridToAOI.getSourceDimensions()) { final TransformSeparator sep = new TransformSeparator(gridToAOI); sep.setTrimSourceDimensions(true); gridToAOI = sep.separate(); modifiedDimensions = sep.getSourceDimensions(); if (modifiedDimensions.length != modifiedDimensionCount) { throw new TransformException(Resources.format(Resources.Keys.CanNotMapToGridDimensions));
/** * Tests separation of a linear transform containing {@link Double#NaN} values. * * @throws FactoryException if an error occurred while creating a new transform. */ @Test public void testIncompleteTransform() throws FactoryException { Matrix matrix = new Matrix4( 1, 0, 0, 7, 0, 0, 1, 8, 0, NaN, 0, 6, 0, 0, 0, 1 ); TransformSeparator s = new TransformSeparator(MathTransforms.linear(matrix)); s.addSourceDimensions(1); assertMatrixEquals("transform", new Matrix2( NaN, 6, 0, 1 ), ((LinearTransform) s.separate()).getMatrix(), STRICT); assertArrayEquals(new int[] {2}, s.getTargetDimensions()); }
/** * Tests separation of a concatenated transform. * * @throws FactoryException if an error occurred while creating a new transform. */ @Test @DependsOnMethod("testLinearTransform") public void testConcatenatedTransform() throws FactoryException { final MathTransformFactory factory = DefaultFactories.forBuildin(MathTransformFactory.class); final TransformSeparator s = new TransformSeparator(EllipsoidToCentricTransform.createGeodeticConversion( factory, HardCodedDatum.WGS84.getEllipsoid(), false), factory); s.addSourceDimensions(0, 1); s.addTargetDimensions(0, 1); final Iterator<MathTransform> it = MathTransforms.getSteps(s.separate()).iterator(); assertInstanceOf("normalize", LinearTransform.class, it.next()); assertInstanceOf("transform", EllipsoidToCentricTransform.class, it.next()); assertInstanceOf("denormalize", LinearTransform.class, it.next()); assertFalse(it.hasNext()); }
final TransformSeparator s = new TransformSeparator(MathTransforms.passThrough(2, nonLinear, 3)); assertSame("transform", s.transform, s.separate()); assertArrayEquals("sourceDimensions", new int[] {0, 1, 2, 3, 4, 5, 6}, s.getSourceDimensions()); assertArrayEquals("targetDimensions", new int[] {0, 1, 2, 3, 4, 5, 6, 7}, s.getTargetDimensions()); 0, 0, 0, 0, 0, 0, 0, 0, 1 }); s.clear(); s.addTargetDimensions(1, 2, 7); MathTransform result = s.separate(); assertArrayEquals("sourceDimensions", new int[] {0, 1, 2, 3, 4, 5, 6}, s.getSourceDimensions()); assertArrayEquals("targetDimensions", new int[] {1, 2, 7}, s.getTargetDimensions()); final Random random = TestUtilities.createRandomNumberGenerator(); compare(s.transform, MathTransforms.linear(expected), result, random); 0, 0, 0, 0, 0, 0, 0, 1 }); s.clear(); s.addTargetDimensions(1, 5, 7); result = s.separate(); assertArrayEquals ("sourceDimensions", new int[] {0, 1, 2, 3, 4, 5, 6}, s.getSourceDimensions()); assertArrayEquals ("targetDimensions", new int[] {1, 5, 7}, s.getTargetDimensions()); assertInstanceOf ("separate()", LinearTransform.class, result); assertMatrixEquals("separate().transform2", expected, ((LinearTransform) result).getMatrix(), STRICT); 0, 0, 1 ); s.clear();
/** * Adds a range of input dimensions to keep in the separated transform. * The {@code lower} and {@code upper} values define a range of <em>source</em> dimension indices * of the transform given to the constructor. * * @param lower the lower dimension, inclusive. Shall not be smaller than 0. * @param upper the upper dimension, exclusive. Shall be smaller than {@link MathTransform#getSourceDimensions()}. * @throws IllegalArgumentException if {@code lower} or {@code upper} are out of bounds. */ public void addSourceDimensionRange(final int lower, final int upper) throws IllegalArgumentException { sourceDimensions = add(sourceDimensions, lower, upper, transform.getSourceDimensions()); }
/** * Adds a range of input dimensions to keep in the separated transform. * The {@code lower} and {@code upper} values define a range of <em>source</em> dimension indices * of the transform given to the constructor. * * @param lower the lower dimension, inclusive. Shall not be smaller than 0. * @param upper the upper dimension, exclusive. Shall be smaller than {@link MathTransform#getSourceDimensions()}. * @throws IllegalArgumentException if {@code lower} or {@code upper} are out of bounds. */ public void addSourceDimensionRange(final int lower, final int upper) throws IllegalArgumentException { sourceDimensions = add(sourceDimensions, lower, upper, transform.getSourceDimensions()); }
/** * Adds a range of output dimensions to keep in the separated transform. * The {@code lower} and {@code upper} values define a range of <em>target</em> dimension indices * of the transform given to the constructor. * * @param lower the lower dimension, inclusive. Shall not be smaller than 0. * @param upper the upper dimension, exclusive. Shall be smaller than {@link MathTransform#getTargetDimensions()}. * @throws IllegalArgumentException if {@code lower} or {@code upper} are out of bounds. */ public void addTargetDimensionRange(final int lower, final int upper) throws IllegalArgumentException { targetDimensions = add(targetDimensions, lower, upper, transform.getTargetDimensions()); }
/** * Adds output dimensions to keep in the separated transform. * The given values are <em>target</em> dimension indices of the transform given to the constructor. * * <p>Constraints:</p> * <ul> * <li>All numbers shall be in the range 0 inclusive to {@link MathTransform#getTargetDimensions()} exclusive.</li> * <li>The {@code dimensions} values shall be in strictly increasing order.</li> * <li>The {@code dimensions} values shall be greater than all values specified by all previous calls * of this method since construction or since the last call to {@link #clear()}.</li> * </ul> * * @param dimensions a sequence of target dimensions to keep, in strictly increasing order. * @throws IllegalArgumentException if {@code dimensions} contains negative values * or if values are not in a strictly increasing order. */ public void addTargetDimensions(final int... dimensions) throws IllegalArgumentException { ArgumentChecks.ensureNonNull("dimensions", dimensions); targetDimensions = add(targetDimensions, dimensions, transform.getTargetDimensions()); }
/** * Adds input dimensions to keep in the separated transform. * The given values are <em>source</em> dimension indices of the transform given to the constructor. * * <p>Constraints:</p> * <ul> * <li>All numbers shall be in the range 0 inclusive to {@link MathTransform#getSourceDimensions()} exclusive.</li> * <li>The {@code dimensions} values shall be in strictly increasing order.</li> * <li>The {@code dimensions} values shall be greater than all values specified by all previous calls * of this method since construction or since the last call to {@link #clear()}.</li> * </ul> * * @param dimensions a sequence of source dimensions to keep, in strictly increasing order. * @throws IllegalArgumentException if {@code dimensions} contains negative values * or if values are not in a strictly increasing order. */ public void addSourceDimensions(final int... dimensions) throws IllegalArgumentException { ArgumentChecks.ensureNonNull("dimensions", dimensions); sourceDimensions = add(sourceDimensions, dimensions, transform.getSourceDimensions()); }
/** * Adds output dimensions to keep in the separated transform. * The given values are <em>target</em> dimension indices of the transform given to the constructor. * * <p>Constraints:</p> * <ul> * <li>All numbers shall be in the range 0 inclusive to {@link MathTransform#getTargetDimensions()} exclusive.</li> * <li>The {@code dimensions} values shall be in strictly increasing order.</li> * <li>The {@code dimensions} values shall be greater than all values specified by all previous calls * of this method since construction or since the last call to {@link #clear()}.</li> * </ul> * * @param dimensions a sequence of target dimensions to keep, in strictly increasing order. * @throws IllegalArgumentException if {@code dimensions} contains negative values * or if values are not in a strictly increasing order. */ public void addTargetDimensions(final int... dimensions) throws IllegalArgumentException { ArgumentChecks.ensureNonNull("dimensions", dimensions); targetDimensions = add(targetDimensions, dimensions, transform.getTargetDimensions()); }
/** * Adds input dimensions to keep in the separated transform. * The given values are <em>source</em> dimension indices of the transform given to the constructor. * * <p>Constraints:</p> * <ul> * <li>All numbers shall be in the range 0 inclusive to {@link MathTransform#getSourceDimensions()} exclusive.</li> * <li>The {@code dimensions} values shall be in strictly increasing order.</li> * <li>The {@code dimensions} values shall be greater than all values specified by all previous calls * of this method since construction or since the last call to {@link #clear()}.</li> * </ul> * * @param dimensions a sequence of source dimensions to keep, in strictly increasing order. * @throws IllegalArgumentException if {@code dimensions} contains negative values * or if values are not in a strictly increasing order. */ public void addSourceDimensions(final int... dimensions) throws IllegalArgumentException { ArgumentChecks.ensureNonNull("dimensions", dimensions); sourceDimensions = add(sourceDimensions, dimensions, transform.getSourceDimensions()); }