[Polycasso-commit] SF.net SVN: polycasso:[129] trunk/polycasso/src/com/mebigfatguy/polycasso/ Image
Brought to you by:
dbrosius
|
From: <dbr...@us...> - 2009-12-01 15:06:06
|
Revision: 129
http://polycasso.svn.sourceforge.net/polycasso/?rev=129&view=rev
Author: dbrosius
Date: 2009-12-01 15:05:56 +0000 (Tue, 01 Dec 2009)
Log Message:
-----------
batch up improvement attempts into numCompetingImage batches, and only pick the best one to improve the image -- an attempt to help remove local maximas.
Modified Paths:
--------------
trunk/polycasso/src/com/mebigfatguy/polycasso/ImageGenerator.java
Modified: trunk/polycasso/src/com/mebigfatguy/polycasso/ImageGenerator.java
===================================================================
--- trunk/polycasso/src/com/mebigfatguy/polycasso/ImageGenerator.java 2009-12-01 15:00:12 UTC (rev 128)
+++ trunk/polycasso/src/com/mebigfatguy/polycasso/ImageGenerator.java 2009-12-01 15:05:56 UTC (rev 129)
@@ -42,6 +42,9 @@
private BufferedImage targetImage;
private PolygonData[] bestData;
private double bestScore = Double.MAX_VALUE;
+ private PolygonData[] candidateData;
+ private double candidateScore = Double.MAX_VALUE;
+ private int candidateStart = 0;
private Dimension imageSize;
private Feedback feedback;
private Thread[] t = null;
@@ -159,7 +162,8 @@
/**
* the runnable interface implementation to repeatedly improve upon the image and check to
- * see if it is closer to the target image.
+ * see if it is closer to the target image. Images are created in batches of settings.numCompetingImages
+ * and the best one (if better than the parent) is selected as the new best.
*/
public void run() {
try {
@@ -188,16 +192,26 @@
double delta = feedback.calculateDelta(image);
String message = null;
+ boolean wasSuccessful = false;
boolean newBest = false;
synchronized(lock) {
attempt++;
- if (delta < bestScore) {
- bestData = data.toArray(new PolygonData[data.size()]);
- bestScore = delta;
+ if (delta < candidateScore) {
+ wasSuccessful = true;
+ candidateData = data.toArray(new PolygonData[data.size()]);
+ candidateScore = delta;
if (Polycasso.DEBUG)
- message = "Attempt: " + attempt + " BestScore: " + bestScore + " type: " + type.name();
- newBest = true;
+ message = "Attempt: " + attempt + " CandidateScore: " + candidateScore + " BestScore: " + bestScore + " type: " + type.name();
}
+
+ if ((candidateStart + settings.getNumCompetingImages()) <= attempt) {
+ if (candidateScore < bestScore) {
+ bestData = candidateData;
+ bestScore = candidateScore;
+ newBest = true;
+ }
+ candidateStart = attempt;
+ }
}
if (Polycasso.DEBUG) {
@@ -210,7 +224,7 @@
image = new BufferedImage(imageSize.width, imageSize.height, BufferedImage.TYPE_4BYTE_ABGR);
g2d = (Graphics2D)image.getGraphics();
}
- improver.typeWasSuccessful(type, newBest);
+ improver.typeWasSuccessful(type, wasSuccessful);
}
} catch (Exception e) {
e.printStackTrace();
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|