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 2015/11/05 11:25:37 UTC
svn commit: r1712734 - in
/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis:
internal/referencing/provider/ referencing/operation/transform/
Author: desruisseaux
Date: Thu Nov 5 10:25:37 2015
New Revision: 1712734
URL: http://svn.apache.org/viewvc?rev=1712734&view=rev
Log:
Minor simplifications:
- Molodensky.optional checks for null values instead than catching IllegalStateException.
- ContextualParameters does not cache anymore the inverse matrices. Instead we keep a
reference to ContextualParameters for the inverse operation and rely on its own caching.
Modified:
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/Molodensky.java
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ContextualParameters.java
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/EllipsoidalToCartesianTransform.java
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/MolodenskyTransform.java
Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/Molodensky.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/Molodensky.java?rev=1712734&r1=1712733&r2=1712734&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/Molodensky.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/internal/referencing/provider/Molodensky.java [UTF-8] Thu Nov 5 10:25:37 2015
@@ -36,7 +36,9 @@ import org.apache.sis.referencing.datum.
import org.apache.sis.referencing.operation.transform.MolodenskyTransform;
import org.apache.sis.internal.referencing.NilReferencingObject;
import org.apache.sis.internal.referencing.Formulas;
+import org.apache.sis.internal.system.Loggers;
import org.apache.sis.util.ArgumentChecks;
+import org.apache.sis.util.logging.Logging;
/**
@@ -238,10 +240,14 @@ public final class Molodensky extends Ge
*/
private static double optional(final Parameters values, final ParameterDescriptor<Double> parameter) {
try {
- return values.doubleValue(parameter);
- } catch (ParameterNotFoundException | IllegalStateException e) {
- return Double.NaN;
+ final Double value = values.getValue(parameter);
+ if (value != null) {
+ return value;
+ }
+ } catch (ParameterNotFoundException e) {
+ Logging.recoverableException(Logging.getLogger(Loggers.COORDINATE_OPERATION), Molodensky.class, "createMathTransform", e);
}
+ return Double.NaN;
}
/**
Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ContextualParameters.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ContextualParameters.java?rev=1712734&r1=1712733&r2=1712734&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ContextualParameters.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ContextualParameters.java [UTF-8] Thu Nov 5 10:25:37 2015
@@ -180,7 +180,7 @@ public class ContextualParameters extend
/**
* For cross-version compatibility.
*/
- private static final long serialVersionUID = 4899134192407586472L;
+ private static final long serialVersionUID = 6769546741493459341L;
/**
* The parameters that represents the sequence of transforms as a whole. The parameter values may be used
@@ -202,12 +202,6 @@ public class ContextualParameters extend
private Matrix normalize, denormalize;
/**
- * The inverse of {@link #normalize} or {@link #denormalize} matrices, computed when first needed.
- * Those matrices are cached only if {@link #isFrozen} is {@code true}.
- */
- private transient Matrix inverseNormalize, inverseDenormalize;
-
- /**
* The parameter values. Null elements in this array are empty slots available for adding new parameter values.
* The array length is the maximum number of parameters allowed, which is determined by the {@link #descriptor}.
*
@@ -217,6 +211,12 @@ public class ContextualParameters extend
private ParameterValue<?>[] values;
/**
+ * If the inverse coordinate operation can be described by another {@code ContextualParameters} instance,
+ * a reference to that instance. Otherwise {@code null}.
+ */
+ private ContextualParameters inverse;
+
+ /**
* {@code false} if this parameter group is modifiable, or {@code true} if it has been made unmodifiable
* (frozen) by a call to {@link #completeTransform(MathTransformFactory, MathTransform)}.
*
@@ -268,14 +268,15 @@ public class ContextualParameters extend
/**
* Creates a {@code ContextualParameters} for the inverse operation.
*
- * @param inverse Descriptor of the inverse operation.
+ * @param desc Descriptor of the inverse operation.
* @param forward The parameters created for the forward operation.
*/
- ContextualParameters(final ParameterDescriptorGroup inverse, final ContextualParameters forward) {
- descriptor = inverse;
+ private ContextualParameters(final ParameterDescriptorGroup desc, final ContextualParameters forward) {
+ descriptor = desc;
normalize = forward.getMatrix(MatrixRole.INVERSE_DENORMALIZATION);
denormalize = forward.getMatrix(MatrixRole.INVERSE_NORMALIZATION);
values = forward.values;
+ inverse = forward;
isFrozen = true;
}
@@ -293,6 +294,20 @@ public class ContextualParameters extend
}
/**
+ * Creates a {@code ContextualParameters} for the inverse operation.
+ *
+ * @param desc Descriptor of the inverse operation.
+ * @return Parameters for the inverse operation.
+ */
+ final synchronized ContextualParameters inverse(final ParameterDescriptorGroup desc) {
+ if (inverse == null) {
+ inverse = new ContextualParameters(desc, this);
+ }
+ assert inverse.descriptor == desc;
+ return inverse;
+ }
+
+ /**
* Returns the parameters for the <cite>normalize</cite> → <cite>non-linear kernel</cite> →
* <cite>denormalize</cite> sequence as a whole. This is the parameter descriptor of the
* {@linkplain org.apache.sis.referencing.operation.DefaultOperationMethod operation method}
@@ -315,17 +330,27 @@ public class ContextualParameters extend
}
/**
- * Ensures that this instance is modifiable.
+ * Ensures that this {@code ContextualParameters} instance is modifiable.
*
* @throws IllegalStateException if this {@code ContextualParameter} has been made unmodifiable.
*/
private void ensureModifiable() throws IllegalStateException {
+ assert Thread.holdsLock(this);
if (isFrozen) {
throw new IllegalStateException(Errors.format(Errors.Keys.UnmodifiableObject_1, getClass()));
}
}
/**
+ * Returns the given matrix as an unmodifiable one if this {@code ContextualParameters} instance is unmodifiable.
+ * Note that if this instance is modifiable, then we <strong>must</strong> return a direct reference to the matrix,
+ * not a wrapper, because the caller may need to modify it.
+ */
+ private MatrixSIS toMatrixSIS(final Matrix m) {
+ return isFrozen ? Matrices.unmodifiable(m) : (MatrixSIS) m;
+ }
+
+ /**
* Returns the affine transforms to be applied before or after the non-linear kernel operation.
* Immediately after {@linkplain #ContextualParameters(OperationMethod) construction}, those matrices
* are modifiable identity matrices. Callers can modify the matrix element values, typically by calls to
@@ -365,40 +390,32 @@ public class ContextualParameters extend
*
* @since 0.7
*/
- public final synchronized MatrixSIS getMatrix(final MatrixRole role) {
- Matrix m;
- switch (role) {
- default: throw new AssertionError(role); // If it happen, then it would be a SIS bug.
- case NORMALIZATION: m = normalize; break;
- case DENORMALIZATION: m = denormalize; break;
- case INVERSE_NORMALIZATION: m = inverseNormalize; break;
- case INVERSE_DENORMALIZATION: m = inverseDenormalize; break;
- }
- if (m != null) {
- if (!isFrozen) {
- return (MatrixSIS) m; // Must be the same instance, not a copy.
- } else {
- return Matrices.unmodifiable(m);
+ public final MatrixSIS getMatrix(MatrixRole role) {
+ final Matrix fallback;
+ final ContextualParameters inverse;
+ synchronized (this) {
+ switch (role) {
+ default: throw new AssertionError(role);
+ case NORMALIZATION: return toMatrixSIS(normalize);
+ case DENORMALIZATION: return toMatrixSIS(denormalize);
+ case INVERSE_NORMALIZATION: role = MatrixRole.DENORMALIZATION; fallback = normalize; break;
+ case INVERSE_DENORMALIZATION: role = MatrixRole.NORMALIZATION; fallback = denormalize; break;
}
+ inverse = this.inverse; // Copy the reference while we are inside the synchronized block.
}
- switch (role) {
- default: throw new AssertionError(role); // If it happen, then it would be a SIS bug.
- case INVERSE_NORMALIZATION: m = normalize; break;
- case INVERSE_DENORMALIZATION: m = denormalize; break;
- }
- final MatrixSIS inverse;
- try {
- inverse = Matrices.unmodifiable(Matrices.inverse(m));
+ /*
+ * Following must be outside the synchronized block in order to avoid potential deadlock while invoking
+ * inverse.getMatrix(role). We do not cache the matrix here, but 'inverse' is likely to have cached it.
+ */
+ final Matrix m;
+ if (inverse != null) {
+ m = inverse.getMatrix(role);
+ } else try {
+ m = Matrices.inverse(fallback);
} catch (NoninvertibleMatrixException e) {
throw new IllegalStateException(Errors.format(Errors.Keys.CanNotCompute_1, role), e);
}
- if (isFrozen) {
- switch (role) {
- case INVERSE_NORMALIZATION: inverseNormalize = inverse; break;
- case INVERSE_DENORMALIZATION: inverseDenormalize = inverse; break;
- }
- }
- return inverse;
+ return Matrices.unmodifiable(m);
}
/**
@@ -509,27 +526,10 @@ public class ContextualParameters extend
Matrix m;
if ((m = MathTransforms.getMatrix(n)) != null) normalize = m;
if ((m = MathTransforms.getMatrix(d)) != null) denormalize = m;
- inverseNormalize = unique(factory, inverseNormalize);
- inverseDenormalize = unique(factory, inverseDenormalize);
return factory.createConcatenatedTransform(factory.createConcatenatedTransform(n, kernel), d);
}
/**
- * Invoked for opportunistically replacing inverse matrices by unique instances. We rely on the fact that
- * SIS's {@link DefaultMathTransformFactory} implementation caches the {@code MathTransform} instances,
- * and that SIS implementations of {@code MathTransform.getMatrix()} return a single immutable matrix.
- */
- private static Matrix unique(final MathTransformFactory factory, Matrix matrix) throws FactoryException {
- if (matrix != null) {
- final Matrix m = MathTransforms.getMatrix(factory.createAffineTransform(matrix));
- if (m != null) {
- matrix = m;
- }
- }
- return matrix;
- }
-
- /**
* Marks this contextual parameter as unmodifiable.
*
* @see #ensureModifiable()
Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/EllipsoidalToCartesianTransform.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/EllipsoidalToCartesianTransform.java?rev=1712734&r1=1712733&r2=1712734&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/EllipsoidalToCartesianTransform.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/EllipsoidalToCartesianTransform.java [UTF-8] Thu Nov 5 10:25:37 2015
@@ -700,14 +700,6 @@ next: while (--numPts >= 0) {
private static final long serialVersionUID = 6942084702259211803L;
/**
- * The inverse of the contextual parameters given by the enclosing class, created when first needed.
- * They are used for formatting <cite>Well Known Text</cite> (WKT) and error messages.
- *
- * @see #getContextualParameters()
- */
- private transient ContextualParameters parameters;
-
- /**
* Creates the inverse of the enclosing transform.
*/
Inverse() {
@@ -718,11 +710,8 @@ next: while (--numPts >= 0) {
* but with a different method name and the (de)normalization matrices inverted.
*/
@Override
- protected synchronized ContextualParameters getContextualParameters() {
- if (parameters == null) {
- parameters = new ContextualParameters(GeocentricToGeographic.PARAMETERS, context);
- }
- return parameters;
+ protected ContextualParameters getContextualParameters() {
+ return context.inverse(GeocentricToGeographic.PARAMETERS);
}
/**
Modified: sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/MolodenskyTransform.java
URL: http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/MolodenskyTransform.java?rev=1712734&r1=1712733&r2=1712734&view=diff
==============================================================================
--- sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/MolodenskyTransform.java [UTF-8] (original)
+++ sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/MolodenskyTransform.java [UTF-8] Thu Nov 5 10:25:37 2015
@@ -127,7 +127,7 @@ public class MolodenskyTransform extends
private final byte type;
/**
- * X,Y,Z shift in units of the semi-major axis.
+ * X,Y,Z shifts in units of the semi-major axis of the source ellipsoid.
*/
private final double tX, tY, tZ;
@@ -137,7 +137,8 @@ public class MolodenskyTransform extends
private final double semiMajor;
/**
- * The square of excentricity: ℯ² = (a²-b²)/a² where
+ * The square of excentricity of the source ellipsoid.
+ * This can be computed by ℯ² = (a²-b²)/a² where
* <var>a</var> is the <cite>semi-major</cite> axis length and
* <var>b</var> is the <cite>semi-minor</cite> axis length.
*/
@@ -184,10 +185,12 @@ public class MolodenskyTransform extends
*
* <ul>
* <li><cite>Normalization</cite> before {@code MolodenskyTransform}:<ul>
- * <li>Conversion of (λ,φ) from degrees to radians</li>
+ * <li>Conversion of (λ,φ) from degrees to radians.</li>
+ * <li>Any implementation-dependent linear conversion of <var>h</var>.</li>
* </ul></li>
* <li><cite>Denormalization</cite> after {@code MolodenskyTransform}:<ul>
- * <li>Conversion of (λ,φ) from radians to degrees</li>
+ * <li>Conversion of (λ,φ) from radians to degrees.</li>
+ * <li>Any implementation-dependent linear conversion of <var>h</var>.</li>
* </ul></li>
* </ul>
*