/** * Returns a new empty bounding box. * @return a new empty bounding box. */ public static BoundingBox empty() { return new BoundingBox(); }
/** * Determines whether this box contains the specified bounding box. * @param bb the bounding box. * @return true, if this box contains the specified box; false, otherwise. */ public boolean contains(BoundingBox bb) { return contains(bb._xmin,bb._ymin,bb._zmin) && contains(bb._xmax,bb._ymax,bb._zmax); }
/** * Constructs a bounding box for points with specified coordinates. * @param x array of x coordinates. * @param y array of y coordinates. * @param z array of z coordinates. */ public BoundingBox(float[] x, float[] y, float[] z) { this(); expandBy(x,y,z); }
/** * Returns a new infinite bounding box. * @return a new infinite bounding box. */ public static BoundingBox infinite() { BoundingBox bb = new BoundingBox(); bb.setInfinite(); return bb; }
/** * Computes the bounding sphere for this group, including its children. * @param finite true, to force bounding sphere to be finite. * @return the computed bounding sphere. */ protected BoundingSphere computeBoundingSphere(boolean finite) { if (countChildren()==1) { return _childList.get(0).getBoundingSphere(finite); } else { BoundingBox bb = new BoundingBox(); for (Node child : _childList) bb.expandBy(child.getBoundingSphere(finite)); if (bb.isEmpty()) return BoundingSphere.empty(); if (bb.isInfinite()) // should not happen if finite == true return BoundingSphere.infinite(); BoundingSphere bs = new BoundingSphere(bb.getCenter(),0.0); for (Node child : _childList) bs.expandRadiusBy(child.getBoundingSphere(finite)); return bs; } }
public void testBoxExpand() { int ntrial = 100; for (int itrial=0; itrial<ntrial; ++itrial) { BoundingBox bb = new BoundingBox(); assertTrue(bb.isEmpty()); int nexpand = 100; for (int iexpand=0; iexpand<nexpand; ++iexpand) { Point3 c = randomPoint3(); double r = randomDouble(); BoundingSphere bs = new BoundingSphere(c,r); bb.expandBy(bs); assertTrue(!bb.isEmpty()); int npoint=100; for (int ipoint=0; ipoint<npoint; ++ipoint) { Point3 p = randomPoint3(); if (bs.contains(p)) assertTrue(bb.contains(p)); } } } }
public void testBox() { BoundingBox bb = new BoundingBox(); bb.expandBy(0,0,0); bb.expandBy(1,1,1); double a = 10.0*DBL_EPSILON; double b = 1.0-a; assertTrue(bb.contains(new Point3(a,a,a))); assertTrue(bb.contains(new Point3(a,a,b))); assertTrue(bb.contains(new Point3(a,b,a))); assertTrue(bb.contains(new Point3(a,b,b))); assertTrue(bb.contains(new Point3(b,a,a))); assertTrue(bb.contains(new Point3(b,a,b))); assertTrue(bb.contains(new Point3(b,b,a))); assertTrue(bb.contains(new Point3(b,b,b))); a = -10.0*DBL_EPSILON; b = 1.0-a; assertTrue(!bb.contains(new Point3(a,a,a))); assertTrue(!bb.contains(new Point3(a,a,b))); assertTrue(!bb.contains(new Point3(a,b,a))); assertTrue(!bb.contains(new Point3(a,b,b))); assertTrue(!bb.contains(new Point3(b,a,a))); assertTrue(!bb.contains(new Point3(b,a,b))); assertTrue(!bb.contains(new Point3(b,b,a))); assertTrue(!bb.contains(new Point3(b,b,b))); }
if (!bb.isInfinite()) { if (!bb.isEmpty()) { Point3 pmin = bb.getMin(); Point3 pmax = bb.getMax(); double xmin = pmin.x; double ymin = pmin.y;
Point3 min = bb.getMin(); Point3 max = bb.getMax(); double xdif = max.x-min.x; double ydif = max.y-min.y; if (adif==xdif) { float spltx = _x[_i[kmid]]; left._bb = new BoundingBox(min.x,min.y,min.z, spltx,max.y,max.z); right._bb = new BoundingBox(spltx,min.y,min.z, max.x,max.y,max.z); } else if (adif==ydif) { float splty = _y[_i[kmid]]; left._bb = new BoundingBox(min.x,min.y,min.z, max.x,splty,max.z); right._bb = new BoundingBox(min.x,splty,min.z, max.x,max.y,max.z); } else { float spltz = _z[_i[kmid]]; left._bb = new BoundingBox(min.x,min.y,min.z, max.x,max.y,spltz); right._bb = new BoundingBox(min.x,min.y,spltz, max.x,max.y,max.z);
public void testSphereExpand() { int ntrial = 100; for (int itrial=0; itrial<ntrial; ++itrial) { BoundingSphere bs = new BoundingSphere(); assertTrue(bs.isEmpty()); int nexpand = 100; for (int iexpand=0; iexpand<nexpand; ++iexpand) { Point3 p = randomPoint3(); Point3 q = randomPoint3(); BoundingBox bb = new BoundingBox(p,q); if (randomDouble()>0.5) { bs.expandBy(bb); } else { bs.expandRadiusBy(bb); } assertTrue(!bs.isEmpty()); int npoint=100; for (int ipoint=0; ipoint<npoint; ++ipoint) { Point3 r = randomPoint3(); if (bb.contains(r)) assertTrue(bs.contains(r)); } } } }
/** * Gets the box radius-squared. * @return the box radius-squared. */ public double getRadiusSquared() { Check.state(!isEmpty(),"bounding box is not empty"); double dx = _xmax-_xmin; double dy = _ymax-_ymin; double dz = _zmax-_zmin; return 0.25*(dx*dx+dy*dy+dz*dz); }
/** * Gets the point at the center of this box. * @return the box center. */ public Point3 getCenter() { Check.state(!isEmpty(),"bounding box is not empty"); Check.state(!isInfinite(),"bounding box is not infinite"); return (isInfinite()) ? new Point3(0.0,0.0,0.0) : new Point3(0.5*(_xmin+_xmax),0.5*(_ymin+_ymax),0.5*(_zmin+_zmax)); }
/** * Gets the box radius, the distance from the center to any corner. * @return the box radius. */ public double getRadius() { return sqrt(getRadiusSquared()); }
if (!bb.isInfinite()) { if (!bb.isEmpty()) { Point3 pmin = bb.getMin(); Point3 pmax = bb.getMax(); double xmin = pmin.x; double ymin = pmin.y;
/** * Gets the point in this box with maximum coordinates. * @return the maximim point. */ public Point3 getMax() { Check.state(!isEmpty(),"bounding box is not empty"); return new Point3(_xmax,_ymax,_zmax); }
/** * Constructs a box constraint with specified bounding box and min sizes. * Constrains objects to lie inside the bounding box. * @param box bounding box. * @param dxmin minimum size in x dimension. * @param dymin minimum size in y dimension. * @param dzmin minimum size in z dimension. */ public BoxConstraint(BoundingBox box, double dxmin, double dymin, double dzmin) { this(box.getMin(),box.getMax(),dxmin,dymin,dzmin); }
/** * Gets the bounding box for this node. * @return the bounding box. */ public BoundingBox getBoundingBox() { return new BoundingBox(_bb); }
/** * Constructs a bounding box for points with specified coordinates. * The (x,y,z) coordinates are packed into the specified array such * that (xyz[0],xyz[1],xyz[2]) are the (x,y,z) coordinates of the * 1st point, (xyz[3],xyz[4],xyz[5]) are the (x,y,z) coordinates of * the 2nd point, and so on. * @param xyz array of packed (x,y,z) coordinates. */ public BoundingBox(float[] xyz) { this(); expandBy(xyz); }
/** * Gets the point in this box with minimum coordinates. * @return the minimim point. */ public Point3 getMin() { Check.state(!isEmpty(),"bounding box is not empty"); return new Point3(_xmin,_ymin,_zmin); }