001: //$HeadURL: $
002: /*---------------- FILE HEADER ------------------------------------------
003: This file is part of deegree.
004: Copyright (C) 2001-2008 by:
005: Department of Geography, University of Bonn
006: http://www.giub.uni-bonn.de/deegree/
007: lat/lon GmbH
008: http://www.lat-lon.de
009:
010: This library is free software; you can redistribute it and/or
011: modify it under the terms of the GNU Lesser General Public
012: License as published by the Free Software Foundation; either
013: version 2.1 of the License, or (at your option) any later version.
014: This library is distributed in the hope that it will be useful,
015: but WITHOUT ANY WARRANTY; without even the implied warranty of
016: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017: Lesser General Public License for more details.
018: You should have received a copy of the GNU Lesser General Public
019: License along with this library; if not, write to the Free Software
020: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
021: Contact:
022:
023: Andreas Poth
024: lat/lon GmbH
025: Aennchenstr. 19
026: 53177 Bonn
027: Germany
028: E-Mail: poth@lat-lon.de
029:
030: Prof. Dr. Klaus Greve
031: Department of Geography
032: University of Bonn
033: Meckenheimer Allee 166
034: 53115 Bonn
035: Germany
036: E-Mail: greve@giub.uni-bonn.de
037: ---------------------------------------------------------------------------*/
038:
039: package org.deegree.crs.transformations;
040:
041: import java.util.List;
042:
043: import javax.vecmath.Point3d;
044:
045: import org.deegree.crs.exceptions.TransformationException;
046:
047: /**
048: * The <code>ConcatenatedTransform</code> class allows the connection of two transformations.
049: * <p>
050: * Calling inverse on this transformation will invert the whole underlying transformation chain. For example, if A * (B
051: * *C)=D and D is this transformation calling D.inverse() will result in (C.inverse * B.inverse) * A.inverse.
052: * </p>
053: *
054: * @author <a href="mailto:bezema@lat-lon.de">Rutger Bezema</a>
055: *
056: * @author last edited by: $Author:$
057: *
058: * @version $Revision:$, $Date:$
059: *
060: */
061:
062: public class ConcatenatedTransform extends CRSTransformation {
063:
064: boolean isIdentitiy = false;
065:
066: private CRSTransformation firstTransform;
067:
068: private CRSTransformation secondTransform;
069:
070: /**
071: * Creates a transform by concatenating two existing transforms. A concatenated transform applies two transforms,
072: * one after the other. The dimension of the output space of the first transform must match the dimension of the
073: * input space in the second transform.
074: *
075: * @param first
076: * The first transformation to apply to given points.
077: * @param second
078: * The second transformation to apply to given points.
079: */
080: public ConcatenatedTransform(CRSTransformation first,
081: CRSTransformation second) {
082: super (first.getSourceCRS(), second.getTargetCRS());
083: if (first.isIdentity() && second.isIdentity()) {
084: isIdentitiy = true;
085: }
086: firstTransform = first;
087: secondTransform = second;
088: }
089:
090: @Override
091: public List<Point3d> doTransform(List<Point3d> srcPts)
092: throws TransformationException {
093: if (!isIdentitiy) {
094: List<Point3d> dest = firstTransform.doTransform(srcPts);
095: return secondTransform.doTransform(dest);
096: }
097: return srcPts;
098: }
099:
100: @Override
101: public void inverse() {
102: super .inverse();
103: CRSTransformation tmp = firstTransform;
104: firstTransform = secondTransform;
105: secondTransform = tmp;
106: firstTransform.inverse();
107: secondTransform.inverse();
108: }
109:
110: /*
111: * (non-Javadoc)
112: *
113: * @see org.deegree.crs.transformations.CRSTransformation#isIdentity()
114: */
115: @Override
116: public boolean isIdentity() {
117: return isIdentitiy;
118: }
119:
120: /**
121: * @return the firstTransform, which is the second transformation if this transform is inverse.
122: */
123: public final CRSTransformation getFirstTransform() {
124: return firstTransform;
125: }
126:
127: /**
128: * @return the secondTransform, which is the first transformation if this transform is inverse.
129: */
130: public final CRSTransformation getSecondTransform() {
131: return secondTransform;
132: }
133:
134: @Override
135: public String getName() {
136: return "Concatenated-Transform";
137: }
138:
139: }
|