From 6a44b074f0169a1b0f9e92347af929c5e471746e Mon Sep 17 00:00:00 2001
From: Camil Staps
Date: Sat, 18 Apr 2015 13:44:44 +0200
Subject: Reorganised projects
---
Week8 Quadtrees/.gitignore | 3 +
Week8 Quadtrees/Assignment (in Dutch).pdf | Bin 0 -> 147901 bytes
Week8 Quadtrees/Week8.tar.gz | Bin 0 -> 4059 bytes
Week8 Quadtrees/build.xml | 73 +
.../build/classes/.netbeans_automatic_build | 0
.../build/classes/.netbeans_update_resources | 0
Week8 Quadtrees/build/classes/qtrees/Bitmap.class | Bin 0 -> 1317 bytes
.../build/classes/qtrees/BlackLeaf.class | Bin 0 -> 369 bytes
.../build/classes/qtrees/GreyNode.class | Bin 0 -> 1715 bytes
Week8 Quadtrees/build/classes/qtrees/QTNode.class | Bin 0 -> 1388 bytes
Week8 Quadtrees/build/classes/qtrees/QTree.class | Bin 0 -> 2259 bytes
Week8 Quadtrees/build/classes/qtrees/Qtrees.class | Bin 0 -> 1404 bytes
.../build/classes/qtrees/WhiteLeaf.class | Bin 0 -> 369 bytes
Week8 Quadtrees/nbproject/build-impl.xml | 1413 ++++++++++++++++++++
Week8 Quadtrees/nbproject/genfiles.properties | 8 +
.../nbproject/private/private.properties | 2 +
Week8 Quadtrees/nbproject/private/private.xml | 7 +
Week8 Quadtrees/nbproject/project.properties | 72 +
Week8 Quadtrees/nbproject/project.xml | 15 +
Week8 Quadtrees/src/qtrees/Bitmap.java | 73 +
Week8 Quadtrees/src/qtrees/BlackLeaf.java | 13 +
Week8 Quadtrees/src/qtrees/GreyNode.java | 59 +
Week8 Quadtrees/src/qtrees/QTNode.java | 63 +
Week8 Quadtrees/src/qtrees/QTree.java | 102 ++
Week8 Quadtrees/src/qtrees/Qtrees.java | 54 +
Week8 Quadtrees/src/qtrees/WhiteLeaf.java | 13 +
26 files changed, 1970 insertions(+)
create mode 100644 Week8 Quadtrees/.gitignore
create mode 100644 Week8 Quadtrees/Assignment (in Dutch).pdf
create mode 100644 Week8 Quadtrees/Week8.tar.gz
create mode 100644 Week8 Quadtrees/build.xml
create mode 100644 Week8 Quadtrees/build/classes/.netbeans_automatic_build
create mode 100644 Week8 Quadtrees/build/classes/.netbeans_update_resources
create mode 100644 Week8 Quadtrees/build/classes/qtrees/Bitmap.class
create mode 100644 Week8 Quadtrees/build/classes/qtrees/BlackLeaf.class
create mode 100644 Week8 Quadtrees/build/classes/qtrees/GreyNode.class
create mode 100644 Week8 Quadtrees/build/classes/qtrees/QTNode.class
create mode 100644 Week8 Quadtrees/build/classes/qtrees/QTree.class
create mode 100644 Week8 Quadtrees/build/classes/qtrees/Qtrees.class
create mode 100644 Week8 Quadtrees/build/classes/qtrees/WhiteLeaf.class
create mode 100644 Week8 Quadtrees/nbproject/build-impl.xml
create mode 100644 Week8 Quadtrees/nbproject/genfiles.properties
create mode 100644 Week8 Quadtrees/nbproject/private/private.properties
create mode 100644 Week8 Quadtrees/nbproject/private/private.xml
create mode 100644 Week8 Quadtrees/nbproject/project.properties
create mode 100644 Week8 Quadtrees/nbproject/project.xml
create mode 100644 Week8 Quadtrees/src/qtrees/Bitmap.java
create mode 100644 Week8 Quadtrees/src/qtrees/BlackLeaf.java
create mode 100644 Week8 Quadtrees/src/qtrees/GreyNode.java
create mode 100644 Week8 Quadtrees/src/qtrees/QTNode.java
create mode 100644 Week8 Quadtrees/src/qtrees/QTree.java
create mode 100644 Week8 Quadtrees/src/qtrees/Qtrees.java
create mode 100644 Week8 Quadtrees/src/qtrees/WhiteLeaf.java
(limited to 'Week8 Quadtrees')
diff --git a/Week8 Quadtrees/.gitignore b/Week8 Quadtrees/.gitignore
new file mode 100644
index 0000000..4523fc2
--- /dev/null
+++ b/Week8 Quadtrees/.gitignore
@@ -0,0 +1,3 @@
+nbproject/private/
+build/
+dist/
diff --git a/Week8 Quadtrees/Assignment (in Dutch).pdf b/Week8 Quadtrees/Assignment (in Dutch).pdf
new file mode 100644
index 0000000..48752d1
Binary files /dev/null and b/Week8 Quadtrees/Assignment (in Dutch).pdf differ
diff --git a/Week8 Quadtrees/Week8.tar.gz b/Week8 Quadtrees/Week8.tar.gz
new file mode 100644
index 0000000..7ca3d94
Binary files /dev/null and b/Week8 Quadtrees/Week8.tar.gz differ
diff --git a/Week8 Quadtrees/build.xml b/Week8 Quadtrees/build.xml
new file mode 100644
index 0000000..096f28f
--- /dev/null
+++ b/Week8 Quadtrees/build.xml
@@ -0,0 +1,73 @@
+
+
+
+
+
+
+
+
+
+
+ Builds, tests, and runs the project Week8 Quadtrees.
+
+
+
diff --git a/Week8 Quadtrees/build/classes/.netbeans_automatic_build b/Week8 Quadtrees/build/classes/.netbeans_automatic_build
new file mode 100644
index 0000000..e69de29
diff --git a/Week8 Quadtrees/build/classes/.netbeans_update_resources b/Week8 Quadtrees/build/classes/.netbeans_update_resources
new file mode 100644
index 0000000..e69de29
diff --git a/Week8 Quadtrees/build/classes/qtrees/Bitmap.class b/Week8 Quadtrees/build/classes/qtrees/Bitmap.class
new file mode 100644
index 0000000..d552ee0
Binary files /dev/null and b/Week8 Quadtrees/build/classes/qtrees/Bitmap.class differ
diff --git a/Week8 Quadtrees/build/classes/qtrees/BlackLeaf.class b/Week8 Quadtrees/build/classes/qtrees/BlackLeaf.class
new file mode 100644
index 0000000..996431c
Binary files /dev/null and b/Week8 Quadtrees/build/classes/qtrees/BlackLeaf.class differ
diff --git a/Week8 Quadtrees/build/classes/qtrees/GreyNode.class b/Week8 Quadtrees/build/classes/qtrees/GreyNode.class
new file mode 100644
index 0000000..fe9a698
Binary files /dev/null and b/Week8 Quadtrees/build/classes/qtrees/GreyNode.class differ
diff --git a/Week8 Quadtrees/build/classes/qtrees/QTNode.class b/Week8 Quadtrees/build/classes/qtrees/QTNode.class
new file mode 100644
index 0000000..13506c9
Binary files /dev/null and b/Week8 Quadtrees/build/classes/qtrees/QTNode.class differ
diff --git a/Week8 Quadtrees/build/classes/qtrees/QTree.class b/Week8 Quadtrees/build/classes/qtrees/QTree.class
new file mode 100644
index 0000000..ff1efb7
Binary files /dev/null and b/Week8 Quadtrees/build/classes/qtrees/QTree.class differ
diff --git a/Week8 Quadtrees/build/classes/qtrees/Qtrees.class b/Week8 Quadtrees/build/classes/qtrees/Qtrees.class
new file mode 100644
index 0000000..744fac8
Binary files /dev/null and b/Week8 Quadtrees/build/classes/qtrees/Qtrees.class differ
diff --git a/Week8 Quadtrees/build/classes/qtrees/WhiteLeaf.class b/Week8 Quadtrees/build/classes/qtrees/WhiteLeaf.class
new file mode 100644
index 0000000..7ee4cd3
Binary files /dev/null and b/Week8 Quadtrees/build/classes/qtrees/WhiteLeaf.class differ
diff --git a/Week8 Quadtrees/nbproject/build-impl.xml b/Week8 Quadtrees/nbproject/build-impl.xml
new file mode 100644
index 0000000..c242c6b
--- /dev/null
+++ b/Week8 Quadtrees/nbproject/build-impl.xml
@@ -0,0 +1,1413 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Must set src.dir
+ Must set test.src.dir
+ Must set build.dir
+ Must set dist.dir
+ Must set build.classes.dir
+ Must set dist.javadoc.dir
+ Must set build.test.classes.dir
+ Must set build.test.results.dir
+ Must set build.classes.excludes
+ Must set dist.jar
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Must set javac.includes
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ No tests executed.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Must set JVM to use for profiling in profiler.info.jvm
+ Must set profiler agent JVM arguments in profiler.info.jvmargs.agent
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Must select some files in the IDE or set javac.includes
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ To run this application from the command line without Ant, try:
+
+ java -jar "${dist.jar.resolved}"
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Must select one file in the IDE or set run.class
+
+
+
+ Must select one file in the IDE or set run.class
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Must select one file in the IDE or set debug.class
+
+
+
+
+ Must select one file in the IDE or set debug.class
+
+
+
+
+ Must set fix.includes
+
+
+
+
+
+
+
+
+
+ This target only works when run from inside the NetBeans IDE.
+
+
+
+
+
+
+
+
+ Must select one file in the IDE or set profile.class
+ This target only works when run from inside the NetBeans IDE.
+
+
+
+
+
+
+
+
+ This target only works when run from inside the NetBeans IDE.
+
+
+
+
+
+
+
+
+
+
+
+
+ This target only works when run from inside the NetBeans IDE.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Must select one file in the IDE or set run.class
+
+
+
+
+
+ Must select some files in the IDE or set test.includes
+
+
+
+
+ Must select one file in the IDE or set run.class
+
+
+
+
+ Must select one file in the IDE or set applet.url
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Must select some files in the IDE or set javac.includes
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Some tests failed; see details above.
+
+
+
+
+
+
+
+
+ Must select some files in the IDE or set test.includes
+
+
+
+ Some tests failed; see details above.
+
+
+
+ Must select some files in the IDE or set test.class
+ Must select some method in the IDE or set test.method
+
+
+
+ Some tests failed; see details above.
+
+
+
+
+ Must select one file in the IDE or set test.class
+
+
+
+ Must select one file in the IDE or set test.class
+ Must select some method in the IDE or set test.method
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Must select one file in the IDE or set applet.url
+
+
+
+
+
+
+
+
+ Must select one file in the IDE or set applet.url
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/Week8 Quadtrees/nbproject/genfiles.properties b/Week8 Quadtrees/nbproject/genfiles.properties
new file mode 100644
index 0000000..c132556
--- /dev/null
+++ b/Week8 Quadtrees/nbproject/genfiles.properties
@@ -0,0 +1,8 @@
+build.xml.data.CRC32=d07c7d97
+build.xml.script.CRC32=544d099d
+build.xml.stylesheet.CRC32=8064a381@1.75.2.48
+# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
+# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
+nbproject/build-impl.xml.data.CRC32=d07c7d97
+nbproject/build-impl.xml.script.CRC32=1870b0c1
+nbproject/build-impl.xml.stylesheet.CRC32=876e7a8f@1.75.2.48
diff --git a/Week8 Quadtrees/nbproject/private/private.properties b/Week8 Quadtrees/nbproject/private/private.properties
new file mode 100644
index 0000000..fca3b8a
--- /dev/null
+++ b/Week8 Quadtrees/nbproject/private/private.properties
@@ -0,0 +1,2 @@
+compile.on.save=true
+user.properties.file=/home/camilstaps/.netbeans/8.0.2/build.properties
diff --git a/Week8 Quadtrees/nbproject/private/private.xml b/Week8 Quadtrees/nbproject/private/private.xml
new file mode 100644
index 0000000..6807a2b
--- /dev/null
+++ b/Week8 Quadtrees/nbproject/private/private.xml
@@ -0,0 +1,7 @@
+
+
+
+
+
+
+
diff --git a/Week8 Quadtrees/nbproject/project.properties b/Week8 Quadtrees/nbproject/project.properties
new file mode 100644
index 0000000..371311f
--- /dev/null
+++ b/Week8 Quadtrees/nbproject/project.properties
@@ -0,0 +1,72 @@
+annotation.processing.enabled=true
+annotation.processing.enabled.in.editor=false
+annotation.processing.processor.options=
+annotation.processing.processors.list=
+annotation.processing.run.all.processors=true
+annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
+build.classes.dir=${build.dir}/classes
+build.classes.excludes=**/*.java,**/*.form
+# This directory is removed when the project is cleaned:
+build.dir=build
+build.generated.dir=${build.dir}/generated
+build.generated.sources.dir=${build.dir}/generated-sources
+# Only compile against the classpath explicitly listed here:
+build.sysclasspath=ignore
+build.test.classes.dir=${build.dir}/test/classes
+build.test.results.dir=${build.dir}/test/results
+# Uncomment to specify the preferred debugger connection transport:
+#debug.transport=dt_socket
+debug.classpath=\
+ ${run.classpath}
+debug.test.classpath=\
+ ${run.test.classpath}
+# Files in build.classes.dir which should be excluded from distribution jar
+dist.archive.excludes=
+# This directory is removed when the project is cleaned:
+dist.dir=dist
+dist.jar=${dist.dir}/Week8_Quadtrees.jar
+dist.javadoc.dir=${dist.dir}/javadoc
+excludes=
+includes=**
+jar.compress=false
+javac.classpath=
+# Space-separated list of extra javac options
+javac.compilerargs=
+javac.deprecation=false
+javac.processorpath=\
+ ${javac.classpath}
+javac.source=1.7
+javac.target=1.7
+javac.test.classpath=\
+ ${javac.classpath}:\
+ ${build.classes.dir}
+javac.test.processorpath=\
+ ${javac.test.classpath}
+javadoc.additionalparam=
+javadoc.author=false
+javadoc.encoding=${source.encoding}
+javadoc.noindex=false
+javadoc.nonavbar=false
+javadoc.notree=false
+javadoc.private=false
+javadoc.splitindex=true
+javadoc.use=true
+javadoc.version=false
+javadoc.windowtitle=
+main.class=qtrees.Qtrees
+meta.inf.dir=${src.dir}/META-INF
+mkdist.disabled=true
+platform.active=default_platform
+run.classpath=\
+ ${javac.classpath}:\
+ ${build.classes.dir}
+# Space-separated list of JVM arguments used when running the project.
+# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value.
+# To set system properties for unit tests define test-sys-prop.name=value:
+run.jvmargs=
+run.test.classpath=\
+ ${javac.test.classpath}:\
+ ${build.test.classes.dir}
+source.encoding=UTF-8
+src.dir=src
+test.src.dir=test
diff --git a/Week8 Quadtrees/nbproject/project.xml b/Week8 Quadtrees/nbproject/project.xml
new file mode 100644
index 0000000..f2206da
--- /dev/null
+++ b/Week8 Quadtrees/nbproject/project.xml
@@ -0,0 +1,15 @@
+
+
+ org.netbeans.modules.java.j2seproject
+
+
+ Week8 Quadtrees
+
+
+
+
+
+
+
+
+
diff --git a/Week8 Quadtrees/src/qtrees/Bitmap.java b/Week8 Quadtrees/src/qtrees/Bitmap.java
new file mode 100644
index 0000000..551c4c4
--- /dev/null
+++ b/Week8 Quadtrees/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 Quadtrees/src/qtrees/BlackLeaf.java b/Week8 Quadtrees/src/qtrees/BlackLeaf.java
new file mode 100644
index 0000000..0f7e71e
--- /dev/null
+++ b/Week8 Quadtrees/src/qtrees/BlackLeaf.java
@@ -0,0 +1,13 @@
+package qtrees;
+
+/**
+ * @author Camil Staps, s4498062
+ */
+public class BlackLeaf extends QTNode {
+
+ public BlackLeaf () {
+ boolean_value = false;
+ string_value = "0";
+ }
+
+}
diff --git a/Week8 Quadtrees/src/qtrees/GreyNode.java b/Week8 Quadtrees/src/qtrees/GreyNode.java
new file mode 100644
index 0000000..326b0af
--- /dev/null
+++ b/Week8 Quadtrees/src/qtrees/GreyNode.java
@@ -0,0 +1,59 @@
+package qtrees;
+
+import java.io.IOException;
+import java.io.Writer;
+
+/**
+ * A "grey" node (contains both black and white leaves)
+ *
+ * @author Camil Staps, s4498062
+ */
+public class GreyNode extends QTNode {
+
+ /** The four children, starting at North West, counting clockwise */
+ private final QTNode children[];
+
+ public GreyNode() {
+ children = new QTNode[4];
+ }
+
+ @Override
+ public void fillBitmap(int x, int y, int width, Bitmap bitmap) {
+ children[0].fillBitmap(x, y, width / 2, bitmap);
+ children[1].fillBitmap(x + width / 2, y, width / 2, bitmap);
+ children[2].fillBitmap(x + width / 2, y + width / 2, width / 2, bitmap);
+ children[3].fillBitmap(x, y + width / 2, width / 2, bitmap);
+ }
+
+ @Override
+ public void writeNode(Writer out) throws IOException {
+ out.write("1");
+ for (QTNode child : children)
+ child.writeNode(out);
+ }
+
+ /**
+ * Set one of the children nodes
+ * @param index the position of the child: 0 = NW; 1 = NE; 2 = SE; 3 = SW
+ * @param child the child node
+ */
+ public void setChild(int index, QTNode child) {
+ assert (index >= 0 && index <= 3);
+
+ children[index] = child;
+ }
+
+ /**
+ * Compress the current node
+ * @return a BlackLeaf if all the children are black, a WhiteLeaf if all the
+ * children are white, or itself otherwise.
+ */
+ QTNode compress() {
+ if (children[0].getClass() == children[1].getClass()
+ && children[1].getClass() == children[2].getClass()
+ && children[2].getClass() == children[3].getClass())
+ return children[0];
+ return this;
+ }
+
+}
diff --git a/Week8 Quadtrees/src/qtrees/QTNode.java b/Week8 Quadtrees/src/qtrees/QTNode.java
new file mode 100644
index 0000000..e2ad7e5
--- /dev/null
+++ b/Week8 Quadtrees/src/qtrees/QTNode.java
@@ -0,0 +1,63 @@
+package qtrees;
+
+import java.io.IOException;
+import java.io.Writer;
+
+/**
+ * Representation of a node in a QTree
+ * @author Sjaak Smetsers
+ * @author Camil Staps, s4498062
+ *
+ * Note: the version by Sjaak Smetsers contained a sameLeaf method. This seems to be redundant 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 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 void writeNode( Writer out ) throws IOException {
+ out.write("0" + string_value);
+ }
+
+ /**
+ * Fill a complete area of a bitmap with a particular value
+ * @param x the x coordinate of the top left corner
+ * @param y the y coordinate of the top left corner
+ * @param width the width (and height) of the area to fill
+ * @param bitmap the bitmap to fill
+ * @param val the value to fill the area with
+ */
+ 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 Quadtrees/src/qtrees/QTree.java b/Week8 Quadtrees/src/qtrees/QTree.java
new file mode 100644
index 0000000..24fa5e0
--- /dev/null
+++ b/Week8 Quadtrees/src/qtrees/QTree.java
@@ -0,0 +1,102 @@
+package qtrees;
+
+import java.io.IOException;
+import java.io.Reader;
+import java.io.Writer;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+/**
+ * Representation of a Quad-tree
+ * @author Camil Staps, s4498062
+ */
+public class QTree {
+ /** the root of the tree */
+ QTNode root;
+
+ /**
+ * Construct the tree based on an ASCII representation of a bitstream on a reader
+ * @param input the reader
+ */
+ public QTree( Reader input ) {
+ root = readQTree( input );
+ }
+
+ /**
+ * Construct the tree based on a bitmap
+ * @param bitmap the bitmap
+ */
+ public QTree( Bitmap bitmap ) {
+ root = bitmap2QTree( 0, 0, bitmap.getWidth(), bitmap );
+ }
+
+ /**
+ * Fill a bitmap based on this tree
+ * @param bitmap the bitmap
+ */
+ public void fillBitmap ( Bitmap bitmap ) {
+ root.fillBitmap(0, 0, bitmap.getWidth(), bitmap);
+ }
+
+ /**
+ * Write the quad-tree as compressed bitstream
+ * @param sb the Writer to write to
+ * @throws IOException is passed on from Writer
+ */
+ public void writeQTree( Writer sb ) throws IOException {
+ root.writeNode( sb );
+ }
+
+ /**
+ * Read a Quad-tree node based on an ASCII representation of a bitstream on a Reader
+ * @param input the Reader
+ * @return the node
+ */
+ private static QTNode readQTree( Reader input ) {
+ try {
+ int read = input.read();
+ if (read == '1') {
+ GreyNode node = new GreyNode();
+ for (int i = 0; i < 4; i++)
+ node.setChild(i, readQTree(input));
+ return node;
+ } else {
+ read = input.read();
+ if (read == '1') {
+ return new WhiteLeaf();
+ } else {
+ return new BlackLeaf();
+ }
+ }
+ } catch (IOException ex) {
+ Logger.getLogger(QTree.class.getName()).log(Level.SEVERE, null, ex);
+ return null;
+ }
+ }
+
+ /**
+ * Get a (compressed) node from a (part of a) bitmap
+ * @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 to read
+ * @param bitmap the bitmap
+ * @return the (compressed) node
+ */
+ public static QTNode bitmap2QTree( int x, int y, int width, Bitmap bitmap ) {
+ if (width == 1) {
+ if (bitmap.getBit(x,y)) {
+ return new WhiteLeaf();
+ } else {
+ return new BlackLeaf();
+ }
+ } else {
+ GreyNode node = new GreyNode();
+ node.setChild(0, bitmap2QTree(x, y, width / 2, bitmap));
+ node.setChild(1, bitmap2QTree(x + width / 2, y, width / 2, bitmap));
+ node.setChild(2, bitmap2QTree(x + width / 2, y + width / 2, width / 2, bitmap));
+ node.setChild(3, bitmap2QTree(x, y + width / 2, width / 2, bitmap));
+ return node.compress();
+ }
+ }
+
+}
diff --git a/Week8 Quadtrees/src/qtrees/Qtrees.java b/Week8 Quadtrees/src/qtrees/Qtrees.java
new file mode 100644
index 0000000..91783f7
--- /dev/null
+++ b/Week8 Quadtrees/src/qtrees/Qtrees.java
@@ -0,0 +1,54 @@
+package qtrees;
+
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.io.StringReader;
+import java.io.Writer;
+
+/**
+ * Demonstration class for Quad-trees
+ * @author Sjaak
+ * @author Camil Staps, s4498062
+ */
+public class Qtrees {
+
+ /**
+ * Example features of the QTree:
+ * Constucts and outputs the same tree in all possible ways. The output should
+ * therefore repeat itself.
+ *
+ * @param args the command line arguments
+ * @throws java.io.IOException shouldn't happen with System.out anyway
+ */
+ public static void main(String[] args) throws IOException {
+ // Example: reading in a bitstream
+ String test_tekst = "10011010001010010001010101100011000101000000";
+ StringReader input = new StringReader(test_tekst);
+ QTree qt = new QTree( input );
+
+ // Example: filling a bitmap
+ Bitmap bitmap = new Bitmap(8, 8);
+ qt.fillBitmap( bitmap );
+ System.out.println(bitmap);
+
+ // Example: writing a bitstream
+ Writer out = new OutputStreamWriter(System.out);
+ qt.writeQTree(out);
+ out.write("\n");
+ out.flush( );
+
+ // Example: reading a bitmap
+ QTree qt2 = new QTree(bitmap);
+
+ // Example: filling a bitmap
+ Bitmap bm2 = new Bitmap(8,8);
+ qt2.fillBitmap(bm2);
+ System.out.println(bm2);
+
+ // Example: writing a bitstream
+ qt2.writeQTree(out);
+ out.write("\n");
+ out.flush( );
+ }
+
+}
diff --git a/Week8 Quadtrees/src/qtrees/WhiteLeaf.java b/Week8 Quadtrees/src/qtrees/WhiteLeaf.java
new file mode 100644
index 0000000..57cb591
--- /dev/null
+++ b/Week8 Quadtrees/src/qtrees/WhiteLeaf.java
@@ -0,0 +1,13 @@
+package qtrees;
+
+/**
+ * @author Camil Staps, s4498062
+ */
+public class WhiteLeaf extends QTNode {
+
+ public WhiteLeaf() {
+ boolean_value = true;
+ string_value = "1";
+ }
+
+}
--
cgit v1.2.3