public void setBands(Band[] bands) { Debug.assertNotNull(bands); this.bands = bands.clone(); Arrays.sort(this.bands, new Comparator<Band>() { @Override public int compare(Band band1, Band band2) { final float v = band1.getSpectralWavelength() - band2.getSpectralWavelength(); return v < 0.0F ? -1 : v > 0.0F ? 1 : 0; } }); if (wavelengths == null || wavelengths.length != this.bands.length) { wavelengths = new double[this.bands.length]; } if (energies == null || energies.length != this.bands.length) { energies = new double[this.bands.length]; } for (int i = 0; i < wavelengths.length; i++) { wavelengths[i] = this.bands[i].getSpectralWavelength(); energies[i] = 0.0f; } Range.computeRangeDouble(wavelengths, IndexValidator.TRUE, wavelengthRange, ProgressMonitor.NULL); Range.computeRangeDouble(energies, IndexValidator.TRUE, energyRange, ProgressMonitor.NULL); }
/** * Computes the value range for the values in the given <code>int</code> array. The array elements are interpreted * as <i>unsigned</i> int values. Values at a given index <code>i</code> for which * <code>validator.validate(i)</code> returns <code>false</code> are excluded from the computation. * * @param values the array whose value range to compute * @param validator used to validate the array indexes, must not be <code>null</code>. Use {@link * IndexValidator#TRUE} instead. * @param range if not <code>null</code>, used as return value, otherwise a new instance is created * @param pm a monitor to inform the user about progress * * @return the value range for the given array */ public static Range computeRangeUInt(final int[] values, final IndexValidator validator, Range range, ProgressMonitor pm) { Guardian.assertNotNull("validator", validator); return computeRangeDouble(new DoubleList.UInt(values), validator, range, pm); }
/** * Computes the value range for the values in the given <code>short</code> array. The array elements are interpreted * as <i>unsigned</i> short values. Values at a given index <code>i</code> for which * <code>validator.validate(i)</code> returns <code>false</code> are excluded from the computation. * * @param values the array whose value range to compute * @param validator used to validate the array indexes, must not be <code>null</code>. Use {@link * IndexValidator#TRUE} instead. * @param range if not <code>null</code>, used as return value, otherwise a new instance is created * * @return the value range for the given array */ public static Range computeRangeUShort(final short[] values, final IndexValidator validator, Range range, ProgressMonitor pm) { Guardian.assertNotNull("validator", validator); return computeRangeDouble(new DoubleList.UShort(values), validator, range, pm); }
/** * Computes the value range for the values in the given <code>byte</code> array. The array elements are interpreted * as <i>unsigned</i> byte values. Values at a given index <code>i</code> for which * <code>validator.validate(i)</code> returns <code>false</code> are excluded from the computation. * * @param values the array whose value range to compute * @param validator used to validate the array indexes, must not be <code>null</code>. Use {@link * IndexValidator#TRUE} instead. * @param range if not <code>null</code>, used as return value, otherwise a new instance is created * @param pm a monitor to inform the user about progress * * @return the value range for the given array */ public static Range computeRangeUByte(final byte[] values, final IndexValidator validator, Range range, ProgressMonitor pm) { Guardian.assertNotNull("validator", validator); return computeRangeDouble(new DoubleList.UByte(values), validator, range, pm); }
/** * Computes the value range for the values in the given <code>int</code> array. The array elements are interpreted * as <i>signed</i> int values. Values at a given index <code>i</code> for which <code>validator.validate(i)</code> * returns <code>false</code> are excluded from the computation. * * @param values the array whose value range to compute * @param validator used to validate the array indexes, must not be <code>null</code>. Use {@link * IndexValidator#TRUE} instead. * @param range if not <code>null</code>, used as return value, otherwise a new instance is created * @param pm a monitor to inform the user about progress * * @return the value range for the given array */ public static Range computeRangeInt(final int[] values, final IndexValidator validator, Range range, ProgressMonitor pm) { Guardian.assertNotNull("validator", validator); return computeRangeDouble(new DoubleList.Int(values), validator, range, pm); }
/** * Computes the value range for the values in the given <code>float</code> array. Values at a given index * <code>i</code> for which <code>validator.validate(i)</code> returns <code>false</code> are excluded from the * computation. * * @param values the array whose value range to compute * @param validator used to validate the array indexes, must not be <code>null</code>. Use {@link * IndexValidator#TRUE} instead. * @param range if not <code>null</code>, used as return value, otherwise a new instance is created * @param pm a monitor to inform the user about progress * * @return the value range for the given array */ public static Range computeRangeFloat(final float[] values, final IndexValidator validator, Range range, ProgressMonitor pm) { Guardian.assertNotNull("validator", validator); return computeRangeDouble(new DoubleList.Float(values), validator, range, pm); }
/** * Computes the value range for the values in the given <code>double</code> array. Values at a given index * <code>i</code> for which <code>validator.validate(i)</code> returns <code>false</code> are excluded from the * computation. * * @param values the array whose value range to compute * @param validator used to validate the array indexes, must not be <code>null</code>. Use {@link * IndexValidator#TRUE} instead. * @param range if not <code>null</code>, used as return value, otherwise a new instance is created * @param pm a monitor to inform the user about progress * * @return the value range for the given array */ public static Range computeRangeDouble(final double[] values, final IndexValidator validator, Range range, ProgressMonitor pm) { Guardian.assertNotNull("validator", validator); return computeRangeDouble(new DoubleList.Double(values), validator, range, pm); }
/** * Computes the value range for the values in the given <code>byte</code> array. The array elements are interpreted * as <i>signed</i> byte values. Values at a given index <code>i</code> for which <code>validator.validate(i)</code> * returns <code>false</code> are excluded from the computation. * * @param values the array whose value range to compute * @param validator used to validate the array indexes, must not be <code>null</code>. Use {@link * IndexValidator#TRUE} instead. * @param range if not <code>null</code>, used as return value, otherwise a new instance is created * @param pm a monitor to inform the user about progress * * @return the value range for the given array */ public static Range computeRangeByte(final byte[] values, final IndexValidator validator, Range range, ProgressMonitor pm) { Guardian.assertNotNull("validator", validator); return computeRangeDouble(new DoubleList.Byte(values), validator, range, pm); }
/** * Computes the value range for the values in the given <code>short</code> array. The array elements are interpreted * as <i>signed</i> short values. Values at a given index <code>i</code> for which * <code>validator.validate(i)</code> returns <code>false</code> are excluded from the computation. * * @param values the array whose value range to compute * @param validator used to validate the array indexes, must not be <code>null</code>. Use {@link * IndexValidator#TRUE} instead. * @param range if not <code>null</code>, used as return value, otherwise a new instance is created * @param pm a monitor to inform the user about progress * * @return the value range for the given array */ public static Range computeRangeShort(final short[] values, final IndexValidator validator, Range range, ProgressMonitor pm) { Guardian.assertNotNull("validator", validator); return computeRangeDouble(new DoubleList.Short(values), validator, range, pm); }
public void readValues() { Debug.assertNotNull(bands); for (int i = 0; i < bands.length; i++) { final Band band = bands[i]; if (placemark != null) { // position of placemark is given in image (L0) coordinates // we have to transform them to the current level final MultiLevelModel multiLevelModel = ImageManager.getMultiLevelModel(band); final AffineTransform i2mTransform = multiLevelModel.getImageToModelTransform(0); final AffineTransform m2iTransform = multiLevelModel.getModelToImageTransform(0); final Point2D modelPixel = i2mTransform.transform(placemark.getPixelPos(), null); final Point2D imagePixel = m2iTransform.transform(modelPixel, null); int pixelX = (int) Math.floor(imagePixel.getX()); int pixelY = (int) Math.floor(imagePixel.getY()); energies[i] = getSample(band, pixelX, pixelY, 0); } } IndexValidator validator = new IndexValidator() { @Override public boolean validateIndex(int index) { return energies[index] != bands[index].getGeophysicalNoDataValue(); } }; Range.computeRangeDouble(energies, validator, energyRange, ProgressMonitor.NULL); // no invalidate() call here, SpectrumDiagram does this }
public void setXYValues(double[] xValues, double[] yValues) { Assert.notNull(xValues, "xValues"); Assert.notNull(yValues, "yValues"); Assert.argument(xValues.length > 1, "xValues.length > 1"); Assert.argument(xValues.length == yValues.length, "xValues.length == yValues.length"); if (!ObjectUtils.equalObjects(this.xValues, xValues) || !ObjectUtils.equalObjects(this.yValues, yValues)) { this.xValues = xValues; this.yValues = yValues; this.xRange = Range.computeRangeDouble(xValues, IndexValidator.TRUE, null, ProgressMonitor.NULL); this.yRange = Range.computeRangeDouble(yValues, IndexValidator.TRUE, null, ProgressMonitor.NULL); invalidate(); } }
result = computeRangeFloat((float[]) values, validator, range, pm); } else if (values instanceof double[]) { result = computeRangeDouble((double[]) values, validator, range, pm); } else if (values instanceof DoubleList) { result = computeRangeDouble((DoubleList) values, validator, range, pm); } else if (values == null) { throw new IllegalArgumentException("values is null");
public void testComputeRangeDouble() { double[] doubles = new double[]{2, -3, 4, 5, -6, 7, 8, 9}; Range range = new Range(); Range.computeRangeDouble(doubles, IndexValidator.TRUE, range, ProgressMonitor.NULL); assertEquals(-6, range.getMin(), 1e-10d); assertEquals(9, range.getMax(), 1e-10d); Range.computeRangeDouble(doubles, _validator, range, ProgressMonitor.NULL); assertEquals(-6, range.getMin(), 1e-10d); assertEquals(7, range.getMax(), 1e-10d); }
public void testComputeRangeDoubleArray() { final DoubleList array = TestHelper.createArray(new int[]{2, -3, 4, 5, -6, 7, 8, 9}); Range range = new Range(); Range.computeRangeDouble(array, IndexValidator.TRUE, range, ProgressMonitor.NULL); assertEquals(-6, range.getMin(), 1e-10d); assertEquals(9, range.getMax(), 1e-10d); Range.computeRangeDouble(array, _validator, range, ProgressMonitor.NULL); assertEquals(-6, range.getMin(), 1e-10d); assertEquals(7, range.getMax(), 1e-10d); }