From bde4724eb154341274b477ff0c65e5a17b8e39cd Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Wed, 25 Mar 2015 22:09:41 +0100 Subject: More flexible usage of QTNode --- Week8/src/qtrees/BlackLeaf.java | 19 ++++--------------- Week8/src/qtrees/QTNode.java | 22 ++++++++++++++++++++-- Week8/src/qtrees/WhiteLeaf.java | 19 ++++--------------- 3 files changed, 28 insertions(+), 32 deletions(-) (limited to 'Week8/src/qtrees') diff --git a/Week8/src/qtrees/BlackLeaf.java b/Week8/src/qtrees/BlackLeaf.java index ec48997..0f7e71e 100644 --- a/Week8/src/qtrees/BlackLeaf.java +++ b/Week8/src/qtrees/BlackLeaf.java @@ -1,24 +1,13 @@ package qtrees; -import java.io.IOException; -import java.io.Writer; - /** * @author Camil Staps, s4498062 */ public class BlackLeaf extends QTNode { - - @Override - public void fillBitmap(int x, int y, int width, Bitmap bitmap) { - int old_x = x, old_y = y; - for (; x < old_x + width; x++) - for (; y < old_y + width; y++) - bitmap.setBit(x, y, false); - } - - @Override - public void writeNode(Writer out) throws IOException { - out.write("00"); + + public BlackLeaf () { + boolean_value = false; + string_value = "0"; } } diff --git a/Week8/src/qtrees/QTNode.java b/Week8/src/qtrees/QTNode.java index 26cf9e1..ee00b7c 100644 --- a/Week8/src/qtrees/QTNode.java +++ b/Week8/src/qtrees/QTNode.java @@ -11,21 +11,39 @@ import java.io.Writer; * Note: the version by Sjaak Smetsers contained a sameLeaf method. This seems to be reduntant though, so I removed it. */ public abstract class QTNode { + protected boolean boolean_value; + protected String string_value; + /** * Fill a (part of a) bitmap with this node + * In the template this was an abstract method. However, then we would use + * essentially the same code in BlackLeaf and WhiteLeaf. Using a concrete + * function here that depends on static properties is much more flexible. In + * GreyNode we still override this function. * @param x the x coordinate of the top left corner * @param y the y coordinate of the top left corner * @param width the width of the part of the bitmap to fill * @param bitmap the bitmap to fill */ - public abstract void fillBitmap( int x, int y, int width, Bitmap bitmap ); + public void fillBitmap( int x, int y, int width, Bitmap bitmap ) { + int old_x = x, old_y = y; + for (; x < old_x + width; x++) + for (y = old_y; y < old_y + width; y++) + bitmap.setBit(x, y, boolean_value); + } /** * Write a node as bitstream + * In the template this was an abstract method. However, then we would use + * essentially the same code in BlackLeaf and WhiteLeaf. Using a concrete + * function here that depends on static properties is much more flexible. In + * GreyNode we still override this function. * @param out Writer to write to * @throws IOException is passed on from Writer */ - public abstract void writeNode( Writer out ) throws IOException; + public void writeNode( Writer out ) throws IOException { + out.write("0" + string_value); + } /** * Fill a complete area of a bitmap with a particular value diff --git a/Week8/src/qtrees/WhiteLeaf.java b/Week8/src/qtrees/WhiteLeaf.java index 31be533..57cb591 100644 --- a/Week8/src/qtrees/WhiteLeaf.java +++ b/Week8/src/qtrees/WhiteLeaf.java @@ -1,24 +1,13 @@ package qtrees; -import java.io.IOException; -import java.io.Writer; - /** * @author Camil Staps, s4498062 */ public class WhiteLeaf extends QTNode { - - @Override - public void fillBitmap(int x, int y, int width, Bitmap bitmap) { - int old_x = x, old_y = y; - for (; x < old_x + width; x++) - for (y = old_y; y < old_y + width; y++) - bitmap.setBit(x, y, true); - } - - @Override - public void writeNode(Writer out) throws IOException { - out.write("01"); + + public WhiteLeaf() { + boolean_value = true; + string_value = "1"; } } -- cgit v1.2.3