public Node(Tree tree, int x, int y, int width, int height) { if (width < 1 || height < 1) { throw new ArgumentOutOfRangeException(); } this.mX = x; this.mY = y; this.mWidth = width; this.mHeight = height; // Test if this node requires splitting. if (tree.IsNodeSplitRequired(this) == false) { // Assign colour - this is a leaf. mColour = tree.GetColourForNode(this); } else { // Split into four (half width, half height) sections. int newWidth = width / 2; int newHeight = height / 2; mChildNodes = new Node[4] { null, null, null, null }; Node childNW = new Node(tree, x, y, newWidth, newHeight); mChildNodes[Node.NorthWest] = childNW; Node childSW = new Node(tree, x, y + newHeight, newWidth, newHeight); mChildNodes[Node.SouthWest] = childSW; Node childSE = new Node(tree, x + newWidth, y + newHeight, newWidth, newHeight); mChildNodes[Node.SouthEast] = childSE; Node childNE = new Node(tree, x + newWidth, y, newWidth, newHeight); mChildNodes[Node.NorthEast] = childNE; } }
private Tree BuildQuadtree(Image img) { Bitmap sourceBitmap = new Bitmap(img); BitmapData sourceData = sourceBitmap.LockBits( new Rectangle(0, 0, sourceBitmap.Width, sourceBitmap.Height), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb ); Tree tree = new Tree(sourceData, MinimumBlockSize, Threshold); sourceBitmap.UnlockBits(sourceData); return tree; }