001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2005-2006, Geotools Project Managment Committee (PMC)
005: * (C) 2001, 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;
018:
019: // J2SE dependencies and extensions
020: import java.awt.Color;
021: import java.io.Serializable;
022: import java.util.Arrays;
023: import javax.units.Unit;
024:
025: // OpenGIS dependencies
026: import org.opengis.util.Cloneable;
027: import org.opengis.referencing.operation.MathTransform1D;
028:
029: // Geotools dependencies
030: import org.geotools.util.NumberRange;
031: import org.geotools.coverage.Category;
032: import org.geotools.coverage.grid.GridCoverage2D;
033: import org.geotools.resources.Utilities;
034:
035: /**
036: * Argument type for {@link DefaultProcessor} operations for specifying the range,
037: * colors and units of a computation result. {@code RangeSpecifier} are used for tuning the
038: * {@link Category} object to be constructed. For example the {@code "GradientMagnitude"}
039: * operation will produces new {@link GridCoverage2D} with sample values ranging from 0 to some
040: * maximal value which may be very different from the source {@link GridCoverage2D} range. By
041: * default, most {@linkplain OperationJAI operations} try to guess a raisonable range for output
042: * values. This default behavior can be overridden with an explicit {@code RangeSpecifier}
043: * argument.
044: * <p>
045: * All {@code RangeSpecifier}'s properties are optional; it is up to processor's
046: * {@linkplain OperationJAI operation} to replace {@code null} values by a default
047: * one.
048: *
049: * @since 2.2
050: * @source $URL: http://svn.geotools.org/geotools/tags/2.4.1/modules/library/coverage/src/main/java/org/geotools/coverage/processing/RangeSpecifier.java $
051: * @version $Id: RangeSpecifier.java 23632 2006-12-29 22:13:51Z desruisseaux $
052: * @author Martin Desruisseaux
053: *
054: * @todo Move into the {@code org.geotools.coverage.grid} package as a {@code ImageLayout}
055: * subclass. Rename as {@code GridCoverageLayout}.
056: */
057: public class RangeSpecifier implements Serializable, Cloneable {
058: /**
059: * Serial number for compatibility with different versions.
060: */
061: private static final long serialVersionUID = 8436500582161136302L;
062:
063: /**
064: * The target range, or {@code null} if none.
065: */
066: private NumberRange range;
067:
068: /**
069: * The target "sample to geophysics" transform, or {@code null} if none.
070: */
071: private MathTransform1D transform;
072:
073: /**
074: * The target range units, or {@code null} if none.
075: */
076: private Unit unit;
077:
078: /**
079: * The target colors, or {@code null} if none.
080: */
081: private Color[] colors;
082:
083: /**
084: * Constructs a default {@code RangeSpecifier} with no value set.
085: */
086: public RangeSpecifier() {
087: }
088:
089: /**
090: * Constructs a {@code RangeSpecifier} initialised to the spécified range.
091: */
092: public RangeSpecifier(final NumberRange range) {
093: this .range = range;
094: }
095:
096: /**
097: * Constructs a {@code RangeSpecifier} initialised to the specified
098: * "sample to geophysics" transform.
099: */
100: public RangeSpecifier(final MathTransform1D transform) {
101: this .transform = transform;
102: }
103:
104: /**
105: * Returns the target range, or {@code null} if none.
106: */
107: public NumberRange getRange() {
108: return range;
109: }
110:
111: /**
112: * Set the target range to the specified values. Setting this property will clear
113: * the {@linkplain #getSampleToGeophysics sample to geophysics transform}, since
114: * those properties are mutually exclusive.
115: *
116: * @param range The target range.
117: */
118: public void setRange(final NumberRange range) {
119: this .range = range;
120: transform = null;
121: }
122:
123: /**
124: * Returns the target "sample to geophysics" transform, or {@code null} if none.
125: */
126: public MathTransform1D getSampleToGeophysics() {
127: return transform;
128: }
129:
130: /**
131: * Set the target "sample to geophysics" transform to the specified value.
132: * Setting this property will clear the {@linkplain #getRange range} property,
133: * since those properties are mutually exclusive.
134: */
135: public void setSampleToGeophysics(final MathTransform1D transform) {
136: this .transform = transform;
137: range = null;
138: }
139:
140: /**
141: * Returns the target range units, or {@code null} if none.
142: */
143: public Unit getUnit() {
144: return unit;
145: }
146:
147: /**
148: * Set the target range units to the specified value.
149: */
150: public void setUnit(final Unit unit) {
151: this .unit = unit;
152: }
153:
154: /**
155: * Returns the target colors, or {@code null} if none.
156: */
157: public Color[] getColors() {
158: return (colors != null) ? (Color[]) colors.clone() : null;
159: }
160:
161: /**
162: * Set the target colors to the specified value.
163: */
164: public void setColors(final Color[] colors) {
165: this .colors = (colors != null) ? (Color[]) colors.clone()
166: : null;
167: }
168:
169: /**
170: * Returns a clone of this object.
171: */
172: public Object clone() {
173: try {
174: return super .clone();
175: } catch (CloneNotSupportedException exception) {
176: // Should not happen, since we are cloneable.
177: throw new AssertionError(exception);
178: }
179: }
180:
181: /**
182: * Returns a hash code value for this range specifier.
183: */
184: public int hashCode() {
185: int code = (int) serialVersionUID;
186: if (range != null) {
187: code += range.hashCode();
188: }
189: if (transform != null) {
190: code += transform.hashCode();
191: }
192: return code;
193: }
194:
195: /**
196: * Compares this range specifier with the specified object for equality.
197: */
198: public boolean equals(final Object object) {
199: if (object != null && object.getClass().equals(getClass())) {
200: final RangeSpecifier that = (RangeSpecifier) object;
201: return Utilities.equals(this .range, that.range)
202: && Utilities.equals(this .transform, that.transform)
203: && Utilities.equals(this .unit, that.unit)
204: && Arrays.equals(this .colors, that.colors);
205: }
206: return false;
207: }
208:
209: /**
210: * Returns a string representation of this range specifier.
211: */
212: public String toString() {
213: final StringBuffer buffer = new StringBuffer(Utilities
214: .getShortClassName(this ));
215: buffer.append('[');
216: if (range != null) {
217: buffer.append(range);
218: } else if (transform != null) {
219: buffer.append(transform);
220: }
221: buffer.append(']');
222: return buffer.toString();
223: }
224: }
|