From 514ddbfe1d3c1f773f911d17479094503ab26d95 Mon Sep 17 00:00:00 2001 From: Camil Staps Date: Mon, 23 Mar 2015 22:20:04 +0100 Subject: Framework week 8 --- Week8/src/qtrees/Bitmap.java | 73 ++++++++++++++++++++++++++++++++++++++++++++ Week8/src/qtrees/QTNode.java | 23 ++++++++++++++ Week8/src/qtrees/QTree.java | 34 +++++++++++++++++++++ Week8/src/qtrees/Qtrees.java | 24 +++++++++++++++ 4 files changed, 154 insertions(+) create mode 100644 Week8/src/qtrees/Bitmap.java create mode 100644 Week8/src/qtrees/QTNode.java create mode 100644 Week8/src/qtrees/QTree.java create mode 100644 Week8/src/qtrees/Qtrees.java (limited to 'Week8/src/qtrees') diff --git a/Week8/src/qtrees/Bitmap.java b/Week8/src/qtrees/Bitmap.java new file mode 100644 index 0000000..551c4c4 --- /dev/null +++ b/Week8/src/qtrees/Bitmap.java @@ -0,0 +1,73 @@ +package qtrees; + +/** + * Bitmap: A class for representing bitmap; + * @author Sjaak Smetsers + * @version 18-03-2015 + */ +public class Bitmap { + // each bit is stored into an two dimensional array + private final boolean[][] raster; + private final int bmWidth, bmHeight; + + /** + * Creates an empty bitmap of size width * height + * @param width + * @param height + */ + public Bitmap( int width, int height ) { + raster = new boolean[width][height]; + bmWidth = width; + bmHeight = height; + } + + /** + * Gets a bit at the specified position + * @param x: x coordinate + * @param y: y coordinate + */ + public boolean getBit( int x, int y ) { + return raster[x][y]; + } + + /** + * Sets a bit at the specified position + * @param x: x coordinate + * @param y: y coordinate + * @param val: the bit value + */ + public void setBit( int x, int y, boolean val ){ + raster[x][y] = val; + } + + /** + * Converts a bitmap into a string + * 1 is represented by '*'; 0 by 'O' + * @return the string representation + */ + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + for (int y = 0; y < bmHeight; y++) { + for (int x = 0; x < bmWidth; x++) { + sb.append( raster[x][y] ? '*' : 'O' ); + } + sb.append( '\n' ); + } + return sb.toString(); + } + + /** + * @return the width of the bitmap + */ + public int getWidth() { + return bmWidth; + } + + /** + * @return the height of the bitmap + */ + public int getHeight() { + return bmHeight; + } +} diff --git a/Week8/src/qtrees/QTNode.java b/Week8/src/qtrees/QTNode.java new file mode 100644 index 0000000..4498dff --- /dev/null +++ b/Week8/src/qtrees/QTNode.java @@ -0,0 +1,23 @@ + +package qtrees; + +import java.io.Writer; + +/** + * + * @author Sjaak Smetsers + * @version 18-03-2014 + */ +public abstract class QTNode { + public abstract void fillBitmap( int x, int y, int width, Bitmap bitmap ); + public abstract void writeNode( Writer out ); + public abstract boolean sameLeaf( QTNode other_node ); + + public static void fillArea( int x, int y, int width, Bitmap bitmap, boolean val ){ + for (int i = 0; i < width; i++) { + for (int j = 0; j < width; j++) { + bitmap.setBit(x+i, y+j, val); + } + } + } +} diff --git a/Week8/src/qtrees/QTree.java b/Week8/src/qtrees/QTree.java new file mode 100644 index 0000000..ab11898 --- /dev/null +++ b/Week8/src/qtrees/QTree.java @@ -0,0 +1,34 @@ +package qtrees; + +import java.io.IOException; +import java.io.Reader; +import java.io.Writer; + +public class QTree { + QTNode root; + + public QTree( Reader input ) { + root = readQTree( input ); + } + + public QTree( Bitmap bitmap ) { + root = bitmap2QTree( 0, 0, bitmap.getWidth(), bitmap ); + } + + public void fillBitmap ( Bitmap bitmap ) { + root.fillBitmap(0, 0, bitmap.getWidth(), bitmap); + } + + public void writeQTree( Writer sb ) { + root.writeNode( sb ); + } + + private static QTNode readQTree( Reader input ) { + return null; + } + + public static QTNode bitmap2QTree( int x, int y, int width, Bitmap bitmap ) { + return null; + } + +} diff --git a/Week8/src/qtrees/Qtrees.java b/Week8/src/qtrees/Qtrees.java new file mode 100644 index 0000000..7bd018e --- /dev/null +++ b/Week8/src/qtrees/Qtrees.java @@ -0,0 +1,24 @@ +package qtrees; + +import java.io.StringReader; + +/** + * + * @author Sjaak + */ +public class Qtrees { + + /** + * @param args the command line arguments + */ + public static void main(String[] args) { + String test_tekst = "10011010001010010001010101100011000101000000"; + StringReader input = new StringReader(test_tekst); + QTree qt = new QTree( input ); + Bitmap bitmap = new Bitmap(8, 8); + qt.fillBitmap( bitmap ); + System.out.println(bitmap); + + } + +} -- cgit v1.2.3