001 //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/tags/2.1/src/org/deegree/model/csct/ct/AffineTransform2D.java $
002 /*---------------- FILE HEADER ------------------------------------------
003
004 This file is part of deegree.
005 Copyright (C) 2001 by:
006 EXSE, Department of Geography, University of Bonn
007 http://www.giub.uni-bonn.de/exse/
008 lat/lon GmbH
009 http://www.lat-lon.de
010
011 It has been implemented within SEAGIS - An OpenSource implementation of OpenGIS specification
012 (C) 2001, Institut de Recherche pour le D�veloppement (http://sourceforge.net/projects/seagis/)
013 SEAGIS Contacts: Surveillance de l'Environnement Assist�e par Satellite
014 Institut de Recherche pour le D�veloppement / US-Espace
015 mailto:seasnet@teledetection.fr
016
017
018 This library is free software; you can redistribute it and/or
019 modify it under the terms of the GNU Lesser General Public
020 License as published by the Free Software Foundation; either
021 version 2.1 of the License, or (at your option) any later version.
022
023 This library is distributed in the hope that it will be useful,
024 but WITHOUT ANY WARRANTY; without even the implied warranty of
025 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
026 Lesser General Public License for more details.
027
028 You should have received a copy of the GNU Lesser General Public
029 License along with this library; if not, write to the Free Software
030 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
031
032 Contact:
033
034 Andreas Poth
035 lat/lon GmbH
036 Aennchenstr. 19
037 53115 Bonn
038 Germany
039 E-Mail: poth@lat-lon.de
040
041 Klaus Greve
042 Department of Geography
043 University of Bonn
044 Meckenheimer Allee 166
045 53115 Bonn
046 Germany
047 E-Mail: klaus.greve@uni-bonn.de
048
049
050 ---------------------------------------------------------------------------*/
051 package org.deegree.model.csct.ct;
052
053 import java.awt.geom.AffineTransform;
054 import java.awt.geom.Point2D;
055
056 import org.deegree.model.csct.pt.CoordinatePoint;
057 import org.deegree.model.csct.pt.Matrix;
058 import org.deegree.model.csct.resources.XAffineTransform;
059 import org.deegree.model.csct.resources.css.ResourceKeys;
060 import org.deegree.model.csct.resources.css.Resources;
061
062
063 /**
064 * Transforms two-dimensional coordinate points using an {@link AffineTransform}.
065 *
066 * @version 1.00
067 * @author Martin Desruisseaux
068 */
069 final class AffineTransform2D extends XAffineTransform implements MathTransform2D
070 {
071 /**
072 * Serial number for interoperability with different versions.
073 */
074 private static final long serialVersionUID = -5299837898367149069L;
075
076 /**
077 * The inverse transform. This field
078 * will be computed only when needed.
079 */
080 private transient AffineTransform2D inverse;
081
082 /**
083 * Construct an affine transform.
084 */
085 protected AffineTransform2D(final AffineTransform transform)
086 {super(transform);}
087
088 /**
089 * Throws an {@link UnsupportedOperationException} when a mutable method
090 * is invoked, since <code>AffineTransform2D</code> must be immutable.
091 */
092 protected void checkPermission()
093 {throw new UnsupportedOperationException(Resources.format(ResourceKeys.ERROR_UNMODIFIABLE_AFFINE_TRANSFORM));}
094
095 /**
096 * Gets the dimension of input points.
097 */
098 public int getDimSource()
099 {return 2;}
100
101 /**
102 * Gets the dimension of output points.
103 */
104 public int getDimTarget()
105 {return 2;}
106
107 /**
108 * Transforms the specified <code>ptSrc</code> and stores the result in <code>ptDst</code>.
109 */
110 public CoordinatePoint transform(final CoordinatePoint ptSrc, CoordinatePoint ptDst)
111 {
112 if (ptDst==null)
113 {
114 ptDst = new CoordinatePoint(2);
115 }
116 transform(ptSrc.ord, 0, ptDst.ord, 0, 1);
117 return ptDst;
118 }
119
120 /**
121 * Gets the derivative of this transform at a point.
122 * For an affine transform, the derivative is the
123 * same everywhere.
124 */
125 public Matrix derivative(final Point2D point)
126 {
127 final Matrix matrix = new Matrix(2);
128 matrix.setElement(0,0, getScaleX());
129 matrix.setElement(1,1, getScaleY());
130 matrix.setElement(0,1, getShearX());
131 matrix.setElement(1,0, getShearY());
132 return matrix;
133 }
134
135 /**
136 * Gets the derivative of this transform at a point.
137 * For an affine transform, the derivative is the
138 * same everywhere.
139 */
140 public Matrix derivative(final CoordinatePoint point)
141 {return derivative((Point2D) null);}
142
143 /**
144 * Creates the inverse transform of this object.
145 */
146 public synchronized MathTransform inverse() throws NoninvertibleTransformException
147 {
148 if (inverse==null) try
149 {
150 if (!isIdentity())
151 {
152 inverse = new AffineTransform2D(createInverse());
153 inverse.inverse = this;
154 }
155 else inverse = this;
156 }
157 catch (java.awt.geom.NoninvertibleTransformException exception)
158 {
159 throw new NoninvertibleTransformException(exception.getLocalizedMessage(), exception);
160 }
161 return inverse;
162 }
163
164 /**
165 * Returns the WKT for this affine transform.
166 */
167 public String toString()
168 {return MatrixTransform.toString(new Matrix(this));}
169 }