Exemplo n.º 1
0
  /**
   * 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>. This returns <code>null</code> if
   * the buffer is empty or contains only a partial point.
   *
   * <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 buffer 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 IllegalArgumentException if the buffer is null or empty, or if the stride is less than
   *     three.
   */
  public static Box computeBoundingBox(FloatBuffer buffer, int stride) {
    if (buffer == null) {
      String msg = Logging.getMessage("nullValue.BufferIsNull");
      Logging.error(msg);
      throw new IllegalArgumentException(msg);
    }

    if (stride < 3) {
      String msg = Logging.getMessage("generic.StrideIsInvalid", stride);
      Logging.error(msg);
      throw new IllegalArgumentException(msg);
    }

    Vec4[] axes = WWMath.computePrincipalAxes(buffer, stride);
    if (axes == null) {
      String msg = Logging.getMessage("generic.BufferIsEmpty");
      Logging.error(msg);
      throw new IllegalArgumentException(msg);
    }

    Vec4 r = axes[0];
    Vec4 s = axes[1];
    Vec4 t = axes[2];

    // Find the extremes along each axis.
    double minDotR = Double.MAX_VALUE;
    double maxDotR = -minDotR;
    double minDotS = Double.MAX_VALUE;
    double maxDotS = -minDotS;
    double minDotT = Double.MAX_VALUE;
    double maxDotT = -minDotT;

    for (int i = buffer.position(); i <= buffer.limit() - stride; i += stride) {
      double x = buffer.get(i);
      double y = buffer.get(i + 1);
      double z = buffer.get(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);
  }
Exemplo n.º 2
0
  /**
   * Compute a <code>Box</code> that bounds a specified list of points. Principal axes are computed
   * for the points and used to form a <code>Box</code>.
   *
   * @param points the points for which to compute a bounding volume.
   * @return the bounding volume, with axes lengths consistent with the conventions described in the
   *     overview.
   * @throws IllegalArgumentException if the point list is null or empty.
   */
  public static Box computeBoundingBox(Iterable<? extends Vec4> points) {
    if (points == null) {
      String msg = Logging.getMessage("nullValue.PointListIsNull");
      Logging.error(msg);
      throw new IllegalArgumentException(msg);
    }

    Vec4[] axes = WWMath.computePrincipalAxes(points);
    if (axes == null) {
      String msg = Logging.getMessage("generic.PointListIsEmpty");
      Logging.error(msg);
      throw new IllegalArgumentException(msg);
    }

    Vec4 r = axes[0];
    Vec4 s = axes[1];
    Vec4 t = axes[2];

    // Find the extremes along each axis.
    double minDotR = Double.MAX_VALUE;
    double maxDotR = -minDotR;
    double minDotS = Double.MAX_VALUE;
    double maxDotS = -minDotS;
    double minDotT = Double.MAX_VALUE;
    double maxDotT = -minDotT;

    for (Vec4 p : points) {
      if (p == null) continue;

      double pdr = p.dot3(r);
      if (pdr < minDotR) minDotR = pdr;
      if (pdr > maxDotR) maxDotR = pdr;

      double pds = p.dot3(s);
      if (pds < minDotS) minDotS = pds;
      if (pds > maxDotS) maxDotS = pds;

      double pdt = p.dot3(t);
      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);
  }
Exemplo n.º 3
0
  /**
   * Construct a unit-length cube centered at a specified point.
   *
   * @param point the center of the cube.
   * @throws IllegalArgumentException if the point is null.
   */
  public Box(Vec4 point) {
    if (point == null) {
      String msg = Logging.getMessage("nullValue.PointIsNull");
      Logging.error(msg);
      throw new IllegalArgumentException(msg);
    }

    this.ru = new Vec4(1, 0, 0, 1);
    this.su = new Vec4(0, 1, 0, 1);
    this.tu = new Vec4(0, 0, 1, 1);

    this.r = this.ru;
    this.s = this.su;
    this.t = this.tu;

    this.rLength = 1;
    this.sLength = 1;
    this.tLength = 1;

    // Plane normals point outwards from the box.
    this.planes = new Plane[6];
    double d = 0.5 * point.getLength3();
    this.planes[0] = new Plane(-this.ru.x, -this.ru.y, -this.ru.z, -(d + 0.5));
    this.planes[1] = new Plane(+this.ru.x, +this.ru.y, +this.ru.z, -(d + 0.5));
    this.planes[2] = new Plane(-this.su.x, -this.su.y, -this.su.z, -(d + 0.5));
    this.planes[3] = new Plane(+this.su.x, +this.su.y, +this.su.z, -(d + 0.5));
    this.planes[4] = new Plane(-this.tu.x, -this.tu.y, -this.tu.z, -(d + 0.5));
    this.planes[5] = new Plane(+this.tu.x, +this.tu.y, +this.tu.z, -(d + 0.5));

    this.center = ru.add3(su).add3(tu).multiply3(0.5);

    Vec4 rHalf = r.multiply3(0.5);
    this.topCenter = this.center.add3(rHalf);
    this.bottomCenter = this.center.subtract3(rHalf);
  }
  public synchronized void logUnavailableHost(URL url) {
    if (this.offlineMode) return;

    if (url == null) {
      String message = Logging.getMessage("nullValue.URLIsNull");
      Logging.error(message);
      throw new IllegalArgumentException(message);
    }

    String hostName = url.getHost();
    HostInfo hi = this.hostMap.get(hostName);
    if (hi != null) {
      if (!hi.isUnavailable()) {
        hi.logCount.incrementAndGet();
        if (hi.isUnavailable()) // host just became unavailable
        this.firePropertyChange(NetworkStatus.HOST_UNAVAILABLE, null, url);
      }
      hi.lastLogTime.set(System.currentTimeMillis());
    } else {
      hi = new HostInfo(this.attemptLimit.get(), this.tryAgainInterval.get());
      hi.logCount.set(1);
      if (hi.isUnavailable()) // the attempt limit may be as low as 1, so handle that case here
      this.firePropertyChange(NetworkStatus.HOST_UNAVAILABLE, null, url);
      this.hostMap.put(hostName, hi);
    }

    this.lastUnavailableLogTime.set(System.currentTimeMillis());
  }
 public Client getClient() {
   try {
     return ClientCatalog.getClient(indexName);
   } catch (SearchLibException e) {
     Logging.error(e);
     return null;
   }
 }
  public void setTryAgainInterval(long interval) {
    if (interval < 0) {
      String message = Logging.getMessage("NetworkStatus.InvalidTryAgainInterval");
      Logging.error(message);
      throw new IllegalArgumentException(message);
    }

    this.tryAgainInterval.set(interval);
  }
  public void setAttemptLimit(int limit) {
    if (limit < 1) {
      String message = Logging.getMessage("NetworkStatus.InvalidAttemptLimit");
      Logging.error(message);
      throw new IllegalArgumentException(message);
    }

    this.attemptLimit.set(limit);
  }
Exemplo n.º 8
0
  /** {@inheritDoc} */
  public double distanceTo(Vec4 point) {
    if (point == null) {
      String msg = Logging.getMessage("nullValue.PointIsNull");
      Logging.error(msg);
      throw new IllegalArgumentException(msg);
    }

    double distance = point.distanceTo3(this.center) - this.getRadius();
    return (distance < 0d) ? 0d : distance;
  }
Exemplo n.º 9
0
 public static final void openAll() {
   try {
     synchronized (ClientCatalog.class) {
       for (ClientCatalogItem catalogItem : getClientCatalog(null)) {
         Logging.info("OSS loads index " + catalogItem.getIndexName());
         getClient(catalogItem.getIndexName());
       }
     }
   } catch (SearchLibException e) {
     Logging.error(e);
   }
 }
  public PerformanceStatistic(String key, String displayName, Object value) {
    if (key == null) {
      String msg = Logging.getMessage("nullValue.KeyIsNull");
      Logging.error(msg);
      throw new IllegalArgumentException(msg);
    }

    if (displayName == null) {
      String msg = Logging.getMessage("nullValue.NameIsNull");
      Logging.error(msg);
      throw new IllegalArgumentException(msg);
    }

    if (value == null) {
      String msg = Logging.getMessage("nullValue.ValueIsNull");
      Logging.error(msg);
      throw new IllegalArgumentException(msg);
    }

    this.key = key;
    this.displayName = displayName;
    this.value = value;
  }
  public synchronized void logAvailableHost(URL url) {
    if (this.offlineMode) return;

    if (url == null) {
      String message = Logging.getMessage("nullValue.URLIsNull");
      Logging.error(message);
      throw new IllegalArgumentException(message);
    }

    String hostName = url.getHost();
    HostInfo hi = this.hostMap.get(hostName);
    if (hi != null) {
      this.hostMap.remove(hostName); // host is available again
      firePropertyChange(NetworkStatus.HOST_AVAILABLE, null, url);
    }

    this.lastAvailableLogTime.set(System.currentTimeMillis());
  }
Exemplo n.º 12
0
  public Box translate(Vec4 point) {
    if (point == null) {
      String msg = Logging.getMessage("nullValue.PointIsNull");
      Logging.error(msg);
      throw new IllegalArgumentException(msg);
    }

    this.bottomCenter.add3AndSet(point);
    this.topCenter.add3AndSet(point);
    this.center.add3AndSet(point);

    for (int i = 0; i < this.planes.length; i++) {
      Vec4 n = this.planes[i].getNormal();
      double d = this.planes[i].getDistance();
      this.planes[i].set(n.x, n.y, n.z, d - n.dot3(point));
    }

    return this;
  }
  public boolean isHostUnavailable(URL url) {
    if (this.offlineMode) return true;

    if (url == null) {
      String message = Logging.getMessage("nullValue.URLIsNull");
      Logging.error(message);
      throw new IllegalArgumentException(message);
    }

    String hostName = url.getHost();
    HostInfo hi = this.hostMap.get(hostName);
    if (hi == null) return false;

    if (hi.isTimeToTryAgain()) {
      hi.logCount.set(0); // info removed from table in logAvailableHost
      return false;
    }

    return hi.isUnavailable();
  }
Exemplo n.º 14
0
  /** {@inheritDoc} */
  public boolean intersects(Frustum frustum) {
    if (frustum == null) {
      String msg = Logging.getMessage("nullValue.FrustumIsNull");
      Logging.error(msg);
      throw new IllegalArgumentException(msg);
    }

    // FYI: this code is identical to that in Cylinder.intersects.

    double intersectionPoint;

    this.tmp1.set(this.bottomCenter);
    this.tmp2.set(this.topCenter);

    double effectiveRadius = this.getEffectiveRadius(frustum.getNear());
    intersectionPoint = this.intersectsAt(frustum.getNear(), effectiveRadius, this.tmp1, this.tmp2);
    if (intersectionPoint < 0) return false;

    // Near and far have the same effective radius.
    effectiveRadius = this.getEffectiveRadius(frustum.getFar());
    intersectionPoint = this.intersectsAt(frustum.getFar(), effectiveRadius, this.tmp1, this.tmp2);
    if (intersectionPoint < 0) return false;

    effectiveRadius = this.getEffectiveRadius(frustum.getLeft());
    intersectionPoint = this.intersectsAt(frustum.getLeft(), effectiveRadius, this.tmp1, this.tmp2);
    if (intersectionPoint < 0) return false;

    effectiveRadius = this.getEffectiveRadius(frustum.getRight());
    intersectionPoint =
        this.intersectsAt(frustum.getRight(), effectiveRadius, this.tmp1, this.tmp2);
    if (intersectionPoint < 0) return false;

    effectiveRadius = this.getEffectiveRadius(frustum.getTop());
    intersectionPoint = this.intersectsAt(frustum.getTop(), effectiveRadius, this.tmp1, this.tmp2);
    if (intersectionPoint < 0) return false;

    effectiveRadius = this.getEffectiveRadius(frustum.getBottom());
    intersectionPoint =
        this.intersectsAt(frustum.getBottom(), effectiveRadius, this.tmp1, this.tmp2);
    return intersectionPoint >= 0;
  }
Exemplo n.º 15
0
  /**
   * Construct a box from three specified unit axes and the locations of the box faces relative to
   * those axes. The box faces are specified by two scalar locations along each axis, each location
   * indicating a face. The non-unit length of an axis is the distance between its respective two
   * locations. The longest side is specified first, followed by the second longest side and then
   * the shortest side.
   *
   * <p>The axes are normally principal axes computed from a collection of points in order to form
   * an oriented bounding volume. See {@link WWMath#computePrincipalAxes(Iterable)}.
   *
   * <p>Note: No check is made to ensure the order of the face locations.
   *
   * @param axes the unit-length axes.
   * @param rMin the location along the first axis corresponding to the left-most box side relative
   *     to the axis.
   * @param rMax the location along the first axis corresponding to the right-most box side relative
   *     to the axis.
   * @param sMin the location along the second axis corresponding to the left-most box side relative
   *     to the axis.
   * @param sMax the location along the second axis corresponding to the right-most box side
   *     relative to the axis.
   * @param tMin the location along the third axis corresponding to the left-most box side relative
   *     to the axis.
   * @param tMax the location along the third axis corresponding to the right-most box side relative
   *     to the axis.
   * @throws IllegalArgumentException if the axes array or one of its entries is null.
   */
  public Box(
      Vec4 axes[], double rMin, double rMax, double sMin, double sMax, double tMin, double tMax) {
    if (axes == null || axes[0] == null || axes[1] == null || axes[2] == null) {
      String msg = Logging.getMessage("nullValue.AxesIsNull");
      Logging.error(msg);
      throw new IllegalArgumentException(msg);
    }

    this.ru = axes[0];
    this.su = axes[1];
    this.tu = axes[2];

    this.r = this.ru.multiply3(rMax - rMin);
    this.s = this.su.multiply3(sMax - sMin);
    this.t = this.tu.multiply3(tMax - tMin);

    this.rLength = this.r.getLength3();
    this.sLength = this.s.getLength3();
    this.tLength = this.t.getLength3();

    // Plane normals point outward from the box.
    this.planes = new Plane[6];
    this.planes[0] = new Plane(-this.ru.x, -this.ru.y, -this.ru.z, +rMin);
    this.planes[1] = new Plane(+this.ru.x, +this.ru.y, +this.ru.z, -rMax);
    this.planes[2] = new Plane(-this.su.x, -this.su.y, -this.su.z, +sMin);
    this.planes[3] = new Plane(+this.su.x, +this.su.y, +this.su.z, -sMax);
    this.planes[4] = new Plane(-this.tu.x, -this.tu.y, -this.tu.z, +tMin);
    this.planes[5] = new Plane(+this.tu.x, +this.tu.y, +this.tu.z, -tMax);

    double a = 0.5 * (rMin + rMax);
    double b = 0.5 * (sMin + sMax);
    double c = 0.5 * (tMin + tMax);
    this.center = ru.multiply3(a).add3(su.multiply3(b)).add3(tu.multiply3(c));

    Vec4 rHalf = r.multiply3(0.5);
    this.topCenter = this.center.add3(rHalf);
    this.bottomCenter = this.center.subtract3(rHalf);
  }