Exemple #1
0
        /**
         * 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));
        }
Exemple #2
0
        /**
         * Compute the perimeter for a black node.
         *
         * @param size
         */
        public override int perimeter(int size)
        {
            int retval = 0;
            // North
            QuadTreeNode neighbor = gtEqualAdjNeighbor(QuadTreeNode.NORTH);

            if (neighbor == null || neighbor is WhiteNode)
            {
                retval += size;
            }
            else if (neighbor is GreyNode)
            {
                retval += neighbor.sumAdjacent(Quadrant.cSouthEast, Quadrant.cSouthWest, size);
            }
            else
            {
                ;
            }

            // East
            neighbor = gtEqualAdjNeighbor(QuadTreeNode.EAST);
            if (neighbor == null || neighbor is WhiteNode)
            {
                retval += size;
            }
            else if (neighbor is GreyNode)
            {
                retval += neighbor.sumAdjacent(Quadrant.cSouthWest, Quadrant.cNorthWest, size);
            }
            else
            {
                ;
            }

            // South
            neighbor = gtEqualAdjNeighbor(QuadTreeNode.SOUTH);
            if (neighbor == null || neighbor is WhiteNode)
            {
                retval += size;
            }
            else if (neighbor is GreyNode)
            {
                retval += neighbor.sumAdjacent(Quadrant.cNorthWest, Quadrant.cNorthEast, size);
            }
            else
            {
                ;
            }

            // West
            neighbor = gtEqualAdjNeighbor(QuadTreeNode.WEST);
            if (neighbor == null || neighbor is WhiteNode)
            {
                retval += size;
            }
            else if (neighbor is GreyNode)
            {
                retval += neighbor.sumAdjacent(Quadrant.cNorthEast, Quadrant.cSouthEast, size);
            }
            else
            {
                ;
            }

            return(retval);
        }