Difference between revisions of "Floodfill Application"
Line 15: | Line 15: | ||
=Mistakes to Avoid= | =Mistakes to Avoid= | ||
− | {{Warning | Do NOT use <nowiki>==</nowiki> to compare Colors. Use Objects.equals(a,b)}} | + | {{Warning | Do NOT use <nowiki>==</nowiki> to compare Colors. Use Objects.equals(a,b)}.} |
==Sequential Implementation Increased Stack Size Requirement== | ==Sequential Implementation Increased Stack Size Requirement== |
Revision as of 16:00, 1 February 2018
Contents
Motivation
Floodfill is an problem that is well-solved recursively. It allows us an opportunity to think about the similarities and differences between creating a task for each sub-problem and wrapping all of your recursive calls in a single async. Further, we will harken back to this studio later in the semester when we discuss determinism.
Background
In this studio, you will be using a parallel and recursive method to create an app that fills in a space with color, much like the paint bucket in GNU Image Manipulation Program.
References
https://en.wikipedia.org/wiki/Flood_fill
Video
Mistakes to Avoid
{{Warning | Do NOT use == to compare Colors. Use Objects.equals(a,b)}.}
Sequential Implementation Increased Stack Size Requirement
For this project, if you decide to first build a sequential version, you will need to change your VM Arguments slightly. In addition to the normal argument that needs to be pasted in for every assignment, you need to add -Xss4m
. This will increase the size of the call stack, essentially increasing the maximum depth of your recursion.
Code To Use
Code To Implement
The class is composed of two methods: floodFill and floodFillKernel. The entire process in the kernel is triggered from the floodFill method.
public static void floodFill(MutablePixels pixels, Color nextColor, int x, int y) throws InterruptedException, ExecutionException { Color prevColor = pixels.getColor(x, y); if (nextColor.equals(prevColor)) { // pass } else { finish(() -> { floodFillKernel(pixels, prevColor, nextColor, x, y); }); } }
This is so that the kernel can run recursively and asynchronously so the floodFill method can wrap the kernel in an all-inclusive finish.
class: | FloodFiller.java | |
methods: | floodFillKernel | |
package: | floodfill.studio | |
source folder: | student/src/main/java |
The kernel should check if the given pixel is in bounds. If it is, it should check if the given pixel matches the targetColor (the color we wish to change). If it is, it should then replace the color with the replacementColor and asynchronously call the method again to repeat the process for the surrounding pixels. The purpose of the assignment is to understand recursion and how to make it work in parallel.
method: floodFillKernel
(parallel implementation required)
Testing Your Solution
Visualization
class: | FloodFillVizApp.java | VIZ |
package: | floodfill.viz | |
source folder: | student/src//java |
JavaFX Setup
In order to run the visualization app you will need to setup e(fx)clipse.
Correctness
A test suite exists but is limited and not all that exciting. Demo to an instructor to get credit for your studio locked in.
class: | MergeSortTestSuite.java | |
package: | sort.studio.merge | |
source folder: | testing/src/test/java |