Modified:
trunk/src/wosaic/WosaicUI.java
trunk/src/wosaic/algorithms/BruteForceAlgorithm.java
trunk/src/wosaic/utilities/Mosaic.java
trunk/src/wosaic/utilities/Pixel.java
Log:
Modified brute force to check its neighbors for the same pixel before
placing a pixel...
Modified: trunk/src/wosaic/WosaicUI.java
==============================================================================
--- trunk/src/wosaic/WosaicUI.java (original)
+++ trunk/src/wosaic/WosaicUI.java Sun Apr 12 21:29:24 2009
@@ -363,7 +363,6 @@
* generated, and then update the UI.
*/
protected void CancelGeneration() {
- // TODO: Write code for the comments below
// Prompt the user to make sure the process should be
// cancelled.
// Send interrupts to the controller
@@ -374,6 +373,17 @@
ControllerThread.interrupt();
CancelButton.setEnabled(false);
+ GenerateMosaicButton.setEnabled(true);
+ SaveButton.setEnabled(true);
+ BrowseButton.setEnabled(true);
+
+ InputImageText.setEnabled(true);
+ MosaicResolutionText.setEnabled(true);
+ SearchQueryText.setEnabled(true);
+
+ TabbedPane.setEnabledAt(TabbedPane.indexOfComponent(AdvancedOptionsTab),
true);
+
+
StatusUI.setStatus("Mosaic Cancelled!");
StatusUI.setIndeterminate(false);
StatusUI.setProgress(0);
Modified: trunk/src/wosaic/algorithms/BruteForceAlgorithm.java
==============================================================================
--- trunk/src/wosaic/algorithms/BruteForceAlgorithm.java (original)
+++ trunk/src/wosaic/algorithms/BruteForceAlgorithm.java Sun Apr 12
21:29:24 2009
@@ -10,6 +10,7 @@
import wosaic.utilities.Mosaic;
import wosaic.utilities.Pixel;
+import wosaic.utilities.Parameters;
/**
* Simple "brute force" algorithm. Each time we receive a new pixel, Check
each
@@ -74,8 +75,21 @@
// Just assign this Pixel to this spot
Mos.UpdatePixel(r, c, pixel, matchScore);
- else if (matchScore < Mos.getScoreAt(r, c))
- Mos.UpdatePixel(r, c, pixel, matchScore);
+ else if (matchScore < Mos.getScoreAt(r, c)) {
+ Pixel[][] imageGrid = Mos.getPixelArr();
+ Parameters params = Mos.getParams();
+
+ // Check neighbors
+ if (r-1 >= 0 && r+1 < params.resRows && c-1 >=0 && c+1
< params.resCols &&
+ imageGrid[r-1][c] != pixel &&
imageGrid[r-1][c+1] != pixel &&
+ imageGrid[r-1][c-1] != pixel &&
imageGrid[r+1][c] != pixel &&
+ imageGrid[r][c+1] != pixel && imageGrid[r][c-1] !=
pixel &&
+ imageGrid[r+1][c-1] != pixel &&
imageGrid[r+1][c+1] != pixel) {
+
+ Mos.UpdatePixel(r, c, pixel, matchScore);
+ }
+
+ }
}
}
@@ -118,7 +132,6 @@
}
}
- @Override
public void run() {
System.err.println("Algorithm thread running");
Modified: trunk/src/wosaic/utilities/Mosaic.java
==============================================================================
--- trunk/src/wosaic/utilities/Mosaic.java (original)
+++ trunk/src/wosaic/utilities/Mosaic.java Sun Apr 12 21:29:24 2009
@@ -243,7 +243,7 @@
final ArrayList<Point> updatedCoords = new ArrayList<Point>();
final int[] avgColors = new int[3];
- for (int r = 0; r < params.resRows; r++)
+ for (int r = 0; r < params.resRows; r++) {
for (int c = 0; c < params.resCols; c++) {
srcPixel.getAvgImageColor(avgColors);
@@ -259,22 +259,31 @@
final int matchScore = (int) Math.sqrt((Math.pow(rmDiff, 2.0) +
Math.pow(gmDiff, 2.0) + Math.pow(bmDiff, 2.0)));
if (imageGrid[r][c] != null) {
-
if (matchScore < scoreGrid[r][c]) {
- imageGrid[r][c] = srcPixel;
- scoreGrid[r][c] = matchScore;
- updatedCoords.add(new Point(r, c));
+ // Check neighbors
+ if (r-1 >= 0 && r+1 < params.resRows && c-1 >=0 &&
c+1 < params.resCols &&
+ imageGrid[r-1][c] != srcPixel &&
imageGrid[r-1][c+1] != srcPixel &&
+ imageGrid[r-1][c-1] != srcPixel &&
imageGrid[r+1][c] != srcPixel &&
+ imageGrid[r][c+1] != srcPixel &&
imageGrid[r][c-1] != srcPixel &&
+ imageGrid[r+1][c-1] != srcPixel &&
imageGrid[r+1][c+1] != srcPixel) {
+
+ imageGrid[r][c] = srcPixel;
+ scoreGrid[r][c] = matchScore;
+ srcPixel.numTimes++;
+ updatedCoords.add(new Point(r, c));
+ }
}
} else {
// Just assign this Pixel to this spot
imageGrid[r][c] = srcPixel;
- scoreGrid[r][c] = matchScore;
// Send an update notification
updatedCoords.add(new Point(r, c));
}
}
+ }
+
if (updatedCoords.size() != 0) _fire(updatedCoords, srcPixel);
notifyAll();
@@ -292,6 +301,7 @@
final Pixel newPixel, int score) {
imageGrid[row][col] = newPixel;
scoreGrid[row][col] = score;
+ newPixel.numTimes++;
// Fire an update
ArrayList<Point> coords = new ArrayList<Point>(1);
Modified: trunk/src/wosaic/utilities/Pixel.java
==============================================================================
--- trunk/src/wosaic/utilities/Pixel.java (original)
+++ trunk/src/wosaic/utilities/Pixel.java Sun Apr 12 21:29:24 2009
@@ -44,6 +44,8 @@
*/
public int width;
+ public int numTimes;
+
/**
* Creates a Pixel object from a BufferedImage
*