jezuch.utils.starmapper3
Interface Plotter<C>

All Known Implementing Classes:
AbstractPlotter, BorderPlotter, CappedMixingPlotter, CappedPlotter, DefaultPlotter, DominationPlotter, MixingPlotter, SmoothMixingPlotter, SmoothPlotter

public interface Plotter<C>

Plotter is an interface for converting raw data generated by Starmapper into pixels.

Starmapper calculates influences of Regions on points, where each point is a center of a pixel. The influences are given as an array of float values and Plotter's responsibility is to use this data to plot a relevant pixel with a specific Color. This Color is calculated from both the influence array and specific Regions' base Colors. Some Plotters simply choose the maximum influence, others mix the Regions' Colors in some way.

The sequence of method calls is as follows:

  1. initNewImage(int, int, List, Config): requests the Plotter to initialise a new image of its own format, color depth etc.; thw dimensions of the image and a list of Regions and their Colors are given; this method returns a "context object", which is an instance of some private class holding necessary context data understandable by this Plotter - this object will then be passed to other methods;
  2. plot(Object, int, int, int, double[]): called for each relevant pixel, tells the Plotter what are the influences of Regions on a pixel at specified coordinates;
  3. plotIcon(Object, int, int, Icon), printString(Object, int, int, String, Font), printString(Object, int, int, String, Font, Color): usually Starmapper wants to draw some additional things on the image, like location of Nodes on the map, their names and the legend;
  4. getImage(Object): finally Starmapper requests the Plotter to return the image as a BufferedImage.

The "context object" returned by initNewImage(int, int, List, Config) is completly private to the Plotter. It is used to ensure thread safety while using a single instance of a Plotter.

Author:
ksobolewski

Field Summary
static List<Color> DEFAULT_COLORS
          A List of default Colors, useful when a Region has no Color defined.
 
Method Summary
 BufferedImage getImage(C context)
          Returns the final image as a BufferedImage.
 C initNewImage(int width, int height, List<Pair<? extends Region,Color>> regions, Config config)
          Initializes a new image with this Plotter's format, the given dimensions and Regions' Colors.
 void plot(C context, int x, int y, int p, double[] influences)
          Tells the Plotter what are the influences of Regions on the point in the center of pixel at the given coordinates.
 void plotIcon(C context, int x, int y, Icon icon)
          Plots an Icon at given coordinates; these coordinates locate the center of the Icon.
 void postProcess(C context)
          Called after all pixels were plotted and before node names and icons are plotted.
 void printString(C context, int x, int y, String string, Font font)
          Prints a String on the target image, using a Color that's convenient to the Plotter.
 void printString(C context, int x, int y, String string, Font font, Color color)
          Prints a String on the target image, using the specified Color.
 

Field Detail

DEFAULT_COLORS

static final List<Color> DEFAULT_COLORS
A List of default Colors, useful when a Region has no Color defined. Actually Plotters don't use this list - Starmapper will assign Colors from this list when necessary.

Method Detail

initNewImage

C initNewImage(int width,
               int height,
               List<Pair<? extends Region,Color>> regions,
               Config config)
               throws ConversionException
Initializes a new image with this Plotter's format, the given dimensions and Regions' Colors. Returns an object that holds this image's data for thread-safe use.

Note: width includes Starmapper.PARAM_IMAGE_LEGEND_WIDTH

Parameters:
width - the image's width
height - the image's height
regions - a List of Regions along with their Colors
config - a Config with optional additional configuration parameters
Returns:
a context-holding object
Throws:
ConversionException - if the Config complains

plot

void plot(C context,
          int x,
          int y,
          int p,
          double[] influences)
Tells the Plotter what are the influences of Regions on the point in the center of pixel at the given coordinates. The index in the array of influences determines the Region which this influence is for - it is the same index as in the List of Regions and Colors passed to initNewImage(int, int, List, Config). The implementation of this method is allowed to modify the influences array - it will be discarded after the call returns.

Parameters:
context - a context-holding object
x - column index of plotted pixel
y - row index of plotted pixel
p - "pixel number" equal to y * width + x
influences - array of influences for all regions

postProcess

void postProcess(C context)
Called after all pixels were plotted and before node names and icons are plotted. This may be used for example when some more context than one pixel is needed (see for example BorderPlotter).

Parameters:
context - a context-holding object

plotIcon

void plotIcon(C context,
              int x,
              int y,
              Icon icon)
Plots an Icon at given coordinates; these coordinates locate the center of the Icon. The Plotter chooses the Color that's best for the Icon in this location.

Parameters:
context - a context-holding object
x - x coordinate of the Icon's center
y - y coordinate of the Icon's center
icon - the Icon to plot

printString

void printString(C context,
                 int x,
                 int y,
                 String string,
                 Font font)
Prints a String on the target image, using a Color that's convenient to the Plotter. The coordinates given are the position of top-left corner of the string.

Parameters:
context - a context-holding object
x - left edge of the String to draw
y - top edge of the String to draw
string - the String to draw
font - the Font to use

printString

void printString(C context,
                 int x,
                 int y,
                 String string,
                 Font font,
                 Color color)
Prints a String on the target image, using the specified Color. The coordinates given are the position of top-left corner of the string.

Parameters:
context - a context-holding object
x - left edge of the String to draw
y - top edge of the String to draw
string - the String to draw
font - the Font to use
color - the String's Color

getImage

BufferedImage getImage(C context)
Returns the final image as a BufferedImage. The context is free to be destroyed after the cal to this method.

Parameters:
context - a context-holding object
Returns:
the final image as a BufferedImage