Author: desruisseaux
Date: Thu Mar 19 23:32:35 2015
New Revision: 1667899
URL: http://svn.apache.org/r1667899
Log:
Matrix update before to port first map projections:
- Moved normalizeColumns() in the super-class for saving place (maybe at a
slight performance cost) since this method is rarely used.
- Moved equals() and hashCode() in the super-class for saving place in Matrix3
and Matrix4, since we rarely put matrices in a HashMap.
- Initial version of a 'concatenateAffine' method, to be needed by map
projection constructors.
Modified:
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/GeneralMatrix.java
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix3.java
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix4.java
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/MatrixSIS.java
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/package-info.java
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/NonLinearParameters.java
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/DoubleDouble.java
Modified:
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/GeneralMatrix.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/GeneralMatrix.java?rev=1667899&r1=1667898&r2=1667899&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/GeneralMatrix.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/GeneralMatrix.java
[UTF-8] Thu Mar 19 23:32:35 2015
@@ -239,6 +239,38 @@ class GeneralMatrix extends MatrixSIS im
}
/**
+ * Stores the value at the specified row and column in the given {@code
dd} object.
+ * This method does not need to verify argument validity.
+ */
+ @Override
+ final void get(final int row, final int column, final DoubleDouble dd) {
+ int i = row * numCol + column;
+ dd.value = elements[i];
+ i += numRow * numCol;
+ if (i < elements.length) {
+ dd.error = elements[i];
+ assert dd.equals(getNumber(row, column));
+ } else {
+ dd.error = DoubleDouble.errorForWellKnownValue(dd.value);
+ }
+ }
+
+ /**
+ * Stores the value of the given {@code dd} object at the specified row
and column.
+ * This method does not need to verify argument validity.
+ */
+ @Override
+ final void set(final int row, final int column, final DoubleDouble dd) {
+ int i = row * numCol + column;
+ elements[i] = dd.value;
+ i += numRow * numCol;
+ if (i < elements.length) {
+ elements[i] = dd.error;
+ assert dd.equals(getNumber(row, column));
+ }
+ }
+
+ /**
* Retrieves the value at the specified row and column of this matrix,
wrapped in a {@code Number}
* or a {@link DoubleDouble} depending on available precision.
*
@@ -523,37 +555,6 @@ class GeneralMatrix extends MatrixSIS im
}
}
- /**
- * {@inheritDoc}
- */
- @Override
- public final void normalizeColumns() {
- final int numRow = this.numRow; // Protection against accidental
changes.
- final int numCol = this.numCol;
- final int errors = numRow * numCol; // Where error values start.
- final double[] elt = getExtendedElements(this, numRow, numCol, false);
- final DoubleDouble sum = new DoubleDouble();
- final DoubleDouble dot = new DoubleDouble();
- for (int i=0; i<numCol; i++) {
- sum.clear();
- for (int j=0; j<numRow; j++) {
- dot.setFrom(elt, j*numCol + i, errors);
- dot.multiply(dot);
- sum.add(dot);
- }
- sum.sqrt();
- for (int j=0; j<numRow; j++) {
- final int k = j*numCol + i;
- dot.setFrom(sum);
- dot.inverseDivide(elt, k, errors);
- dot.storeTo(elt, k, errors);
- }
- }
- if (elt != elements) {
- System.arraycopy(elt, 0, elements, 0, elements.length);
- }
- }
-
/**
* Sets this matrix to the product of the given matrices: {@code this = A
× B}.
* The matrix sizes much match - this is not verified unless assertions
are enabled.
Modified:
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix3.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix3.java?rev=1667899&r1=1667898&r2=1667899&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix3.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix3.java
[UTF-8] Thu Mar 19 23:32:35 2015
@@ -16,10 +16,7 @@
*/
package org.apache.sis.referencing.operation.matrix;
-import java.util.Arrays;
import org.opengis.referencing.operation.Matrix;
-import org.apache.sis.internal.util.Numerics;
-import org.apache.sis.math.MathFunctions;
/**
@@ -34,7 +31,7 @@ import org.apache.sis.math.MathFunctions
*
* @author Martin Desruisseaux (IRD, Geomatys)
* @since 0.4
- * @version 0.4
+ * @version 0.6
* @module
*
* @see Matrix1
@@ -293,48 +290,4 @@ public final class Matrix3 extends Matri
swap = m02; m02 = m20; m20 = swap;
swap = m12; m12 = m21; m21 = swap;
}
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void normalizeColumns() {
- double m;
- final double[] v = new double[3];
- v[0]=m00; v[1]=m10; v[2]=m20; m = MathFunctions.magnitude(v); m00 /=
m; m10 /= m; m20 /= m;
- v[0]=m01; v[1]=m11; v[2]=m21; m = MathFunctions.magnitude(v); m01 /=
m; m11 /= m; m21 /= m;
- v[0]=m02; v[1]=m12; v[2]=m22; m = MathFunctions.magnitude(v); m02 /=
m; m12 /= m; m22 /= m;
- }
-
- /**
- * Returns {@code true} if the specified object is of type {@code Matrix3}
and
- * all of the data members are equal to the corresponding data members in
this matrix.
- *
- * @param object The object to compare with this matrix for equality.
- * @return {@code true} if the given object is equal to this matrix.
- */
- @Override
- public boolean equals(final Object object) {
- if (object instanceof Matrix3) {
- final Matrix3 that = (Matrix3) object;
- return Numerics.equals(this.m00, that.m00) &&
- Numerics.equals(this.m01, that.m01) &&
- Numerics.equals(this.m02, that.m02) &&
- Numerics.equals(this.m10, that.m10) &&
- Numerics.equals(this.m11, that.m11) &&
- Numerics.equals(this.m12, that.m12) &&
- Numerics.equals(this.m20, that.m20) &&
- Numerics.equals(this.m21, that.m21) &&
- Numerics.equals(this.m22, that.m22);
- }
- return false;
- }
-
- /**
- * Returns a hash code value based on the data values in this object.
- */
- @Override
- public int hashCode() {
- return Arrays.hashCode(getElements()) ^ (int) serialVersionUID;
- }
}
Modified:
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix4.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix4.java?rev=1667899&r1=1667898&r2=1667899&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix4.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/Matrix4.java
[UTF-8] Thu Mar 19 23:32:35 2015
@@ -16,10 +16,7 @@
*/
package org.apache.sis.referencing.operation.matrix;
-import java.util.Arrays;
import org.opengis.referencing.operation.Matrix;
-import org.apache.sis.internal.util.Numerics;
-import org.apache.sis.math.MathFunctions;
/**
@@ -35,7 +32,7 @@ import org.apache.sis.math.MathFunctions
*
* @author Martin Desruisseaux (IRD, Geomatys)
* @since 0.4
- * @version 0.4
+ * @version 0.6
* @module
*
* @see Matrix1
@@ -331,56 +328,4 @@ public final class Matrix4 extends Matri
swap = m13; m13 = m31; m31 = swap;
swap = m23; m23 = m32; m32 = swap;
}
-
- /**
- * {@inheritDoc}
- */
- @Override
- public void normalizeColumns() {
- double m;
- final double[] v = new double[4];
- v[0]=m00; v[1]=m10; v[2]=m20; v[3]=m30; m =
MathFunctions.magnitude(v); m00 /= m; m10 /= m; m20 /= m; m30 /= m;
- v[0]=m01; v[1]=m11; v[2]=m21; v[3]=m31; m =
MathFunctions.magnitude(v); m01 /= m; m11 /= m; m21 /= m; m31 /= m;
- v[0]=m02; v[1]=m12; v[2]=m22; v[3]=m32; m =
MathFunctions.magnitude(v); m02 /= m; m12 /= m; m22 /= m; m32 /= m;
- v[0]=m03; v[1]=m13; v[2]=m23; v[3]=m33; m =
MathFunctions.magnitude(v); m03 /= m; m13 /= m; m23 /= m; m33 /= m;
- }
-
- /**
- * Returns {@code true} if the specified object is of type {@code Matrix4}
and
- * all of the data members are equal to the corresponding data members in
this matrix.
- *
- * @param object The object to compare with this matrix for equality.
- * @return {@code true} if the given object is equal to this matrix.
- */
- @Override
- public boolean equals(final Object object) {
- if (object instanceof Matrix4) {
- final Matrix4 that = (Matrix4) object;
- return Numerics.equals(this.m00, that.m00) &&
- Numerics.equals(this.m01, that.m01) &&
- Numerics.equals(this.m02, that.m02) &&
- Numerics.equals(this.m03, that.m03) &&
- Numerics.equals(this.m10, that.m10) &&
- Numerics.equals(this.m11, that.m11) &&
- Numerics.equals(this.m12, that.m12) &&
- Numerics.equals(this.m13, that.m13) &&
- Numerics.equals(this.m20, that.m20) &&
- Numerics.equals(this.m21, that.m21) &&
- Numerics.equals(this.m22, that.m22) &&
- Numerics.equals(this.m23, that.m23) &&
- Numerics.equals(this.m30, that.m30) &&
- Numerics.equals(this.m31, that.m31) &&
- Numerics.equals(this.m32, that.m32) &&
- Numerics.equals(this.m33, that.m33);
- }
- return false;
- }
-
- /**
- * Returns a hash code value based on the data values in this object.
- */
- @Override
- public int hashCode() {
- return Arrays.hashCode(getElements()) ^ (int) serialVersionUID;
- }
}
Modified:
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/MatrixSIS.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/MatrixSIS.java?rev=1667899&r1=1667898&r2=1667899&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/MatrixSIS.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/MatrixSIS.java
[UTF-8] Thu Mar 19 23:32:35 2015
@@ -16,8 +16,12 @@
*/
package org.apache.sis.referencing.operation.matrix;
+import java.util.Arrays;
import java.io.Serializable;
+import java.awt.geom.AffineTransform; // For javadoc
import org.opengis.referencing.operation.Matrix;
+import org.apache.sis.internal.util.DoubleDouble;
+import org.apache.sis.internal.util.Numerics;
import org.apache.sis.util.ArgumentChecks;
import org.apache.sis.util.ComparisonMode;
import org.apache.sis.util.LenientComparable;
@@ -39,7 +43,7 @@ import org.apache.sis.util.resources.Err
*
* @author Martin Desruisseaux (IRD, Geomatys)
* @since 0.4
- * @version 0.4
+ * @version 0.6
* @module
*
* @see Matrices
@@ -126,6 +130,23 @@ public abstract class MatrixSIS implemen
}
/**
+ * Stores the value at the specified row and column in the given {@code
dd} object.
+ * This method does not need to verify argument validity.
+ */
+ void get(final int row, final int column, final DoubleDouble dd) {
+ dd.value = getElement(row, column);
+ dd.error = DoubleDouble.errorForWellKnownValue(dd.value);
+ }
+
+ /**
+ * Stores the value of the given {@code dd} object at the specified row
and column.
+ * This method does not need to verify argument validity.
+ */
+ void set(final int row, final int column, final DoubleDouble dd) {
+ setElement(row, column, dd.value);
+ }
+
+ /**
* Retrieves the value at the specified row and column of this matrix,
wrapped in a {@code Number}.
* The {@code Number} type depends on the matrix accuracy.
*
@@ -245,7 +266,71 @@ public abstract class MatrixSIS implemen
* ordinate in the source space is increased by one. Invoking this method
turns those vectors
* into unitary vectors, which is useful for forming the basis of a new
coordinate system.</p>
*/
- public abstract void normalizeColumns();
+ public void normalizeColumns() {
+ final int numRow = getNumRow();
+ final int numCol = getNumCol();
+ final DoubleDouble sum = new DoubleDouble();
+ final DoubleDouble dot = new DoubleDouble();
+ final DoubleDouble tmp = new DoubleDouble();
+ for (int i=0; i<numCol; i++) {
+ sum.clear();
+ for (int j=0; j<numRow; j++) {
+ get(j, i, dot);
+ dot.multiply(dot);
+ sum.add(dot);
+ }
+ sum.sqrt();
+ for (int j=0; j<numRow; j++) {
+ get(j, i, tmp);
+ dot.setFrom(sum);
+ dot.inverseDivide(tmp);
+ set(j, i, dot);
+ }
+ }
+ }
+
+ /**
+ * Assuming that this matrix represents an affine transform, applies a
scale and a translation
+ * on the given dimension.
+ *
+ * <p>If:</p>
+ * <ul>
+ * <li>{@code original} is this matrix before this method call</li>
+ * <li>{@code modified} is this matrix after this method call</li>
+ * </ul>
+ *
+ * Then transforming a coordinate by {@code modified} is equivalent to
first replacing the ordinate
+ * value at dimension {@code srcDim} by ({@code scale} ×
<var>ordinate</var> + {@code offset}),
+ * then apply the {@code original} transform.
+ *
+ * @param srcDim The dimension of the ordinate to rescale in the source
coordinates.
+ * @param scale The amount by which to multiply the source ordinate value
before to apply the transform, or {@code null} if none.
+ * @param offset The amount by which to translate the source ordinate
value before to apply the transform, or {@code null} if none.
+ *
+ * @see AffineTransform#concatenate(AffineTransform)
+ *
+ * @since 0.6
+ */
+ public void concatenateAffine(final int srcDim, final Number scale, final
Number offset) {
+ final int lastCol = getNumCol() - 1;
+ ArgumentChecks.ensureValidIndex(lastCol, srcDim);
+ final DoubleDouble s = new DoubleDouble();
+ final DoubleDouble t = new DoubleDouble();
+ for (int j = getNumRow() - 1; --j >= 0;) {
+ if (offset != null) {
+ get(j, srcDim, s); // Scale factor
+ get(j, lastCol, t); // Translation factor
+ s.multiply(offset);
+ t.add(s);
+ set(j, lastCol, t);
+ }
+ if (scale != null) {
+ get(j, srcDim, s); // Scale factor
+ s.multiply(scale);
+ set(j, srcDim, s);
+ }
+ }
+ }
/**
* Returns a new matrix which is the result of multiplying this matrix
with the specified one.
@@ -297,6 +382,43 @@ public abstract class MatrixSIS implemen
}
/**
+ * Returns a hash code value based on the data values in this matrix.
+ *
+ * @return A hash code value for this matrix.
+ */
+ @Override
+ public int hashCode() {
+ return Arrays.hashCode(getElements()) ^ (int) serialVersionUID;
+ }
+
+ /**
+ * Returns {@code true} if the specified object is of the same class than
this matrix and
+ * all of the data members are equal to the corresponding data members in
this matrix.
+ *
+ * @param object The object to compare with this matrix for equality.
+ * @return {@code true} if the given object is equal to this matrix.
+ */
+ @Override
+ public boolean equals(final Object object) {
+ if (object != null && object.getClass() == getClass()) {
+ final int numRow = getNumRow();
+ final int numCol = getNumCol();
+ final MatrixSIS that = (MatrixSIS) object;
+ if (that.getNumRow() == numRow && that.getNumCol() == numCol) {
+ for (int j=numRow; --j >= 0;) {
+ for (int i=numCol; --i >= 0;) {
+ if (!Numerics.equals(that.getElement(j, i),
getElement(j, i))) {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+ }
+ return false;
+ }
+
+ /**
* Compares the given matrices for equality, using the given absolute
tolerance threshold.
* The given matrix does not need to be the same implementation class than
this matrix.
*
Modified:
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/package-info.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/package-info.java?rev=1667899&r1=1667898&r2=1667899&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/package-info.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/matrix/package-info.java
[UTF-8] Thu Mar 19 23:32:35 2015
@@ -70,7 +70,7 @@
*
* @author Martin Desruisseaux (IRD, Geomatys)
* @since 0.4
- * @version 0.4
+ * @version 0.6
* @module
*/
package org.apache.sis.referencing.operation.matrix;
Modified:
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/NonLinearParameters.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/NonLinearParameters.java?rev=1667899&r1=1667898&r2=1667899&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/NonLinearParameters.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/NonLinearParameters.java
[UTF-8] Thu Mar 19 23:32:35 2015
@@ -44,9 +44,27 @@ import static org.apache.sis.util.Argume
* (<cite>normalize</cite> – <cite>non-linear kernel</cite> –
<cite>denormalize</cite>) transforms.
* The normalize and denormalize parts must be affine transforms.
*
- * <p>This object is used mostly for Apache SIS implementation of map
projections, where the kernel is a
+ * {@section Usage in map projections}
+ * This object is used mostly for Apache SIS implementation of map
projections, where the kernel is a
* {@linkplain
org.apache.sis.referencing.operation.projection.UnitaryProjection unitary
projection}.
- * See the {@linkplain org.apache.sis.referencing.operation.projection
projection package} for details.</p>
+ * This object is typically created and used as below:
+ *
+ * <ol>
+ * <li>A {@link
MathTransformProvider#createMathTransform(ParameterValueGroup)} method
+ * instantiates a class from the {@link
org.apache.sis.referencing.operation.projection} package.
+ * Note that different {@code MathTransformProvider}s may instantiate the
same map projection class.
+ * For example both <cite>"Mercator (variant A)"</cite> and
<cite>"Mercator (variant B)"</cite> operation methods
+ * instantiate the same {@link
org.apache.sis.referencing.operation.Mercator} class, but with different
descriptors.</li>
+ *
+ * <li>The map projection constructor fetches all parameters that he needs
from the user-supplied
+ * {@link ParameterValueGroup}, initializes the projection, then saves the
parameter values that
+ * it actually used in a new {@code NonLinearParameters} instance.</li>
+ *
+ * <li>The constructor should invoke {@link #normalizeGeographic(double)}
+ * and {@link #denormalizeCartesian(double, double, double, double)}.
+ * The constructor is free to apply additional operations on the two
affine transforms
+ * ({@linkplain #normalization(boolean) normalize / denormalize}) after
the above-cited methods have been invoked.</li>
+ * </ol>
*
* {@section Serialization}
* Serialized instances of this class are not guaranteed to be compatible with
future SIS versions.
Modified:
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/DoubleDouble.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/DoubleDouble.java?rev=1667899&r1=1667898&r2=1667899&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/DoubleDouble.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-utility/src/main/java/org/apache/sis/internal/util/DoubleDouble.java
[UTF-8] Thu Mar 19 23:32:35 2015
@@ -56,7 +56,7 @@ import org.apache.sis.math.DecimalFuncti
*
* @author Martin Desruisseaux (Geomatys)
* @since 0.4
- * @version 0.4
+ * @version 0.6
* @module
*
* @see <a
href="http://en.wikipedia.org/wiki/Double-double_%28arithmetic%29#Double-double_arithmetic">Wikipedia:
Double-double arithmetic</a>
@@ -943,6 +943,34 @@ public final class DoubleDouble extends
}
/**
+ * Returns a hash code value for this number.
+ *
+ * @return A hash code value.
+ */
+ @Override
+ public int hashCode() {
+ return Numerics.hashCode(Double.doubleToLongBits(value) ^
Double.doubleToLongBits(error));
+ }
+
+ /**
+ * Compares this number with the given object for equality.
+ *
+ * @param obj The other object to compare with this number.
+ * @return {@code true} if both object are equal.
+ */
+ @Override
+ public boolean equals(Object obj) {
+ if (obj instanceof DoubleDouble) {
+ final DoubleDouble other = (DoubleDouble) obj;
+ return Numerics.equals(value, other.value) &&
+ Numerics.equals(error, other.error);
+ }
+ return false;
+ }
+
+
+
+ /**
* Returns a string representation of this number for debugging purpose.
* The returned string does not need to contains all digits that this
{@code DoubleDouble} can handle.
*