// // Linear1DSet.java // /* VisAD system for interactive analysis and visualization of numerical data. Copyright (C) 1996 - 2017 Bill Hibbard, Curtis Rueden, Tom Rink, Dave Glowacki, Steve Emmerson, Tom Whittaker, Don Murray, and Tommy Jasmin. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ package visad; /** Linear1DSet represents a finite set of samples of R in an arithmetic progression.is a Linear1DSet and * the type, first, last and lengths of the progressions * are equal. */ public boolean equals(Object set) { boolean flag; if (!(set instanceof Linear1DSet) || set == null) return false; if (this == set) return true; if (!equalUnitAndCS((Set) set)) return false; try { flag = (First == ((Linear1DSet) set).getFirst() && Last == ((Linear1DSet) set).getLast() && Length == ((Linear1DSet) set).getLength()); } catch (VisADException e) { return false; } return flag; } /** * Returns the hash code for this instance. * @return The hash code for this instance. */ public int hashCode() { if (!hashCodeSet) { hashCode = unitAndCSHashCode() ^ new Double(First).hashCode() ^ new Double(Last).hashCode() ^ Length; hashCodeSet = true; } return hashCode; } /** * Get the indexed component (X is at 0 and is the only valid index) * * @param i Index of component * @return The requested component * @exception ArrayIndexOutOfBoundsException If an invalid index is * specified. */ public Linear1DSet getLinear1DComponent(int i) { if (i == 0) return this; else throw new ArrayIndexOutOfBoundsException("Invalid component index " + i); } /** * Return a clone of this object with a new MathType. * @param type new MathType. * @return new Linear1DSet withThe samples are ordered from First to Last.
*/ public class Linear1DSet extends Gridded1DSet implements LinearSet, GriddedDoubleSet { private double First, Last, Step, Invstep; private boolean cacheSamples; /** * Construct a 1-D arithmetic progression with null * errors and generic type * @param first first value in progression * @param last last value in progression * @param length number of samples in progression (R) * @throws VisADException problem creating set */ public Linear1DSet(double first, double last, int length) throws VisADException { this(RealType.Generic, first, last, length, null, null, null); } /** * Construct a 1-D arithmetic progression with the specified *
typeand null errors. * @param type MathType for this Linear1DSet. * @param first first value in progression * @param last last value in progression * @param length number of samples in progression (R) * @throws VisADException problem creating set */ public Linear1DSet(MathType type, double first, double last, int length) throws VisADException { this(type, first, last, length, null, null, null); } /** * Construct a 1-D arithmetic progression with * the specifiedtype,coord_sys, *unitsanderrors. * @param type MathType for this Linear2DSet. * @param first first value in progression * @param last last value in progression * @param length number of samples in progression (R) * @param coord_sys CoordinateSystem for this set. May be null, but * if not, must be consistent withtype. * @param units Unit-s for the values insets. May * be null, but must be convertible with default * oftypeif specified. * @param errors ErrorEstimate-s for values insets, * may be null * @throws VisADException problem creating VisAD objects. */ public Linear1DSet(MathType type, double first, double last, int length, CoordinateSystem coord_sys, Unit[] units, ErrorEstimate[] errors) throws VisADException { this(type, first, last, length, coord_sys, units, errors, false); } /** * Construct a 1-D arithmetic progression with * the specifiedtype,coord_sys, *unitsanderrors. * @param type MathType for this Linear2DSet. * @param first first value in progression * @param last last value in progression * @param length number of samples in progression (R) * @param coord_sys CoordinateSystem for this set. May be null, but * if not, must be consistent withtype. * @param units Unit-s for the values insets. May * be null, but must be convertible with default * oftypeif specified. * @param errors ErrorEstimate-s for values insets, * may be null * @param cache if true, enumerate and cache the samples. This will * result in a larger memory footprint, but will * reduce the time to return samples from calls to * {@link #getSamples()} * @throws VisADException problem creating VisAD objects. */ public Linear1DSet(MathType type, double first, double last, int length, CoordinateSystem coord_sys, Unit[] units, ErrorEstimate[] errors, boolean cache) throws VisADException { super(type, (float[][]) null, length, coord_sys, units, errors); if (DomainDimension != 1) { throw new SetException("Linear1DSet: DomainDimension must be 1, not " + DomainDimension); } First = first; Last = last; Length = length; if (Length < 1) throw new SetException("Linear1DSet: number of samples (" + Length + " must be greater than 0"); Step = (Length < 2) ? 1.0 : (Last - First) / (Length - 1); Invstep = 1.0 / Step; LowX = (float) Math.min(First, First + Step * (Length - 1)); HiX = (float) Math.max(First, First + Step * (Length - 1)); Low[0] = LowX; Hi[0] = HiX; if (SetErrors[0] != null ) { SetErrors[0] = new ErrorEstimate(SetErrors[0].getErrorValue(), (Low[0] + Hi[0]) / 2.0, Length, SetErrors[0].getUnit()); } cacheSamples = cache; } /** * Convert an array of 1-D indices to an array of values in * the set corresponding to those indices. * @param index array of indices of values in R^1 space. * @return values in R^1 space corresponding to indices. * @throws VisADException problem converting indices to values. */ public float[][] indexToValue(int[] index) throws VisADException { int length = index.length; float[][] values = new float[1][length]; for (int i=0; i1"); } */ int length = grid[0].length; float[][] value = new float[1][length]; float[] value0 = value[0]; float[] grid0 = grid[0]; float l = -0.5f; float h = ((float) Length) - 0.5f; float g; for (int i=0; i 1"); } */ int length = grid[0].length; double[][] value = new double[1][length]; double[] value0 = value[0]; double[] grid0 = grid[0]; double l = -0.5; double h = (Length) - 0.5; double g; for (int i=0; i 1"); } */ int length = value[0].length; float[][] grid = new float[1][length]; float[] grid0 = grid[0]; float[] value0 = value[0]; float l = (float) (First - 0.5 * Step); float h = (float) (First + (((float) Length) - 0.5) * Step); float v; if (h < l) { float temp = l; l = h; h = temp; } for (int i=0; i 1"); } */ int length = value[0].length; double[][] grid = new double[1][length]; double[] grid0 = grid[0]; double[] value0 = value[0]; double l = (First - 0.5 * Step); double h = (First + (((float) Length) - 0.5) * Step); double v; if (h < l) { double temp = l; l = h; h = temp; } for (int i=0; i = 0.0))) { // only interp along ManifoldDimension-1 // if between two valid grid coords length_is *= 2; } base = l[ManifoldDimension-1]; } for (j=ManifoldDimension-2; j>=0 && base>=0; j--) { if (Double.isNaN(grid[j][i])) { base = -1; } else { l[j] = (int) (grid[j][i] + 0.5); if (l[j] == Lengths[j]) l[j]--; // WLH 23 Dec 99 c[j] = grid[j][i] - ((double) l[j]); if (!((l[j] == 0 && c[j] <= 0.0) || (l[j] == Lengths[j] - 1 && c[j] >= 0.0))) { // only interp along dimension j if between two valid grid coords length_is *= 2; } base = l[j] + Lengths[j] * base; } } if (base < 0) { // value is out of grid so return null is = null; cs = null; } else { // create is & cs of proper length, and init first element is = new int[length_is]; cs = new double[length_is]; is[0] = base; cs[0] = 1.0f; lis = 1; for (j=0; j = 0.0))) { // only interp along dimension j if between two valid grid coords if (c[j] >= 0.0) { // grid coord above base isoff = off[j]; a = 1.0f - c[j]; b = c[j]; } else { // grid coord below base isoff = -off[j]; a = 1.0f + c[j]; b = -c[j]; } // double is & cs; adjust new offsets; split weights for (k=0; k set type. * @throws VisADException iftypeis not compatible * with MathType of this. */ public Object cloneButType(MathType type) throws VisADException { return new Linear1DSet(type, First, Last, Length, DomainCoordinateSystem, SetUnits, SetErrors, cacheSamples); } /** * Extended version of the toString() method. * @param pre prefix for string. * @return wordy string describing this Linear1DSet. */ public String longString(String pre) throws VisADException { return pre + "Linear1DSet: Length = " + Length + " Range = " + First + " to " + Last + "\n"; } }
Ads help maintain this website.