01: /*
02: * GeoTools - OpenSource mapping toolkit
03: * http://geotools.org
04: *
05: * (C) 2003-2006, Geotools Project Managment Committee (PMC)
06: * (C) 2001, Institut de Recherche pour le Développement
07: *
08: * This library is free software; you can redistribute it and/or
09: * modify it under the terms of the GNU Lesser General Public
10: * License as published by the Free Software Foundation; either
11: * version 2.1 of the License, or (at your option) any later version.
12: *
13: * This library is distributed in the hope that it will be useful,
14: * but WITHOUT ANY WARRANTY; without even the implied warranty of
15: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16: * Lesser General Public License for more details.
17: */
18: package org.geotools.referencing.operation.transform;
19:
20: // OpenGIS dependencies
21: import org.geotools.geometry.DirectPosition1D;
22: import org.opengis.referencing.operation.MathTransform;
23: import org.opengis.referencing.operation.MathTransform1D;
24: import org.opengis.referencing.operation.Matrix;
25: import org.opengis.referencing.operation.TransformException;
26:
27: /**
28: * Concatenated transform in which the resulting transform is one-dimensional.
29: *
30: * @since 2.0
31: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/referencing/src/main/java/org/geotools/referencing/operation/transform/ConcatenatedTransform1D.java $
32: * @version $Id: ConcatenatedTransform1D.java 20874 2006-08-07 10:00:01Z jgarnett $
33: * @author Martin Desruisseaux
34: */
35: final class ConcatenatedTransform1D extends ConcatenatedTransform
36: implements MathTransform1D {
37: /**
38: * Serial number for interoperability with different versions.
39: */
40: private static final long serialVersionUID = 8150427971141078395L;
41:
42: /**
43: * Constructs a concatenated transform.
44: */
45: public ConcatenatedTransform1D(final MathTransform transform1,
46: final MathTransform transform2) {
47: super (transform1, transform2);
48: }
49:
50: /**
51: * Check if transforms are compatibles with this implementation.
52: */
53: boolean isValid() {
54: return super .isValid() && getSourceDimensions() == 1
55: && getTargetDimensions() == 1;
56: }
57:
58: /**
59: * Transforms the specified value.
60: */
61: public double transform(final double value)
62: throws TransformException {
63: final double[] values = new double[] { value };
64: final double[] buffer = new double[] { transform1
65: .getTargetDimensions() };
66: transform1.transform(values, 0, buffer, 0, 1);
67: transform2.transform(buffer, 0, values, 0, 1);
68: return values[0];
69: }
70:
71: /**
72: * Gets the derivative of this function at a value.
73: */
74: public double derivative(final double value)
75: throws TransformException {
76: final DirectPosition1D p = new DirectPosition1D(value);
77: final Matrix m = derivative(p);
78: assert m.getNumRow() == 1 && m.getNumCol() == 1;
79: return m.getElement(0, 0);
80: }
81: }
|