/** * Returns the minimum and maximum floating point values in the specified buffer. Values equivalent to the specified * <code>missingDataSignal</code> are ignored. This returns null if the buffer is empty or contains only missing * values. * * @param buffer the buffer to search for the minimum and maximum values. * @param missingDataSignal the number indicating a specific floating point value to ignore. * * @return an array containing the minimum value in index 0 and the maximum value in index 1, or null if the buffer * is empty or contains only missing values. * * @throws ArgumentException if the buffer is null. */ public static double[] computeExtremeValues(BufferWrapper buffer, double missingDataSignal) { if (buffer == null) { String message = Logging.getMessage("nullValue.BufferIsNull"); Logging.logger().severe(message); throw new ArgumentException(message); } double min = Double.MaxValue; double max = -Double.MaxValue; for (int i = 0; i < buffer.length(); i++) { double value = buffer.getDouble(i); if (Double.compare(value, missingDataSignal) == 0) { continue; } if (min > value) { min = value; } if (max < value) { max = value; } } if (Double.compare(min, Double.MaxValue) == 0 || Double.compare(max, -Double.MaxValue) == 0) { return(null); } return(new double[] { min, max }); }
/** * Computes a <code>Box</code> that bounds a specified buffer of points. Principal axes are computed for the points * and used to form a <code>Box</code>. * <p/> * The buffer must contain XYZ coordinate tuples which are either tightly packed or offset by the specified stride. * The stride specifies the number of buffer elements between the first coordinate of consecutive tuples. For * example, a stride of 3 specifies that each tuple is tightly packed as XYZXYZXYZ, whereas a stride of 5 specifies * that there are two elements between each tuple as XYZabXYZab (the elements "a" and "b" are ignored). The stride * must be at least 3. If the buffer's length is not evenly divisible into stride-sized tuples, this ignores the * remaining elements that follow the last complete tuple. * * @param coordinates the buffer containing the point coordinates for which to compute a bounding volume. * @param stride the number of elements between the first coordinate of consecutive points. If stride is 3, * this interprets the buffer has having tightly packed XYZ coordinate tuples. * * @return the bounding volume, with axes lengths consistent with the conventions described in the <code>Box</code> * class overview. * * @throws ArgumentException if the buffer is null or empty, or if the stride is less than three. */ public static Box computeBoundingBox(BufferWrapper coordinates, int stride) { if (coordinates == null) { String msg = Logging.getMessage("nullValue.CoordinatesAreNull"); Logging.logger().severe(msg); throw new ArgumentException(msg); } if (stride < 3) { String msg = Logging.getMessage("generic.StrideIsInvalid", stride); Logging.logger().severe(msg); throw new ArgumentException(msg); } Vec4[] axes = WWMath.computePrincipalAxes(coordinates, stride); if (axes == null) { String msg = Logging.getMessage("generic.ListIsEmpty"); Logging.logger().severe(msg); throw new ArgumentException(msg); } Vec4 r = axes[0]; Vec4 s = axes[1]; Vec4 t = axes[2]; // Find the extremes along each axis. double minDotR = Double.MaxValue; double maxDotR = -minDotR; double minDotS = Double.MaxValue; double maxDotS = -minDotS; double minDotT = Double.MaxValue; double maxDotT = -minDotT; for (int i = 0; i <= coordinates.length() - stride; i += stride) { double x = coordinates.getDouble(i); double y = coordinates.getDouble(i + 1); double z = coordinates.getDouble(i + 2); double pdr = x * r.x() + y * r.y() + z * r.z(); if (pdr < minDotR) { minDotR = pdr; } if (pdr > maxDotR) { maxDotR = pdr; } double pds = x * s.x() + y * s.y() + z * s.z(); if (pds < minDotS) { minDotS = pds; } if (pds > maxDotS) { maxDotS = pds; } double pdt = x * t.x() + y * t.y() + z * t.z(); if (pdt < minDotT) { minDotT = pdt; } if (pdt > maxDotT) { maxDotT = pdt; } } if (maxDotR == minDotR) { maxDotR = minDotR + 1; } if (maxDotS == minDotS) { maxDotS = minDotS + 1; } if (maxDotT == minDotT) { maxDotT = minDotT + 1; } return(new Box(axes, minDotR, maxDotR, minDotS, maxDotS, minDotT, maxDotT)); }
public Object get(BufferWrapper bufferWrapper, int index) { return(bufferWrapper.getDouble(index)); }
public bool hasValue(BufferWrapper bufferWrapper, int index) { // Scalar doubles are null when equal to the 64 bit floating point NaN. return(!isNoValueDouble(bufferWrapper.getDouble(index))); }
public bool hasValue(BufferWrapper bufferWrapper, int index) { // Scalar floats are null when equal to the 32 bit floating point NaN. return(!isNoValueFloat((float)bufferWrapper.getDouble(index))); }