Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class QuadTree {
- /** Attributes **/
- MyPicture pic;
- QuadNode root;
- int maxLevel;
- double RedT;
- double GreenT;
- double BlueT;
- QuadNode northWest;
- QuadNode southWest;
- QuadNode northEast;
- QuadNode southEast;
- /**
- * Constructor for QuadTree
- * @param pic - the picture object
- * @param root - the root
- * @param maxLevel - the maximum level
- * @param RedT - the red T
- * @param GreenT - the green T
- * @param BlueT - the blue T
- */
- public QuadTree (MyPicture pic, QuadNode root, int maxLevel, double RedT, double GreenT, double BlueT){
- this.pic = pic;
- this.root = root;
- this.maxLevel = maxLevel;
- this.RedT = RedT;
- this.GreenT = GreenT;
- this.BlueT = BlueT;
- this.split(root);
- }
- /**
- * Split helper method that splits the segments represented by it into 4 QuadNode nodes
- * One for each of northEast, northWest, southEast, and southWest
- * @param QuadNode node
- */
- public void split(QuadNode node) {
- if (homogeneous(node) != true) {
- node.northWest = new QuadNode(pic, node.getX(), node.getY(), node.getSideLength()/2,node.getLevel()+1, pic.simpleStatistics(node.getX(),node.getY(), node.getSideLength()));
- split(northWest);
- node.northEast = new QuadNode(pic, node.getX()+node.getSideLength()/2, node.getY(), node.getSideLength()/2,node.getLevel()+1, pic.simpleStatistics(node.getX(),node.getY(), node.getSideLength()));
- split(northEast);
- node.southWest = new QuadNode(pic, node.getX(), node.getY()+node.getSideLength()/2, node.getSideLength()/2,node.getLevel()+1, pic.simpleStatistics(node.getX(),node.getY(), node.getSideLength()));
- split(southWest);
- node.southEast = new QuadNode(pic, node.getX()+node.getSideLength()/2, node.getY()+node.getSideLength()/2, node.getSideLength()/2,node.getLevel()+1, pic.simpleStatistics(node.getX(),node.getY(), node.getSideLength()));
- split(southEast);
- }
- }
- public boolean homogeneous(QuadNode node){
- if ((node.sigmaRed <= RedT && node.sigmaGreen <= GreenT && node.sigmaBlue <= BlueT || node.level==maxLevel || node.sideLength <= 8))
- return true;
- }
- public boolean isLeaf() {
- return northEast == null;
- }
- private void preorder (QuadNode root, LinkedQueue<T> queue)
- {
- if (root != null)
- {
- queue.enqueue(node);
- preorder (root.getNorthEast(), queue);
- preorder (root.getSouthWest(), queue);
- preorder (root.getNorthWest(), queue);
- preorder (root.getSouthEast(), queue);
- }//if
- } // method preorder
- public void drawSegmentation(MyPicture pic, LinkedQueue<T> queue){
- dequeue(queue);
- }
- public void paintSquares(){
- paintSegment(int x,int y,int sideLength, double red,double green,double blue);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement