You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sis.apache.org by de...@apache.org on 2016/04/02 01:15:53 UTC
svn commit: r1737452 - in /sis/branches/JDK8/core/sis-referencing/src:
main/java/org/apache/sis/internal/referencing/provider/
main/java/org/apache/sis/referencing/operation/transform/
main/resources/META-INF/services/ test/java/org/apache/sis/referenc...
Author: desruisseaux
Date: Fri Apr 1 23:15:53 2016
New Revision: 1737452
URL: http://svn.apache.org/viewvc?rev=1737452&view=rev
Log:
In LinearInterpolator1D, rename "x" and "y" as "preimage" and "values" respectively.
"preimage" seems to be the appropriate mathematical term for what this array is.
Add a provider for that coordinate operation.
Added:
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/Interpolation1D.java (with props)
Modified:
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/LinearInterpolator1D.java
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/MathTransforms.java
sis/branches/JDK8/core/sis-referencing/src/main/resources/META-INF/services/org.opengis.referencing.operation.OperationMethod
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/LinearInterpolator1DTest.java
Added: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/Interpolation1D.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/Interpolation1D.java?rev=1737452&view=auto
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/Interpolation1D.java (added)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/Interpolation1D.java [UTF-8] Fri Apr 1 23:15:53 2016
@@ -0,0 +1,104 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sis.internal.referencing.provider;
+
+import org.opengis.parameter.ParameterValueGroup;
+import org.opengis.parameter.ParameterDescriptor;
+import org.opengis.parameter.ParameterDescriptorGroup;
+import org.opengis.parameter.ParameterNotFoundException;
+import org.opengis.referencing.operation.Conversion;
+import org.opengis.referencing.operation.MathTransform;
+import org.opengis.referencing.operation.MathTransformFactory;
+import org.apache.sis.referencing.operation.transform.MathTransforms;
+import org.apache.sis.metadata.iso.citation.Citations;
+import org.apache.sis.internal.util.Constants;
+import org.apache.sis.parameter.Parameters;
+import org.apache.sis.parameter.ParameterBuilder;
+
+
+/**
+ * The provider for interpolation of one-dimensional coordinates.
+ *
+ * @author Martin Desruisseaux (Geomatys)
+ * @since 0.7
+ * @version 0.7
+ * @module
+ */
+public final class Interpolation1D extends AbstractProvider {
+ /**
+ * Serial number for inter-operability with different versions.
+ */
+ private static final long serialVersionUID = -2571645687075958970L;
+
+ /**
+ * The operation parameter descriptor for the <cite>"preimage"</cite> parameter value.
+ * This parameter is optional and often omitted.
+ *
+ * @see <a href="https://en.wikipedia.org/wiki/Image_%28mathematics%29#Inverse_image">Preimage on Wikipedia</a>
+ * @see <a href="http://mathworld.wolfram.com/Preimage.html">Preimage on MathWord</a>
+ */
+ private static final ParameterDescriptor<double[]> PREIMAGE;
+
+ /**
+ * The operation parameter descriptor for the <cite>"values"</cite> parameter value.
+ */
+ private static final ParameterDescriptor<double[]> VALUES;
+
+ /**
+ * The group of all parameters expected by this coordinate operation.
+ */
+ public static final ParameterDescriptorGroup PARAMETERS;
+ static {
+ final ParameterBuilder builder = new ParameterBuilder().setCodeSpace(Citations.SIS, Constants.SIS);
+ PREIMAGE = builder.addName("preimage").create(double[].class, null); // Optional and often omitted.
+ VALUES = builder.addName("values") .create(double[].class, null); // Optional but usually provided.
+ PARAMETERS = builder.addName("Interpolation 1D").createGroup(PREIMAGE, VALUES);
+ }
+
+ /**
+ * Constructs a provider for the 1-dimensional case.
+ */
+ public Interpolation1D() {
+ super(1, 1, PARAMETERS);
+ }
+
+ /**
+ * Returns the operation type.
+ *
+ * @return {@code Conversion.class}.
+ */
+ @Override
+ public Class<Conversion> getOperationType() {
+ return Conversion.class;
+ }
+
+ /**
+ * Creates a transform from the specified group of parameter values.
+ *
+ * @param factory Ignored (can be null).
+ * @param values The group of parameter values.
+ * @return The created math transform.
+ * @throws ParameterNotFoundException if a required parameter was not found.
+ */
+ @Override
+ public MathTransform createMathTransform(MathTransformFactory factory, ParameterValueGroup values)
+ throws ParameterNotFoundException
+ {
+ final Parameters pv = Parameters.castOrWrap(values);
+ return MathTransforms.interpolate(pv.getValue(PREIMAGE), pv.getValue(VALUES));
+ }
+}
Propchange: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/Interpolation1D.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/Interpolation1D.java
------------------------------------------------------------------------------
svn:mime-type = text/plain;charset=UTF-8
Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/LinearInterpolator1D.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/LinearInterpolator1D.java?rev=1737452&r1=1737451&r2=1737452&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/LinearInterpolator1D.java (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/LinearInterpolator1D.java Fri Apr 1 23:15:53 2016
@@ -18,8 +18,11 @@ package org.apache.sis.referencing.opera
import java.util.Arrays;
import java.io.Serializable;
+import org.opengis.parameter.ParameterValueGroup;
+import org.opengis.parameter.ParameterDescriptorGroup;
import org.opengis.referencing.operation.MathTransform1D;
import org.opengis.referencing.operation.NoninvertibleTransformException;
+import org.apache.sis.internal.referencing.provider.Interpolation1D;
import org.apache.sis.internal.util.Numerics;
import org.apache.sis.util.ComparisonMode;
import org.apache.sis.util.resources.Errors;
@@ -124,50 +127,68 @@ final class LinearInterpolator1D extends
}
/**
- * Creates a <i>y=f(x)</i> transform for the given <var>x</var> and <var>y</var> values.
+ * Creates a <i>y=f(x)</i> transform for the given preimage (<var>x</var>) and values (<var>y</var>).
* See {@link MathTransforms#interpolate(double[], double[])} javadoc for more information.
*/
- static MathTransform1D create(final double[] x, final double[] y) {
+ static MathTransform1D create(final double[] preimage, final double[] values) {
final int length;
- if (x == null) {
- if (y == null) {
+ if (preimage == null) {
+ if (values == null) {
return IdentityTransform1D.INSTANCE;
}
- length = y.length;
+ length = values.length;
} else {
- length = x.length;
- if (y != null && y.length != length) {
+ length = preimage.length;
+ if (values != null && values.length != length) {
throw new IllegalArgumentException(Errors.format(Errors.Keys.MismatchedArrayLengths));
}
}
switch (length) {
- case 0: throw new IllegalArgumentException(Errors.format(Errors.Keys.EmptyArgument_1, (x != null) ? "x" : "y"));
- case 1: return LinearTransform1D.constant((x != null) ? x[0] : Double.NaN, (y != null) ? y[0] : Double.NaN);
+ case 0: throw new IllegalArgumentException(Errors.format(Errors.Keys.EmptyArgument_1, (preimage != null) ? "preimage" : "values"));
+ case 1: return LinearTransform1D.constant((preimage != null) ? preimage[0] : Double.NaN, (values != null) ? values[0] : Double.NaN);
}
/*
* A common usage of this 'create' method is for creating a "gridToCRS" transform from grid coordinates
- * to something else, in which case the 'x' array is null. In the less frequent case where x is non-null,
- * we first convert from x values to indices, then from indices to y values.
+ * to something else, in which case the preimage array is null. In the less frequent case where preimage
+ * is non-null, we first convert from preimage to indices, then from indices to y values.
*/
MathTransform1D tr = null;
- if (y != null) {
- tr = create(y.clone());
+ if (values != null) {
+ tr = create(values.clone());
}
- if (x != null) {
- final MathTransform1D indexToY = tr;
+ if (preimage != null) {
+ final MathTransform1D indexToValues = tr;
try {
- tr = create(x.clone()).inverse(); // xToIndex transform.
+ tr = create(preimage.clone()).inverse(); // preimageToIndex transform.
} catch (NoninvertibleTransformException e) {
- throw new IllegalArgumentException(Errors.format(Errors.Keys.NonMonotonicSequence_1, "x"), e);
+ throw new IllegalArgumentException(Errors.format(Errors.Keys.NonMonotonicSequence_1, "preimage"), e);
}
- if (indexToY != null) {
- tr = MathTransforms.concatenate(tr, indexToY);
+ if (indexToValues != null) {
+ tr = MathTransforms.concatenate(tr, indexToValues);
}
}
return tr;
}
/**
+ * Returns the parameter descriptors for this math transform.
+ */
+ @Override
+ public ParameterDescriptorGroup getParameterDescriptors() {
+ return Interpolation1D.PARAMETERS;
+ }
+
+ /**
+ * Returns the parameter values for this math transform.
+ */
+ @Override
+ public ParameterValueGroup getParameterValues() {
+ final ParameterValueGroup p = getParameterDescriptors().createValue();
+ p.parameter("values").setValue(values);
+ return p;
+ }
+
+ /**
* Returns {@code true} if this transform is the identity transform. This method should never returns {@code true}
* since we verified the inputs in the {@code create(â¦)} method. We nevertheless verify as a paranoiac safety.
*/
Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/MathTransforms.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/MathTransforms.java?rev=1737452&r1=1737451&r2=1737452&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/MathTransforms.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/MathTransforms.java [UTF-8] Fri Apr 1 23:15:53 2016
@@ -148,29 +148,29 @@ public final class MathTransforms extend
/**
* Creates a transform for the <i>y=f(x)</i> function where <var>y</var> are computed by a linear interpolation.
- * Both {@code x} and {@code y} arguments can be null:
+ * Both {@code preimage} (the <var>x</var>) and {@code values} (the <var>y</var>) arguments can be null:
*
* <ul>
- * <li>If both {@code x} and {@code y} arrays are non-null, then the must have the same length.</li>
- * <li>If both {@code x} and {@code y} arrays are null, then this method returns the identity transform.</li>
- * <li>If only {@code x} is null, then the <var>x</var> values are taken as {0, 1, 2, …, {@code y.length} - 1}.</li>
- * <li>If only {@code y} is null, then the <var>y</var> values are taken as {0, 1, 2, …, {@code x.length} - 1}.</li>
+ * <li>If both {@code preimage} and {@code values} arrays are non-null, then the must have the same length.</li>
+ * <li>If both {@code preimage} and {@code values} arrays are null, then this method returns the identity transform.</li>
+ * <li>If only {@code preimage} is null, then the <var>x</var> values are taken as {0, 1, 2, …, {@code values.length} - 1}.</li>
+ * <li>If only {@code values} is null, then the <var>y</var> values are taken as {0, 1, 2, …, {@code preimage.length} - 1}.</li>
* </ul>
*
- * All <var>x</var> values shall be real numbers (not NaN) sorted in increasing or decreasing order.
- * Elements in the {@code y} array do not need to be ordered, but the returned transform will be invertible
- * only if all <var>y</var> values are real numbers sorted in increasing or decreasing order.
+ * All {@code preimage} elements shall be real numbers (not NaN) sorted in increasing or decreasing order.
+ * Elements in the {@code values} array do not need to be ordered, but the returned transform will be invertible
+ * only if all values are real numbers sorted in increasing or decreasing order.
* Furthermore the returned transform is affine (i.e. implement the {@link LinearTransform} interface)
- * if the interval between each <var>x</var> and <var>y</var> value is constant.
+ * if the interval between each {@code preimage} and {@code values} element is constant.
*
- * @param x the input values in the function domain, or {@code null}.
- * @param y the output values in the function range, or {@code null}.
+ * @param preimage the input values (<var>x</var>) in the function domain, or {@code null}.
+ * @param values the output values (<var>y</var>) in the function range, or {@code null}.
* @return the <i>y=f(x)</i> function.
*
* @since 0.7
*/
- public static MathTransform1D interpolate(final double[] x, final double[] y) {
- return LinearInterpolator1D.create(x, y);
+ public static MathTransform1D interpolate(final double[] preimage, final double[] values) {
+ return LinearInterpolator1D.create(preimage, values);
}
/**
Modified: sis/branches/JDK8/core/sis-referencing/src/main/resources/META-INF/services/org.opengis.referencing.operation.OperationMethod
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/resources/META-INF/services/org.opengis.referencing.operation.OperationMethod?rev=1737452&r1=1737451&r2=1737452&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/resources/META-INF/services/org.opengis.referencing.operation.OperationMethod [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/resources/META-INF/services/org.opengis.referencing.operation.OperationMethod [UTF-8] Fri Apr 1 23:15:53 2016
@@ -42,3 +42,4 @@ org.apache.sis.internal.referencing.prov
org.apache.sis.internal.referencing.provider.NTv2
org.apache.sis.internal.referencing.provider.NADCON
org.apache.sis.internal.referencing.provider.FranceGeocentricInterpolation
+org.apache.sis.internal.referencing.provider.Interpolation1D
Modified: sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/LinearInterpolator1DTest.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/LinearInterpolator1DTest.java?rev=1737452&r1=1737451&r2=1737452&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/LinearInterpolator1DTest.java (original)
+++ sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/LinearInterpolator1DTest.java Fri Apr 1 23:15:53 2016
@@ -39,7 +39,7 @@ public final strictfp class LinearInterp
/**
* The values of the <i>y=f(x)</i> function to test.
*/
- private double[] x, y;
+ private double[] preimage, values;
/**
* Creates a new test case.
@@ -54,8 +54,8 @@ public final strictfp class LinearInterp
*/
@Test
public void testIndicesToIncreasingValues() throws TransformException {
- x = new double[] { 0, 1, 2, 3};
- y = new double[] {10, 12, 16, 22};
+ preimage = new double[] { 0, 1, 2, 3};
+ values = new double[] {10, 12, 16, 22};
verifyConsistency(-2, 5, -5196528645359952958L);
assertInstanceOf("Expected y=f(i)", LinearInterpolator1D.class, transform);
}
@@ -67,8 +67,8 @@ public final strictfp class LinearInterp
*/
@Test
public void testIndicesToDecreasingValues() throws TransformException {
- x = new double[] {0, 1, 2, 3};
- y = new double[] {35, 27, 22, 5};
+ preimage = new double[] {0, 1, 2, 3};
+ values = new double[] {35, 27, 22, 5};
verifyConsistency(-2, 5, 6445394511592290678L);
assertInstanceOf("Expected y = -f(-i)", ConcatenatedTransformDirect1D.class, transform);
assertInstanceOf("Expected y = -f(-i)", LinearInterpolator1D.class, ((ConcatenatedTransform) transform).transform1);
@@ -82,8 +82,8 @@ public final strictfp class LinearInterp
*/
@Test
public void testIncreasingInputsToIndices() throws TransformException {
- x = new double[] {10, 12, 16, 22};
- y = new double[] { 0, 1, 2, 3};
+ preimage = new double[] {10, 12, 16, 22};
+ values = new double[] { 0, 1, 2, 3};
verifyConsistency(0, 30, 6130776597146077588L);
}
@@ -94,8 +94,8 @@ public final strictfp class LinearInterp
*/
@Test
public void testDecreasingInputsToIndices() throws TransformException {
- x = new double[] {35, 27, 22, 5};
- y = new double[] {0, 1, 2, 3};
+ preimage = new double[] {35, 27, 22, 5};
+ values = new double[] {0, 1, 2, 3};
verifyConsistency(0, 40, 4109281798631024654L);
assertInstanceOf("Expected i = -f(-x)", ConcatenatedTransformDirect1D.class, transform);
}
@@ -107,8 +107,8 @@ public final strictfp class LinearInterp
*/
@Test
public void testIncreasingInputsToIncreasingValues() throws TransformException {
- x = new double[] { -207, -96, -5, 2};
- y = new double[] { -50, -20, 7, 105};
+ preimage = new double[] { -207, -96, -5, 2};
+ values = new double[] { -50, -20, 7, 105};
verifyConsistency(-210, 5, 1941178068603334535L);
assertInstanceOf("Expected y = f(x)", ConcatenatedTransformDirect1D.class, transform);
assertInstanceOf("Expected y = f(x)", LinearInterpolator1D.class, ((ConcatenatedTransform) transform).transform2);
@@ -121,8 +121,8 @@ public final strictfp class LinearInterp
*/
@Test
public void testDecreasingInputsToIncreasingValues() throws TransformException {
- x = new double[] { 2, -5, -96, -207};
- y = new double[] {-50, -20, 7, 105};
+ preimage = new double[] { 2, -5, -96, -207};
+ values = new double[] {-50, -20, 7, 105};
verifyConsistency(-210, 5, 7360962930883142147L);
assertInstanceOf("Expected y = -f(-x)", ConcatenatedTransformDirect1D.class, transform);
}
@@ -134,8 +134,8 @@ public final strictfp class LinearInterp
*/
@Test
public void testDecreasingInputsToDecreasingValues() throws TransformException {
- x = new double[] { 2, -5, -96, -207};
- y = new double[] {105, 7, -19, -43};
+ preimage = new double[] { 2, -5, -96, -207};
+ values = new double[] {105, 7, -19, -43};
verifyConsistency(-210, 5, -2463171263749789198L);
assertInstanceOf("Expected y = -f(-x)", ConcatenatedTransformDirect1D.class, transform);
}
@@ -147,8 +147,8 @@ public final strictfp class LinearInterp
*/
@Test
public void testIncreasingInputsToNonMonotonic() throws TransformException {
- x = new double[] {-52, -27, -13, 2};
- y = new double[] {105, -19, 7, -43};
+ preimage = new double[] {-52, -27, -13, 2};
+ values = new double[] {105, -19, 7, -43};
isInverseTransformSupported = false;
verifyConsistency(-60, 5, 7750310847358135291L);
}
@@ -160,8 +160,8 @@ public final strictfp class LinearInterp
*/
@Test
public void testDecreasingInputsToNonMonotonic() throws TransformException {
- x = new double[] {1017, 525, 24, 12};
- y = new double[] { -43, 7, -19, 105};
+ preimage = new double[] {1017, 525, 24, 12};
+ values = new double[] { -43, 7, -19, 105};
isInverseTransformSupported = false;
verifyConsistency(0, 1020, 2060810396521686858L);
}
@@ -173,8 +173,8 @@ public final strictfp class LinearInterp
*/
@Test
public void testIncreasingInputsToPercent() throws TransformException {
- x = new double[] { 5, 6.5, 8, 10, 25, 28, 30, 32};
- y = new double[] {100, 66, 33, 0, 0, 33, 66, 100};
+ preimage = new double[] { 5, 6.5, 8, 10, 25, 28, 30, 32};
+ values = new double[] {100, 66, 33, 0, 0, 33, 66, 100};
isInverseTransformSupported = false;
verifyConsistency(0, 40, -6588291548545974041L);
}
@@ -184,19 +184,19 @@ public final strictfp class LinearInterp
*/
@Test
public void testArgumentChecks() {
- x = new double[] { -43, 7, -19, 105}; // Non-monotonic sequence.
- y = new double[] {1017, 525, 24, 12};
+ preimage = new double[] { -43, 7, -19, 105}; // Non-monotonic sequence.
+ values = new double[] {1017, 525, 24, 12};
try {
- LinearInterpolator1D.create(x, y);
+ LinearInterpolator1D.create(preimage, values);
fail("Should not have accepted the x inputs.");
} catch (IllegalArgumentException e) {
final String message = e.getMessage();
- assertTrue(message, message.contains("x"));
+ assertTrue(message, message.contains("preimage"));
}
- x = new double[] {1017, 525, 24, 12};
- y = new double[] {-43, 7, -19, 105};
- MathTransform1D mt = LinearInterpolator1D.create(x, y);
+ preimage = new double[] {1017, 525, 24, 12};
+ values = new double[] {-43, 7, -19, 105};
+ MathTransform1D mt = LinearInterpolator1D.create(preimage, values);
try {
mt.inverse();
fail("Should not have accepted the inverse that transform.");
@@ -205,10 +205,10 @@ public final strictfp class LinearInterp
assertFalse(message, message.isEmpty());
}
- x = new double[] {1017, 525, 24, 12, 45}; // Mismatched array length.
- y = new double[] {-43, 7, -19, 105};
+ preimage = new double[] {1017, 525, 24, 12, 45}; // Mismatched array length.
+ values = new double[] {-43, 7, -19, 105};
try {
- LinearInterpolator1D.create(x, y);
+ LinearInterpolator1D.create(preimage, values);
fail("Should not have accepted the x inputs.");
} catch (IllegalArgumentException e) {
final String message = e.getMessage();
@@ -220,7 +220,7 @@ public final strictfp class LinearInterp
* Transforms point and verifies that the result is consistent with the inverse transform and the derivative.
*/
private void verifyConsistency(final double min, final double max, final long randomSeed) throws TransformException {
- transform = LinearInterpolator1D.create(x, y);
+ transform = LinearInterpolator1D.create(preimage, values);
tolerance = 1E-10;
derivativeDeltas = new double[] {0.1};
/*