new DefaultPiecewiseTransform1DElement( "t0", RangeFactory.create(0.0, true, 1.0, true), RangeFactory.create(0.0, true, 1.0, true), RangeFactory.create(200, 201))); Assert.assertEquals(t0.transform(0.5), 200.5, 0.0); Assert.assertTrue(t0.contains(0.5)); Assert.assertTrue(t0.contains(RangeFactory.create(0.1, 0.9))); Assert.assertFalse(t0.contains(1.5)); Assert.assertFalse(t0.contains(RangeFactory.create(0.1, 1.9))); Assert.assertTrue(t0.equals(t0)); Assert.assertEquals( t0.transform(new Position(0.5), null).getOrdinatePosition(), 200.5, 0.0); Assert.assertEquals( t0.inverse().transform(new Position(200.5), null).getOrdinatePosition(), 0.5, 0.0); DefaultPiecewiseTransform1DElement.create( "t0", RangeFactory.create(0.0, true, 1.0, true), RangeFactory.create(200, 201)); Assert.assertFalse( t0.equals( DefaultPiecewiseTransform1DElement.create( "t0", RangeFactory.create(0.0, true, 1.0, true), RangeFactory.create(200, 202)))); Assert.assertEquals(t0.transform(0.5), 200.5, 0.0); Assert.assertEquals(
DefaultPiecewiseTransform1DElement.create( "zero", RangeFactory.create(0, 100), RangeFactory.create(0, 200)); Assert.assertTrue(e0 instanceof DefaultLinearPiecewiseTransform1DElement); e0.transform(0), 0.0); Assert.assertEquals( ((DefaultLinearPiecewiseTransform1DElement) e0).getOutputMaximum(), e0.transform(e0.getInputMaximum()), 0.0); Assert.assertEquals(0.0, ((DefaultLinearPiecewiseTransform1DElement) e0).getOffset(), 0.0); Assert.assertEquals(2.0, ((DefaultLinearPiecewiseTransform1DElement) e0).getScale(), 0.0); Assert.assertFalse(e0.isIdentity()); Assert.assertEquals(1, e0.getSourceDimensions()); Assert.assertEquals(1, e0.getTargetDimensions()); Assert.assertEquals(e0.transform(Double.POSITIVE_INFINITY), 0.0, 0.0); Assert.assertTrue(false); } catch (Exception e) {
DefaultPiecewiseTransform1DElement.create( "zero", RangeFactory.create(Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY), Assert.assertEquals(0.0, e0.transform(0), 0.0); Assert.assertEquals(e0.transform(Double.POSITIVE_INFINITY), 0.0, 0.0); try { e0.inverse(); Assert.assertTrue(false); } catch (Exception e) { DefaultPiecewiseTransform1DElement.create( "zero", RangeFactory.create(Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY), Assert.assertEquals(0.0, e0.transform(0), 0.0); Assert.assertEquals(e0.transform(Double.POSITIVE_INFINITY), 0.0, 0.0); try { e0.inverse(); Assert.assertTrue(false); } catch (Exception e) { DefaultPiecewiseTransform1DElement.create( "zero", RangeFactory.create(Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY), Assert.assertEquals(0.0, e0.transform(0), 0.0); Assert.assertEquals(e0.transform(Double.POSITIVE_INFINITY), 0.0, 0.0); try {
DefaultPiecewiseTransform1DElement.create("zero", RangeFactory.create(0, 0), 0); final DefaultPiecewiseTransform1DElement mainElement = new DefaultPiecewiseTransform1DElement( "natural logarithm", RangeFactory.create(0, false, 255, true), DefaultPiecewiseTransform1DElement.create( "no-data", RangeFactory.create(-1, -1), Double.NaN); transform = DefaultPiecewiseTransform1DElement.create( "overlap", RangeFactory.create(-100, 12), Double.NaN); exceptionFound = false;
/** * Return a Piecewise transform doing clamping outside the central range * * @param minimum minimum valid value of the central range * @param maximum maximum valid value of the central range * @param minValue minValue to be returned from values outside (below) the central range * @param maxValue maxValue to be returned from values outside (above) the central range * @return */ private static PiecewiseTransform1D<DefaultPiecewiseTransform1DElement> generateClampingPiecewise( double minimum, double maximum, double minValue, double maxValue) { final DefaultPiecewiseTransform1DElement zeroElement = DefaultPiecewiseTransform1DElement.create( "clamp-to-min", RangeFactory.create(0, true, minimum, false), minValue); final DefaultPiecewiseTransform1DElement mainElement = DefaultPiecewiseTransform1DElement.create( "passthrough", RangeFactory.create(minimum, maximum)); final DefaultPiecewiseTransform1DElement maxElement = DefaultPiecewiseTransform1DElement.create( "clamp-to-max", RangeFactory.create(maximum, false, Double.POSITIVE_INFINITY, true), maxValue); return new DefaultPiecewiseTransform1D<DefaultPiecewiseTransform1DElement>( new DefaultPiecewiseTransform1DElement[] {zeroElement, mainElement, maxElement}, 0); }
public static DefaultPiecewiseTransform1DElement create(String string, Range range, MathTransformation mathTransform1D) { return new DefaultPiecewiseTransform1DElement(string, range, mathTransform1D); }
/** * Transforms the specified {@code ptSrc} and stores the result in {@code ptDst}. */ public Position transform(final Position ptSrc, Position ptDst) throws TransformationException { if (ptDst == null) { ptDst = new Position(); } ptDst.setOrdinatePosition(transform(ptSrc.getOrdinatePosition())); return ptDst; }
/** * Transforms the specified value. * * @param value The value to transform. * @return the transformed value. * @throws TransformationException if the value can't be transformed. */ public synchronized double transform(double value) throws TransformationException { if (transform == null) throw new IllegalStateException(); if (contains(value)) return transform.transform(value); throw new IllegalArgumentException("Provided value is not contained in this domain"); }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (!(obj instanceof DefaultLinearPiecewiseTransform1DElement)) return false; final DefaultLinearPiecewiseTransform1DElement that = (DefaultLinearPiecewiseTransform1DElement) obj; if (that.getEquivalenceClass() != this.getEquivalenceClass()) return false; if (!outputRange.equals(that.outputRange)) return false; if (!PiecewiseUtilities.equals(outputMaximum, that.outputMaximum)) return false; if (!PiecewiseUtilities.equals(outputMinimum, that.outputMinimum)) return false; return super.equals(obj); }
DefaultPiecewiseTransform1DElement e0 = DefaultPiecewiseTransform1DElement.create("zero", RangeFactory.create(Double.NEGATIVE_INFINITY, true, Double.POSITIVE_INFINITY, true, true), ((byte) 0)); Assert.assertTrue(e0 instanceof DefaultConstantPiecewiseTransformElement); Assert.assertEquals(0.0, e0.transform(0), 0.0); Assert.assertEquals(e0.transform(Double.POSITIVE_INFINITY), 0.0, 0.0); try { e0.inverse(); Assert.assertTrue(false); } catch (Exception e) { e0 = DefaultPiecewiseTransform1DElement.create("zero", RangeFactory.create( Double.NEGATIVE_INFINITY, true, Double.POSITIVE_INFINITY, true, true), 0); Assert.assertTrue(e0 instanceof DefaultConstantPiecewiseTransformElement); Assert.assertEquals(0.0, e0.transform(0), 0.0); Assert.assertEquals(e0.transform(Double.POSITIVE_INFINITY), 0.0, 0.0); e0 = DefaultPiecewiseTransform1DElement.create("zero", RangeFactory.create( Double.NEGATIVE_INFINITY, true, Double.POSITIVE_INFINITY, true, true), 0.0); Assert.assertTrue(e0 instanceof DefaultConstantPiecewiseTransformElement); Assert.assertEquals(0.0, e0.transform(0), 0.0); Assert.assertEquals(e0.transform(Double.POSITIVE_INFINITY), 0.0, 0.0); boolean exceptionThrown = false; try { e0.inverse(); Assert.assertTrue(false);
final DefaultPiecewiseTransform1DElement zero = DefaultPiecewiseTransform1DElement.create( "zero", RangeFactory.create(0, true, 0, true), 0); final DefaultPiecewiseTransform1DElement mainElement = new DefaultPiecewiseTransform1DElement( "natural logarithm", RangeFactory.create(0, false, 255, true), new MathTransformation() { .create("no-data", RangeFactory.create(-1, true, -1, true), Double.NaN); transform = new DefaultPiecewiseTransform1D<DefaultPiecewiseTransform1DElement>( new DefaultPiecewiseTransform1DElement[] { zero, mainElement, nodata }); .create("overlap", RangeFactory.create(-100, true, 12, true), Double.NaN); try { transform = new DefaultPiecewiseTransform1D<DefaultPiecewiseTransform1DElement>(
DefaultPiecewiseTransform1DElement.create( "exponential-contrast-enhancement-transform", RangeFactory.create(minimum, maximum),
public static DefaultPiecewiseTransform1DElement create(String string, Range range, MathTransformation mathTransform1D) { return new DefaultPiecewiseTransform1DElement(string, range, mathTransform1D); }
/** * Transforms the specified {@code ptSrc} and stores the result in {@code ptDst}. */ public Position transform(final Position ptSrc, Position ptDst) throws TransformationException { if (ptDst == null) { ptDst = new Position(); } ptDst.setOrdinatePosition(transform(ptSrc.getOrdinatePosition())); return ptDst; }
/** * Transforms the specified value. * * @param value The value to transform. * @return the transformed value. * @throws TransformationException if the value can't be transformed. */ public synchronized double transform(double value) throws TransformationException { if (transform == null) throw new IllegalStateException(); if (contains(value)) return transform.transform(value); throw new IllegalArgumentException("Provided value is not contained in this domain"); }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (!(obj instanceof DefaultLinearPiecewiseTransform1DElement)) return false; final DefaultLinearPiecewiseTransform1DElement that = (DefaultLinearPiecewiseTransform1DElement) obj; if (that.getEquivalenceClass() != this.getEquivalenceClass()) return false; if (!outputRange.equals(that.outputRange)) return false; if (!PiecewiseUtilities.equals(outputMaximum, that.outputMaximum)) return false; if (!PiecewiseUtilities.equals(outputMinimum, that.outputMinimum)) return false; return super.equals(obj); }
DefaultPiecewiseTransform1DElement t0 = new DefaultPiecewiseTransform1DElement("t0", RangeFactory.create(0.0, true, 1.0, true, false), PiecewiseUtilities.createLinearTransform1D( RangeFactory.create(0.0, true, 1.0, true, false), RangeFactory.create(200, true, 201, true))); Assert.assertEquals(t0.transform(0.5), 200.5, 0.0); Assert.assertTrue(t0.contains(0.5)); Assert.assertTrue(t0.contains(RangeFactory.create(0.1, true, 0.9, true, false))); Assert.assertFalse(t0.contains(1.5)); Assert.assertFalse(t0.contains(RangeFactory.create(0.1, true, 1.9, true, false))); Assert.assertTrue(t0.equals(t0)); Assert.assertEquals(t0.inverse().transform(200.5), 0.5, 0.0); t0 = DefaultPiecewiseTransform1DElement.create("t0", RangeFactory.create(0.0, true, 1.0, true, false), RangeFactory.create(200, true, 201, true)); Assert.assertFalse(t0.equals(DefaultPiecewiseTransform1DElement.create("t0", RangeFactory.create(0.0, true, 1.0, true, false), RangeFactory.create(200, true, 202, true)))); Assert.assertEquals(t0.transform(0.5), 200.5, 0.0); Assert.assertEquals(t0.inverse().transform(200.5), 0.5, 0.0); DefaultPiecewiseTransform1DElement t1 = DefaultPiecewiseTransform1DElement.create("t1", RangeFactory.create(1.0, false, 2.0, true, false), 201); Assert.assertEquals(t1.transform(1.5), 201, 0.0); Assert.assertEquals(t1.transform(1.6), 201, 0.0); Assert.assertFalse(t0.equals(t1)); Assert.assertEquals(t1.transform(1.8), 201, 0.0);
DefaultPiecewiseTransform1DElement e0 = DefaultPiecewiseTransform1DElement.create("zero", RangeFactory.create(0, true, 100, true), RangeFactory.create(0, true, 200, true)); Assert.assertTrue(e0 instanceof DefaultLinearPiecewiseTransform1DElement); e0.transform(0), 0.0); Assert.assertEquals(((DefaultLinearPiecewiseTransform1DElement) e0).getOutputMaximum(), e0.transform(e0.getInputMaximum()), 0.0); Assert.assertEquals(0.0, ((DefaultLinearPiecewiseTransform1DElement) e0).getOffset(), 0.0); Assert.assertEquals(2.0, ((DefaultLinearPiecewiseTransform1DElement) e0).getScale(), 0.0); Assert.assertFalse(e0.isIdentity()); Assert.assertEquals(1, e0.getSourceDimensions()); Assert.assertEquals(1, e0.getTargetDimensions()); Assert.assertEquals(e0.transform(Double.POSITIVE_INFINITY), 0.0, 0.0); } catch (Exception e) { exceptionThrown = true;
DefaultPiecewiseTransform1DElement.create( "logarithmic-contrast-enhancement-transform", RangeFactory.create(minimum, maximum),
new DefaultPiecewiseTransform1DElement( "natural logarithm", RangeFactory.create(minimum[0], maximum[0]),