001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2005-2006, Geotools Project Managment Committee (PMC)
005: * (C) 2005, Institut de Recherche pour le Développement
006: *
007: * This library is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU Lesser General Public
009: * License as published by the Free Software Foundation; either
010: * version 2.1 of the License, or (at your option) any later version.
011: *
012: * This library is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: */
017: package org.geotools.coverage.processing.operation;
018:
019: // JAI dependencies (for javadoc)
020: import javax.media.jai.operator.DivideByConstDescriptor;
021:
022: // Geotools dependencies
023: import org.geotools.util.NumberRange;
024: import org.geotools.coverage.processing.OperationJAI;
025:
026: /**
027: * Divides every sample values of the source coverage by constants (one for each band).
028: * If the number of constants supplied is less than the number of bands of the destination,
029: * then the constant from entry 0 is applied to all the bands. Otherwise, a constant from a
030: * different entry is applied to each band.
031: *
032: * <P><STRONG>Name:</STRONG> <CODE>"DivideByConst"</CODE><BR>
033: * <STRONG>JAI operator:</STRONG> <CODE>"{@linkplain DivideByConstDescriptor DivideByConst}"</CODE><BR>
034: * <STRONG>Parameters:</STRONG></P>
035: * <table border='3' cellpadding='6' bgcolor='F4F8FF'>
036: * <tr bgcolor='#B9DCFF'>
037: * <th>Name</th>
038: * <th>Class</th>
039: * <th>Default value</th>
040: * <th>Minimum value</th>
041: * <th>Maximum value</th>
042: * </tr>
043: * <tr>
044: * <td>{@code "Source"}</td>
045: * <td>{@link org.geotools.coverage.grid.GridCoverage2D}</td>
046: * <td align="center">N/A</td>
047: * <td align="center">N/A</td>
048: * <td align="center">N/A</td>
049: * </tr>
050: * <tr>
051: * <td>{@code "constants"}</td>
052: * <td>{@code double[]}</td>
053: * <td align="center">1.0</td>
054: * <td align="center">N/A</td>
055: * <td align="center">N/A</td>
056: * </tr>
057: * </table>
058: *
059: * @since 2.2
060: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/coverage/src/main/java/org/geotools/coverage/processing/operation/DivideByConst.java $
061: * @version $Id: DivideByConst.java 20970 2006-08-11 07:53:22Z jgarnett $
062: * @author Martin Desruisseaux
063: *
064: * @see org.geotools.coverage.processing.Operations#divideBy
065: * @see DivideByConstDescriptor
066: *
067: * @todo Should operates on {@code sampleToGeophysics} transform when possible.
068: * See <A HREF="http://jira.codehaus.org/browse/GEOT-610">GEOT-610</A>.
069: */
070: public class DivideByConst extends OperationJAI {
071: /**
072: * Serial number for interoperability with different versions.
073: */
074: private static final long serialVersionUID = -3723238033407316564L;
075:
076: /**
077: * Constructs a default {@code "DivideByConst"} operation.
078: */
079: public DivideByConst() {
080: super ("DivideByConst");
081: }
082:
083: /**
084: * Returns the expected range of values for the resulting image.
085: */
086: protected NumberRange deriveRange(final NumberRange[] ranges,
087: final Parameters parameters) {
088: final double[] constants = (double[]) parameters.parameters
089: .getObjectParameter("constants");
090: if (constants.length == 1) {
091: final double c = constants[0];
092: final NumberRange range = ranges[0];
093: final double min = range.getMinimum() / c;
094: final double max = range.getMaximum() / c;
095: return (max < min) ? new NumberRange(max, min)
096: : new NumberRange(min, max);
097: }
098: return super.deriveRange(ranges, parameters);
099: }
100: }
|