/** * Returns a new empty bounding box. * @return a new empty bounding box. */ public static BoundingBox empty() { return new BoundingBox(); }
/** * Gets the bounding box for this node. * @return the bounding box. */ public BoundingBox getBoundingBox() { return new BoundingBox(_bb); }
/** * Gets the bounding box for this constraint. * @return the bounding box. */ public BoundingBox getBoundingBox() { return new BoundingBox(_xmin,_ymin,_zmin,_xmax,_ymax,_zmax); }
/** * Returns a new infinite bounding box. * @return a new infinite bounding box. */ public static BoundingBox infinite() { BoundingBox bb = new BoundingBox(); bb.setInfinite(); return bb; }
/** * Sets the bounding sphere of the frame. * @param xmin the minimum x coordinate. * @param ymin the minimum y coordinate. * @param zmin the minimum z coordinate. * @param xmax the maximum x coordinate. * @param ymax the maximum y coordinate. * @param zmax the maximum z coordinate. */ public void setWorldSphere( double xmin, double ymin, double zmin, double xmax, double ymax, double zmax) { setWorldSphere( new BoundingSphere( new BoundingBox(xmin,ymin,zmin,xmax,ymax,zmax))); }
public LineNode(float[] xyz, float[] rgb) { BoundingBox bb = new BoundingBox(xyz); _bs = new BoundingSphere(bb); _np = xyz.length/3; int np = _np; int nv = np; int nc = np; _vb = Direct.newFloatBuffer(3*nv); _cb = (rgb!=null)?Direct.newFloatBuffer(3*nc):null; for (int ip=0,iv=0,ic=0; ip<np; ++ip) { int i = 3*ip; _vb.put(iv++,xyz[i+X]); _vb.put(iv++,xyz[i+Y]); _vb.put(iv++,xyz[i+Z]); if (_cb!=null) { _cb.put(ic++,rgb[i+R]); _cb.put(ic++,rgb[i+G]); _cb.put(ic++,rgb[i+B]); } } }
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);
/** * Constructs a bounding box tree 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 minSize the minimum number of points in a child node. * @param xyz array of packed (x,y,z) coordinates. */ public BoundingBoxTree(int minSize, float[] xyz) { Check.argument(minSize>0,"minSize>0"); _n = xyz.length/3; _i = rampint(0,1,_n); _x = copy(_n,0,3,xyz); _y = copy(_n,1,3,xyz); _z = copy(_n,2,3,xyz); _root = new Node(); _root._bb = new BoundingBox(_x,_y,_z); _root._kmin = 0; _root._kmax = _n-1; split(minSize,_root); _x = _y = _z = null; }
/** * 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; } }
/** * Constructs a bounding box tree for points with specified coordinates. * @param minSize the minimum number of points in a child node. * @param x array of x coordinates. * @param y array of y coordinates. * @param z array of z coordinates. */ public BoundingBoxTree(int minSize, float[] x, float[] y, float[] z) { Check.argument(minSize>0,"minSize>0"); Check.argument(x.length==y.length,"x.length==y.length"); Check.argument(x.length==z.length,"x.length==z.length"); _n = x.length; _i = rampint(0,1,_n); _x = copy(x); _y = copy(y); _z = copy(z); _root = new Node(); _root._bb = new BoundingBox(_x,_y,_z); _root._kmin = 0; _root._kmax = _n-1; split(minSize,_root); _x = _y = _z = null; }
_bs = new BoundingSphere(new BoundingBox(0,0,0,1,1,1));
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 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)); } } } }
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))); }