com.mebigfatguy.polycasso
Class DefaultImageGenerator

java.lang.Object
  extended by com.mebigfatguy.polycasso.DefaultImageGenerator
All Implemented Interfaces:
ImageGenerator, java.lang.Runnable

public class DefaultImageGenerator
extends java.lang.Object
implements ImageGenerator, java.lang.Runnable

class that generates test images iteratively looking for the best image that matches a target. The images are generated from semi-transparent polygons that are improved upon over time. This class generates multiple images in parallel to keep multicore processors busy.


Constructor Summary
DefaultImageGenerator(Settings confSettings, java.awt.Image image, java.awt.Dimension size)
          creates an ImageGenerator for the given target image, and size
 
Method Summary
 void addImageGeneratedListener(ImageGeneratedListener listener)
          allows interested parties to register to receive events when a new best image has been found.
 void complete()
          completes the image by transforming the polygon image to the real image
 void fireImageGenerated(java.awt.Image image)
          informs all listeners that a new best image has been found
 PolygonData[] getBestData()
          retrieves the best set of polygons for drawing the image so far
 java.awt.Dimension getImageSize()
          returns the image size that is being generated.
 java.awt.image.BufferedImage getTargetImage()
          retrieves the scaled target iamge
 void removeImageGeneratedListener(ImageGeneratedListener listener)
          allows uninterested parties to unregister to receive events when a new best image is found
 void run()
          the runnable interface implementation to repeatedly improve upon the image and check to see if it is closer to the target image.
 void startGenerating()
          starts up threads to start looking for images that are closest to the target
 void stopGenerating()
          shuts down threads that were looking for images
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultImageGenerator

public DefaultImageGenerator(Settings confSettings,
                             java.awt.Image image,
                             java.awt.Dimension size)
creates an ImageGenerator for the given target image, and size

Parameters:
confSettings - the configuration settings
image - the target image
size - the dimension of the image
Method Detail

getTargetImage

public java.awt.image.BufferedImage getTargetImage()
retrieves the scaled target iamge

Specified by:
getTargetImage in interface ImageGenerator
Returns:
the target image

getImageSize

public java.awt.Dimension getImageSize()
returns the image size that is being generated. This size might be different the original image if the size is bigger then the max setting.

Specified by:
getImageSize in interface ImageGenerator
Returns:
the image size

addImageGeneratedListener

public void addImageGeneratedListener(ImageGeneratedListener listener)
allows interested parties to register to receive events when a new best image has been found.

Specified by:
addImageGeneratedListener in interface ImageGenerator
Parameters:
listener - the listener that is interested in events

removeImageGeneratedListener

public void removeImageGeneratedListener(ImageGeneratedListener listener)
allows uninterested parties to unregister to receive events when a new best image is found

Specified by:
removeImageGeneratedListener in interface ImageGenerator
Parameters:
listener - the listener that is no longer needed

fireImageGenerated

public void fireImageGenerated(java.awt.Image image)
informs all listeners that a new best image has been found

Specified by:
fireImageGenerated in interface ImageGenerator
Parameters:
image - the new best image

startGenerating

public void startGenerating()
starts up threads to start looking for images that are closest to the target

Specified by:
startGenerating in interface ImageGenerator

stopGenerating

public void stopGenerating()
shuts down threads that were looking for images

Specified by:
stopGenerating in interface ImageGenerator

complete

public void complete()
completes the image by transforming the polygon image to the real image

Specified by:
complete in interface ImageGenerator

getBestData

public PolygonData[] getBestData()
retrieves the best set of polygons for drawing the image so far

Specified by:
getBestData in interface ImageGenerator
Returns:
the best set of polygons

run

public void run()
the runnable interface implementation to repeatedly improve upon the image and check to 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.

Specified by:
run in interface java.lang.Runnable


Copyright © 2009-2010 MeBigFatGuy.com. All Rights Reserved.