Author: desruisseaux
Date: Fri Jun 27 18:34:28 2014
New Revision: 1606173
URL: http://svn.apache.org/r1606173
Log:
Ported a test.
Added:
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/ConcatenatedTransformTest.java
(with props)
Modified:
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/AbstractMathTransform.java
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/AbstractMathTransform2D.java
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ConcatenatedTransform.java
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/PassThroughTransform.java
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
Modified:
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/AbstractMathTransform.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/AbstractMathTransform.java?rev=1606173&r1=1606172&r2=1606173&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/AbstractMathTransform.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/AbstractMathTransform.java
[UTF-8] Fri Jun 27 18:34:28 2014
@@ -951,7 +951,7 @@ public abstract class AbstractMathTransf
* @see AbstractMathTransform2D#beforeFormat(List, int, boolean)
* @see ConcatenatedTransform#getPseudoSteps()
*/
- int beforeFormat(List<MathTransform> transforms, int index, boolean
inverse) {
+ int beforeFormat(List<Object> transforms, int index, boolean inverse) {
return index;
}
Modified:
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/AbstractMathTransform2D.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/AbstractMathTransform2D.java?rev=1606173&r1=1606172&r2=1606173&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/AbstractMathTransform2D.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/AbstractMathTransform2D.java
[UTF-8] Fri Jun 27 18:34:28 2014
@@ -26,7 +26,6 @@ import java.awt.geom.PathIterator;
import java.awt.geom.AffineTransform;
import java.awt.geom.IllegalPathStateException;
import org.opengis.referencing.operation.Matrix;
-import org.opengis.referencing.operation.MathTransform;
import org.opengis.referencing.operation.MathTransform2D;
import org.opengis.referencing.operation.TransformException;
import org.opengis.referencing.operation.NoninvertibleTransformException;
@@ -340,11 +339,52 @@ public abstract class AbstractMathTransf
}
/**
+ * Transforms the specified {@code ptSrc} and stores the result in
{@code ptDst}.
+ * The default implementation invokes {@link #transform(double[], int,
double[], int, boolean)}
+ * using a temporary array of doubles.
+ *
+ * @param ptSrc The coordinate point to be transformed.
+ * @param ptDst The coordinate point that stores the result of
transforming {@code ptSrc},
+ * or {@code null} if a new point shall be created.
+ * @return The coordinate point after transforming {@code ptSrc} and
storing the result in {@code ptDst},
+ * or in a new point if {@code ptDst} was null.
+ * @throws TransformException If the point can not be transformed.
+ *
+ * @see MathTransform2D#transform(Point2D, Point2D)
+ */
+ @Override
+ public Point2D transform(final Point2D ptSrc, final Point2D ptDst)
throws TransformException {
+ final double[] ord = new double[] {ptSrc.getX(), ptSrc.getY()};
+ transform(ord, 0, ord, 0, false);
+ if (ptDst != null) {
+ ptDst.setLocation(ord[0], ord[1]);
+ return ptDst;
+ } else {
+ return new Point2D.Double(ord[0], ord[1]);
+ }
+ }
+
+ /**
+ * Transforms the specified shape. The default implementation computes
quadratic curves
+ * using three points for each line segment in the shape. The returned
object is often
+ * a {@link Path2D}, but may also be a {@link Line2D} or a {@link
QuadCurve2D} if such
+ * simplification is possible.
+ *
+ * @param shape Shape to transform.
+ * @return Transformed shape, or {@code shape} if this transform is
the identity transform.
+ * @throws TransformException if a transform failed.
+ */
+ @Override
+ public Shape createTransformedShape(final Shape shape) throws
TransformException {
+ return isIdentity() ? shape :
AbstractMathTransform2D.createTransformedShape(this, shape, null, null, false);
+ }
+
+ /**
* Same work than {@link AbstractMathTransform2D#beforeFormat(List,
int, boolean)}
* but with the knowledge that this transform is an inverse transform.
*/
@Override
- final int beforeFormat(final List<MathTransform> transforms, final int
index, final boolean inverse) {
+ final int beforeFormat(final List<Object> transforms, final int index,
final boolean inverse) {
return AbstractMathTransform2D.this.beforeFormat(transforms,
index, !inverse);
}
}
Modified:
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ConcatenatedTransform.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ConcatenatedTransform.java?rev=1606173&r1=1606172&r2=1606173&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ConcatenatedTransform.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/ConcatenatedTransform.java
[UTF-8] Fri Jun 27 18:34:28 2014
@@ -38,6 +38,7 @@ import org.apache.sis.util.ComparisonMod
import org.apache.sis.util.Utilities;
import org.apache.sis.io.wkt.Convention;
import org.apache.sis.io.wkt.Formatter;
+import org.apache.sis.io.wkt.FormattableObject;
import org.apache.sis.util.resources.Errors;
@@ -409,11 +410,11 @@ class ConcatenatedTransform extends Abst
* (<var>normalize</var>, <var>unitary projection</var>,
<var>denormalize</var>) tuples are replaced by single
* (<var>projection</var>) elements, which does not need to be instances
of {@link MathTransform}.
*/
- private List<MathTransform> getPseudoSteps() {
- final List<MathTransform> transforms = new ArrayList<>();
+ private List<Object> getPseudoSteps() {
+ final List<Object> transforms = new ArrayList<>();
getSteps(transforms);
/*
- * Pre-process the transforms before to format. Some steps may be*
merged, or new
+ * Pre-process the transforms before to format. Some steps may be
merged, or new
* steps may be created. Do not move size() out of the loop, because
it may change.
*/
for (int i=0; i<transforms.size(); i++) {
@@ -430,7 +431,7 @@ class ConcatenatedTransform extends Abst
*
* @param transforms The list where to add concatenated transforms.
*/
- private void getSteps(final List<MathTransform> transforms) {
+ private void getSteps(final List<? super MathTransform> transforms) {
if (transform1 instanceof ConcatenatedTransform) {
((ConcatenatedTransform) transform1).getSteps(transforms);
} else {
@@ -468,7 +469,7 @@ class ConcatenatedTransform extends Abst
*/
private Parameterized getParameterised() {
Parameterized param = null;
- final List<MathTransform> transforms = getPseudoSteps();
+ final List<Object> transforms = getPseudoSteps();
if (transforms.size() == 1 || Semaphores.query(Semaphores.PROJCS)) {
for (final Object candidate : transforms) {
if (!(candidate instanceof Parameterized)) {
@@ -888,7 +889,7 @@ class ConcatenatedTransform extends Abst
*/
@Override
public String formatTo(final Formatter formatter) {
- final List<MathTransform> transforms;
+ final List<? super MathTransform> transforms;
if (formatter.getConvention() == Convention.INTERNAL) {
transforms = getSteps();
} else {
@@ -902,9 +903,13 @@ class ConcatenatedTransform extends Abst
if (transforms.size() == 1) {
return formatter.delegateTo(transforms.get(0));
}
- for (final MathTransform step : transforms) {
+ for (final Object step : transforms) {
formatter.newLine();
- formatter.append(step);
+ if (step instanceof FormattableObject) {
+ formatter.append((FormattableObject) step); // May not
implement MathTransform.
+ } else {
+ formatter.append((MathTransform) step);
+ }
}
return "Concat_MT";
}
Modified:
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/PassThroughTransform.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/PassThroughTransform.java?rev=1606173&r1=1606172&r2=1606173&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/PassThroughTransform.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-referencing/src/main/java/org/apache/sis/referencing/operation/transform/PassThroughTransform.java
[UTF-8] Fri Jun 27 18:34:28 2014
@@ -85,7 +85,7 @@ public class PassThroughTransform extend
* The sub-transform to apply on the {@linkplain #getModifiedCoordinates()
modified coordinates}.
* This is often the sub-transform specified at construction time, but not
necessarily.
*/
- protected final MathTransform subTransform;
+ final MathTransform subTransform;
/**
* The inverse transform. This field will be computed only when needed,
@@ -275,6 +275,16 @@ public class PassThroughTransform extend
}
/**
+ * Returns the sub-transform to apply on the {@linkplain
#getModifiedCoordinates() modified coordinates}.
+ * This is often the sub-transform specified at construction time, but not
necessarily.
+ *
+ * @return The sub-transform.
+ */
+ public final MathTransform getSubTransform() {
+ return subTransform;
+ }
+
+ /**
* Tests whether this transform does not move any points. A {@code
PassThroughTransform}
* is identity if the {@linkplain #subTransform sub-transform} is also
identity.
*
Added:
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/ConcatenatedTransformTest.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/ConcatenatedTransformTest.java?rev=1606173&view=auto
==============================================================================
---
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/ConcatenatedTransformTest.java
(added)
+++
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/ConcatenatedTransformTest.java
[UTF-8] Fri Jun 27 18:34:28 2014
@@ -0,0 +1,155 @@
+/*
+ * 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.referencing.operation.transform;
+
+import org.opengis.referencing.operation.MathTransform;
+import org.opengis.referencing.operation.TransformException;
+import org.apache.sis.internal.referencing.j2d.AffineTransform2D;
+import org.apache.sis.referencing.operation.matrix.Matrix4;
+import org.apache.sis.test.DependsOn;
+import org.junit.Test;
+
+import static org.opengis.test.Assert.*;
+
+
+/**
+ * Tests the {@link ConcatenatedTransform} class.
+ *
+ * @author Martin Desruisseaux (Geomatys)
+ * @since 0.5 (derived from geotk-3.00)
+ * @version 0.5
+ * @module
+ */
+@DependsOn(ProjectiveTransformTest.class)
+public final strictfp class ConcatenatedTransformTest extends
MathTransformTestCase {
+ /**
+ * Tests the concatenation of two affine transforms than can be represented
+ * as a {@link ConcatenatedTransformDirect2D}.
+ *
+ * @throws TransformException Should never happen.
+ */
+ @Test
+ public void testDirect2D() throws TransformException {
+ final AffineTransform2D first = new AffineTransform2D();
+ first.translate(2,4);
+ first.freeze();
+
+ final AffineTransform2D second = new AffineTransform2D();
+ second.translate(0.25, 0.75);
+ second.freeze();
+
+ // Direct for 2D case.
+ tolerance = 1E-10;
+ transform = new ConcatenatedTransformDirect2D(first, second);
+ validate();
+ final double[] source =
generateRandomCoordinates(CoordinateDomain.PROJECTED, 0);
+ final double[] target = new double[source.length];
+ first .transform(source, 0, target, 0, source.length/2);
+ second.transform(target, 0, target, 0, target.length/2);
+ verifyTransform(source, target);
+
+ // Non-direct for 2D case.
+ transform = new ConcatenatedTransform2D(first, second);
+ validate();
+ verifyTransform(source, target);
+
+ // Direct for general case - can't be validated.
+ transform = new ConcatenatedTransformDirect(first, second);
+ verifyTransform(source, target);
+
+ // Most general case - can't be validated.
+ transform = new ConcatenatedTransform(first, second);
+ verifyTransform(source, target);
+
+ // Optimized case.
+ transform = MathTransforms.concatenate(first, second);
+ assertInstanceOf("Expected optimized concatenation through matrix
multiplication.", AffineTransform2D.class, transform);
+ validate();
+ verifyTransform(source, target);
+ }
+
+ /**
+ * Tests the concatenation of two affine transforms than can not be
represented as a
+ * {@link ConcatenatedTransformDirect}. The slower {@link
ConcatenatedTransform} shall be used.
+ *
+ * @throws TransformException Should never happen.
+ */
+ @Test
+ @org.junit.Ignore("Missing implementation of DimensionFilter.")
+ public void testGeneric() throws TransformException {
+ final MathTransform first = null; //MathTransforms.dimensionFilter(4,
new int[] {1,3});
+
+ final AffineTransform2D second = new AffineTransform2D();
+ second.scale(0.5, 0.25);
+ second.freeze();
+
+ transform = new ConcatenatedTransform(first, second);
+ isInverseTransformSupported = false;
+ validate();
+ final double[] source =
generateRandomCoordinates(CoordinateDomain.PROJECTED, 0);
+ final double[] target = new double[source.length / 2]; // Going from 4
to 2 dimensions.
+ first .transform(source, 0, target, 0, target.length/2);
+ second.transform(target, 0, target, 0, target.length/2);
+ verifyTransform(source, target);
+
+ // Optimized case.
+ transform = ConcatenatedTransform.create(first, second);
+ assertInstanceOf("Expected optimized concatenation through matrix
multiplication.", ProjectiveTransform.class, transform);
+ validate();
+ verifyTransform(source, target);
+ }
+
+ /**
+ * Tests the concatenation of a 3D affine transform with a pass-through
transform.
+ * The {@link ConcatenatedTransform#create(MathTransform, MathTransform)}
method
+ * should optimize this case.
+ */
+ @Test
+ public void testPassthrough() {
+ final MathTransform kernel = new PseudoTransform(2, 3); // Any
non-linear transform.
+ final MathTransform passth = PassThroughTransform.create(0, kernel, 1);
+ final Matrix4 matrix = new Matrix4();
+ transform =
ConcatenatedTransform.create(MathTransforms.linear(matrix), passth);
+ assertSame("Identity transform should be ignored.", passth, transform);
+ assertEquals("Source dimensions", 3, transform.getSourceDimensions());
+ assertEquals("Target dimensions", 4, transform.getTargetDimensions());
+ /*
+ * Put scale or offset factors only in the dimension to be processed
by the sub-transform.
+ * The matrix should be concatenated to the sub-transform rather than
to the passthrough
+ * transform.
+ */
+ matrix.m00 = 3;
+ matrix.m13 = 2;
+ transform =
ConcatenatedTransform.create(MathTransforms.linear(matrix), passth);
+ assertInstanceOf("Expected a new passthrough transform.",
PassThroughTransform.class, transform);
+ final MathTransform subTransform = ((PassThroughTransform)
transform).getSubTransform();
+ assertInstanceOf("Expected a new concatenated transform.",
ConcatenatedTransform.class, subTransform);
+ assertSame(kernel, ((ConcatenatedTransform) subTransform).transform2);
+ assertEquals("Source dimensions", 3, transform.getSourceDimensions());
+ assertEquals("Target dimensions", 4, transform.getTargetDimensions());
+ /*
+ * Put scale or offset factors is a passthrough dimension. Now, the
affine transform
+ * can not anymore be concatenated with the sub-transform.
+ */
+ matrix.m22 = 4;
+ transform =
ConcatenatedTransform.create(MathTransforms.linear(matrix), passth);
+ assertInstanceOf("Expected a new concatenated transform.",
ConcatenatedTransform.class, transform);
+ assertSame(passth, ((ConcatenatedTransform) transform).transform2);
+ assertEquals("Source dimensions", 3, transform.getSourceDimensions());
+ assertEquals("Target dimensions", 4, transform.getTargetDimensions());
+ }
+}
Propchange:
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/ConcatenatedTransformTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/referencing/operation/transform/ConcatenatedTransformTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain;charset=UTF-8
Modified:
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
URL:
http://svn.apache.org/viewvc/sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java?rev=1606173&r1=1606172&r2=1606173&view=diff
==============================================================================
---
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
[UTF-8] (original)
+++
sis/branches/JDK8/core/sis-referencing/src/test/java/org/apache/sis/test/suite/ReferencingTestSuite.java
[UTF-8] Fri Jun 27 18:34:28 2014
@@ -48,6 +48,7 @@ import org.junit.BeforeClass;
org.apache.sis.referencing.operation.transform.ExponentialTransform1DTest.class,
org.apache.sis.referencing.operation.transform.CopyTransformTest.class,
org.apache.sis.referencing.operation.transform.PassThroughTransformTest.class,
+
org.apache.sis.referencing.operation.transform.ConcatenatedTransformTest.class,
org.apache.sis.referencing.operation.transform.TransferFunctionTest.class,
org.apache.sis.internal.referencing.FormulasTest.class,