001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: *
005: * (C) 2003-2006, Geotools Project Managment Committee (PMC)
006: * (C) 2001, Institut de Recherche pour le Développement
007: *
008: * This library is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU Lesser General Public
010: * License as published by the Free Software Foundation; either
011: * version 2.1 of the License, or (at your option) any later version.
012: *
013: * This library is distributed in the hope that it will be useful,
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
016: * Lesser General Public License for more details.
017: */
018: package org.geotools.referencing.operation.transform;
019:
020: // J2SE dependencies
021: import java.awt.Shape;
022: import java.awt.geom.Point2D;
023:
024: // OpenGIS dependencies
025: import org.opengis.referencing.operation.MathTransform2D;
026: import org.opengis.referencing.operation.Matrix;
027: import org.opengis.referencing.operation.TransformException;
028:
029: // Geotools dependencies
030: import org.geotools.referencing.operation.matrix.XMatrix;
031:
032: /**
033: * Concatenated transform where both transforms are two-dimensional.
034: *
035: * @since 2.0
036: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/referencing/src/main/java/org/geotools/referencing/operation/transform/ConcatenatedTransformDirect2D.java $
037: * @version $Id: ConcatenatedTransformDirect2D.java 20874 2006-08-07 10:00:01Z jgarnett $
038: * @author Martin Desruisseaux
039: */
040: final class ConcatenatedTransformDirect2D extends
041: ConcatenatedTransformDirect implements MathTransform2D {
042: /**
043: * Serial number for interoperability with different versions.
044: */
045: private static final long serialVersionUID = 6009454091075588885L;
046:
047: /**
048: * The first math transform. This field is identical
049: * to {@link ConcatenatedTransform#transform1}. Only
050: * the type is different.
051: */
052: private final MathTransform2D transform1;
053:
054: /**
055: * The second math transform. This field is identical
056: * to {@link ConcatenatedTransform#transform1}. Only
057: * the type is different.
058: */
059: private final MathTransform2D transform2;
060:
061: /**
062: * Constructs a concatenated transform.
063: */
064: public ConcatenatedTransformDirect2D(
065: final MathTransform2D transform1,
066: final MathTransform2D transform2) {
067: super (transform1, transform2);
068: this .transform1 = transform1;
069: this .transform2 = transform2;
070: }
071:
072: /**
073: * Check if transforms are compatibles with this implementation.
074: */
075: boolean isValid() {
076: return super .isValid() && getSourceDimensions() == 2
077: && getTargetDimensions() == 2;
078: }
079:
080: /**
081: * Transforms the specified {@code ptSrc}
082: * and stores the result in {@code ptDst}.
083: */
084: public Point2D transform(final Point2D ptSrc, Point2D ptDst)
085: throws TransformException {
086: assert isValid();
087: ptDst = transform1.transform(ptSrc, ptDst);
088: return transform2.transform(ptDst, ptDst);
089: }
090:
091: /**
092: * Transforms the specified shape.
093: */
094: public Shape createTransformedShape(final Shape shape)
095: throws TransformException {
096: assert isValid();
097: return transform2.createTransformedShape(transform1
098: .createTransformedShape(shape));
099: }
100:
101: /**
102: * Gets the derivative of this transform at a point.
103: *
104: * @param point The coordinate point where to evaluate the derivative.
105: * @return The derivative at the specified point (never {@code null}).
106: * @throws TransformException if the derivative can't be evaluated at the specified point.
107: */
108: public Matrix derivative(final Point2D point)
109: throws TransformException {
110: final XMatrix matrix1 = toXMatrix(transform1.derivative(point));
111: final XMatrix matrix2 = toXMatrix(transform2
112: .derivative(transform1.transform(point, null)));
113: matrix2.multiply(matrix1);
114: return matrix2;
115: }
116: }
|