01: /*
02: * GeoTools - OpenSource mapping toolkit
03: * http://geotools.org
04: * (C) 2005-2006, Geotools Project Managment Committee (PMC)
05: * (C) 2005, Institut de Recherche pour le Développement
06: *
07: * This library is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU Lesser General Public
09: * License as published by the Free Software Foundation; either
10: * version 2.1 of the License, or (at your option) any later version.
11: *
12: * This library is distributed in the hope that it will be useful,
13: * but WITHOUT ANY WARRANTY; without even the implied warranty of
14: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15: * Lesser General Public License for more details.
16: */
17: package org.geotools.coverage.processing.operation;
18:
19: // JAI dependencies (for javadoc)
20: import javax.media.jai.operator.SubtractConstDescriptor;
21:
22: // Geotools dependencies
23: import org.geotools.util.NumberRange;
24: import org.geotools.coverage.processing.OperationJAI;
25:
26: /**
27: * Subtracts constants (one for each band) from every sample values of the source coverage.
28: * If the number of constants supplied is less than the number of bands of the destination,
29: * then the constant from entry 0 is applied to all the bands. Otherwise, a constant from a
30: * different entry is applied to each band.
31: *
32: * <P><STRONG>Name:</STRONG> <CODE>"SubtractConst"</CODE><BR>
33: * <STRONG>JAI operator:</STRONG> <CODE>"{@linkplain SubtractConstDescriptor SubtractConst}"</CODE><BR>
34: * <STRONG>Parameters:</STRONG></P>
35: * <table border='3' cellpadding='6' bgcolor='F4F8FF'>
36: * <tr bgcolor='#B9DCFF'>
37: * <th>Name</th>
38: * <th>Class</th>
39: * <th>Default value</th>
40: * <th>Minimum value</th>
41: * <th>Maximum value</th>
42: * </tr>
43: * <tr>
44: * <td>{@code "Source"}</td>
45: * <td>{@link org.geotools.coverage.grid.GridCoverage2D}</td>
46: * <td align="center">N/A</td>
47: * <td align="center">N/A</td>
48: * <td align="center">N/A</td>
49: * </tr>
50: * <tr>
51: * <td>{@code "constants"}</td>
52: * <td>{@code double[]}</td>
53: * <td align="center">N/A</td>
54: * <td align="center">N/A</td>
55: * <td align="center">N/A</td>
56: * </tr>
57: * </table>
58: *
59: * @since 2.2
60: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/coverage/src/main/java/org/geotools/coverage/processing/operation/SubtractConst.java $
61: * @version $Id: SubtractConst.java 20970 2006-08-11 07:53:22Z jgarnett $
62: * @author Martin Desruisseaux
63: *
64: * @see org.geotools.coverage.processing.Operations#subtract
65: * @see SubtractConstDescriptor
66: *
67: * @todo Should operates on {@code sampleToGeophysics} transform when possible.
68: * See <A HREF="http://jira.codehaus.org/browse/GEOT-610">GEOT-610</A>.
69: */
70: public class SubtractConst extends OperationJAI {
71: /**
72: * Serial number for interoperability with different versions.
73: */
74: private static final long serialVersionUID = 279426577290256732L;
75:
76: /**
77: * Constructs a default {@code "SubtractConst"} operation.
78: */
79: public SubtractConst() {
80: super ("SubtractConst");
81: }
82:
83: /**
84: * Returns the expected range of values for the resulting image.
85: */
86: protected NumberRange deriveRange(final NumberRange[] ranges,
87: final Parameters parameters) {
88: final double[] constants = (double[]) parameters.parameters
89: .getObjectParameter("constants");
90: if (constants.length == 1) {
91: final double c = constants[0];
92: final NumberRange range = ranges[0];
93: final double min = range.getMinimum() - c;
94: final double max = range.getMaximum() - c;
95: return new NumberRange(min, max);
96: }
97: return super.deriveRange(ranges, parameters);
98: }
99: }
|