/** * Sum the perimeter of all white leaves in the two specified * quadrants of the sub quad tree rooted at this node. Since * this is a grey node, we just recursively call this routine * on the appropriate children (that may be white nodes). * * @param quad1 the first specified quadrant * @param quad2 the second specified quadrant * @param size the size of the image represented by this node * @return the perimeter of the adjacent nodes */ public override int sumAdjacent (Quadrant quad1, Quadrant quad2, int size) { QuadTreeNode child1 = quad1.child (this); QuadTreeNode child2 = quad2.child (this); size = size / 2; return child1.sumAdjacent (quad1, quad2, size) + child2.sumAdjacent (quad1, quad2, size); }
/** * The entry point to computing the perimeter of an image. * * @param args the command line arguments */ public static void Main(String[] args, ILog ilog) { logger = ilog; parseCmdLine(args); Quadrant.staticInitQuadrant(); int size = 1 << levels; int msize = 1 << (levels - 1); QuadTreeNode.gcmp = size * 1024; QuadTreeNode.lcmp = msize * 1024; QuadTreeNode tree = QuadTreeNode.createTree(msize, 0, 0, null, Quadrant.cSouthEast, levels); int leaves = tree.countTree(); int perm = tree.perimeter(size); if (printResult) { logger.InfoFormat("Perimeter is " + perm); logger.InfoFormat("Number of leaves " + leaves); } logger.InfoFormat("Done!"); }
/** * Sum the perimeter of all white leaves in the two specified * quadrants of the sub quad tree rooted at this node. Since * this is a grey node, we just recursively call this routine * on the appropriate children (that may be white nodes). * * @param quad1 the first specified quadrant * @param quad2 the second specified quadrant * @param size the size of the image represented by this node * @return the perimeter of the adjacent nodes */ public override int sumAdjacent(Quadrant quad1, Quadrant quad2, int size) { QuadTreeNode child1 = quad1.child(this); QuadTreeNode child2 = quad2.child(this); size = size / 2; return(child1.sumAdjacent(quad1, quad2, size) + child2.sumAdjacent(quad1, quad2, size)); }
/** * Create a node in the quad tree. * * @param childType if there's a parent, the type of child * @param nw the node represent the northwest quadrant * @param ne the node represent the northeast quadrant * @param sw the node represent the southwest quadrant * @param se the node represent the southeast quadrant */ private QuadTreeNode(Quadrant quad, QuadTreeNode nw, QuadTreeNode ne, QuadTreeNode sw, QuadTreeNode se, QuadTreeNode parent) { this.quadrant = quad; this.nw = nw; this.ne = ne; this.sw = sw; this.se = se; this.parent = parent; }
/** * Sum the perimeter of all white leaves in the two specified * quadrants of the sub quad tree rooted at this node. * * @param quad1 the first specified quadrant * @param quad2 the second specified quadrant * @param size the size of the image represented by this node. * @return the perimeter of the adjacent nodes */ public override int sumAdjacent (Quadrant quad1, Quadrant quad2, int size) { return 0; }
/** * Construct a <tt>black</tt> quad tree node. * * @param quadrant the quadrant that this node represents * @param the parent quad tree node */ public BlackNode (Quadrant quadrant, QuadTreeNode parent) : base (quadrant, parent) { ; }
/** * Construct a <tt>black</tt> quad tree node. * * @param quadrant the quadrant that this node represents * @param the parent quad tree node */ public BlackNode(Quadrant quadrant, QuadTreeNode parent) : base(quadrant, parent) { ; }
/** * Sum the perimeter of all white leaves in the two specified * quadrants of the sub quad tree rooted at this node. * * @param quad1 the first specified quadrant * @param quad2 the second specified quadrant * @param size the size of the image represented by this node. * @return the perimeter of the adjacent nodes */ public override int sumAdjacent(Quadrant quad1, Quadrant quad2, int size) { return(0); }
/** * Create a leaf node in the Quad Tree. * * @param childType if there's a parent, the type of child this node represents * @param parent the parent quad tree node */ public QuadTreeNode(Quadrant quad, QuadTreeNode parent) : this(quad, null, null, null, null, parent) { ; }
/** * Sum the perimeter of all white leaves in the two specified * quadrants of the sub quad tree rooted at this node. * * @param quad1 the first specified quadrant * @param quad2 the second specified quadrant * @param size the size of the image represented by this node. * @return the perimeter of the adjacent nodes */ abstract public int sumAdjacent(Quadrant quad1, Quadrant quad2, int size);
/** * Create an image which is represented using a QuadTreeNode. * * @param size size of image * @param center_x x coordinate of center * @param center_y; y coordinate of center * @param parent parent quad tree node * @param quadrant the quadrant that the sub tree is in * @param level the level of the tree */ public static QuadTreeNode createTree(int size, int center_x, int center_y, QuadTreeNode parent, Quadrant quadrant, int level) { QuadTreeNode node; int intersect = checkIntersect(center_x, center_y, size); size = size / 2; if (intersect == 0 && size < 512) { node = new WhiteNode(quadrant, parent); } else if (intersect == 2) { node = new BlackNode(quadrant, parent); } else { if (level == 0) { node = new BlackNode(quadrant, parent); } else { node = new GreyNode(quadrant, parent); QuadTreeNode sw = createTree(size, center_x - size, center_y - size, node, Quadrant.cSouthWest, level - 1); QuadTreeNode se = createTree(size, center_x + size, center_y - size, node, Quadrant.cSouthEast, level - 1); QuadTreeNode ne = createTree(size, center_x + size, center_y + size, node, Quadrant.cNorthEast, level - 1); QuadTreeNode nw = createTree(size, center_x - size, center_y + size, node, Quadrant.cNorthWest, level - 1); node.setChildren(nw, ne, sw, se); } } return(node); }
/** * Construct a <tt>grey</tt> image node. * * @param quadrant the quadrant that this node represents * @param parent the parent node in the quad tree. */ public GreyNode(Quadrant quadrant, QuadTreeNode parent) : base(quadrant, parent) { ; }
/** * Construct a <tt>white</tt> image node. * * @param quadrant the quadrant that this node represents * @param parent the parent node in the quad tree */ public WhiteNode(Quadrant quadrant, QuadTreeNode parent) : base(quadrant, parent) { ; }
/** * Construct a <tt>white</tt> image node. * * @param quadrant the quadrant that this node represents * @param parent the parent node in the quad tree */ public WhiteNode (Quadrant quadrant, QuadTreeNode parent) : base (quadrant, parent) { ; }
/** * Construct a <tt>grey</tt> image node. * * @param quadrant the quadrant that this node represents * @param parent the parent node in the quad tree. */ public GreyNode (Quadrant quadrant, QuadTreeNode parent) : base (quadrant, parent) { ; }