/** * Recursively builds a binary tree with leaf quad nodes. */ private void buildTree(int[] ijkl, float[] xyz, float[] uvw, float[] rgb) { float[] c = computeCenters(ijkl,xyz); BoundingBoxTree bbt = new BoundingBoxTree(MIN_QUAD_PER_NODE,c); buildTree(this,bbt.getRoot(),ijkl,xyz,uvw,rgb); } private void buildTree(Group parent, BoundingBoxTree.Node bbtNode,
/** * Constructs a quad group with specified vertex coordinates * and optional corresponding normal vectors and colors. * <p> * Quads are specified by sets of four vertex indices (i,j,k), * one set per quad, packed into the specified array of integers * ijkl. The number of quads is nq = ijkl.length/4. * <p> * The (x,y,z) coordinates of vertices are packed into the specified * array xyz. The number of vertices is nv = xyz.length/3. * <p> * The (u,v,w) components of normal vectors are packed into the specified * array uvw. If not null, the number of normal vectors equals the number * of vertices. * <p> * The (r,g,b) components of colors are packed into the specified array * rgb. If not null, the number of colors equals the number of vertices. * @param ijkl array[4*nq] of packed vertex indices. * @param xyz array[3*nv] of packed vertex coordinates. * @param uvw array[3*nv] of packed normal vector components. * @param rgb array[3*nv] of packed color components. */ public QuadGroup(int[] ijkl, float[] xyz, float[] uvw, float[] rgb) { if (uvw==null) uvw = computeNormals(ijkl,xyz); buildTree(ijkl,xyz,uvw,rgb); setDefaultStates(); }
private void buildTree(Group parent, BoundingBoxTree.Node bbtNode, int[] ijkl, float[] xyz, float[] uvw, float[] rgb) { if (bbtNode.isLeaf()) { QuadNode qn = new QuadNode(bbtNode,ijkl,xyz,uvw,rgb); parent.addChild(qn); } else { Group group = new Group(); parent.addChild(group); buildTree(group,bbtNode.getLeft(),ijkl,xyz,uvw,rgb); buildTree(group,bbtNode.getRight(),ijkl,xyz,uvw,rgb); } }
/** * Constructs a quad group with specified vertex coordinates. * <p> * The (x,y,z) coordinates of vertices are packed into the specified * array xyz. The number of vertices is nv = xyz.length/3. The number * of quads is nq = nv/4 = xyz.length/12. * <p> * The (r,g,b) components of colors are packed into the specified * array rgb. The number of colors equals the number of vertices. * <p> * Normal vectors may be computed for either vertices or quads. * When computed for a vertex, a normal vector is the area-weighted * average of the normal vectors for all quads with that vertex. * <p> * If no vertices have the same (x,y,z) coordinates, then vertex and * quad normal vectors are the same vectors, but quad normal vectors * are less costly to compute. * @param vn true, for vertex normals; false, for quad normals. * @param xyz array[3*nv] of packed vertex coordinates. * @param rgb array[3*nv] of packed color components. */ public QuadGroup(boolean vn, float[] xyz, float[] rgb) { int[] ijkl = indexVertices(!vn,xyz); float[] uvw = computeNormals(ijkl,xyz); buildTree(ijkl,xyz,uvw,rgb); setDefaultStates(); }