edu.washington.biostr.sig.volume.colors
Class ColorLookupTable

java.lang.Object
  extended by edu.washington.biostr.sig.volume.colors.ColorLookupTable

public class ColorLookupTable
extends Object

Create an efficient (time, not space) lookup array for translating values from the volume into colors. This precomputes values from ColorSchemes into arrays.

Implementations should be immutable.

Version:
1
Author:
Eider Moore

Field Summary
protected  float multiplier
          The multiplier is used to convert doubles to ints.
protected  int[] ncolors
          This stores an array of colors represented by int[]s.
protected  int[] pcolors
          This stores an array of colors represented by int[]s.
 
Constructor Summary
ColorLookupTable(double min, double max)
          Create a scheme for values between min and max.
ColorLookupTable(float multiplier, double min, double max)
          Create a scheme for values betwenn min and max.
ColorLookupTable(int min, int max)
          Create a scheme for values between min and max.
 
Method Summary
 boolean equals(ColorLookupTable other)
          Compares two ColorLookupTables based on the requirement that all of each tables instance variables satisfy each of their equals conditions.
 boolean equals(Object o)
          Dispatch to equals(ColorLookupTable) or return false.
protected  void fill(boolean positive, int low, int high, ColorScheme scheme)
          Use the scheme to fill the values from low to high.
protected  void finish(boolean positive, int low, int high, int defaultValue)
          Finish up the arrays by filling all values from low to high with the defaultValue.
 BufferedImage generateLegend(boolean positive, boolean horizontal, int width, int height)
          Make a legend that can be used to express the range that this table can display.
 AlphaComposite getAlphaComposite()
          Get the compositing rule for blending this color with an existing image.
 int getColor(double value)
          Look up the given value and return an ARGB integer.
 double getMax()
          Get the maximum supported value.
 double getMin()
          Get the minimum supported value.
 void setColor(double value, int color)
           
 void setNegative(ColorScheme scheme, double threshold, double window)
          Set the negative values for this using the specified color scheme with the given threshold and window.
 void setPositive(ColorScheme scheme, double threshold, double window)
          Set the positive values for this using the specified color scheme with the given threshold and window.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

pcolors

protected int[] pcolors
This stores an array of colors represented by int[]s. It is used to look up positive values.


ncolors

protected int[] ncolors
This stores an array of colors represented by int[]s. It is used to look up negative values.


multiplier

protected float multiplier
The multiplier is used to convert doubles to ints. The current conversion is (int) (double * multiplier). This may change slightly with roundings.

Constructor Detail

ColorLookupTable

public ColorLookupTable(double min,
                        double max)
Create a scheme for values between min and max.

Parameters:
min - The minimum supported value.
max - The maximum supported value.

ColorLookupTable

public ColorLookupTable(int min,
                        int max)
Create a scheme for values between min and max.

Parameters:
min - The minimum supported value.
max - The maximum supported value.

ColorLookupTable

public ColorLookupTable(float multiplier,
                        double min,
                        double max)
Create a scheme for values betwenn min and max. The multiplier is used to convert floating points into indices. Large values result in higher resolution (note that most schemes only have a few thousand colors), but it takes more space to store and more time to precompute.

Parameters:
multiplier - The multiplier is used to convert floating points into indices.
min - The minimum supported value.
max - The maximum supported value.
Method Detail

getColor

public int getColor(double value)
Look up the given value and return an ARGB integer.

Parameters:
value - The value from the volume.
Returns:
An ARGB value.

setColor

public void setColor(double value,
                     int color)

fill

protected void fill(boolean positive,
                    int low,
                    int high,
                    ColorScheme scheme)
Use the scheme to fill the values from low to high. We assume that the range for this in values for the scheme is from [0, 1]

Parameters:
positive - Whether or not this is positive or negative
low - a value between [0, high]
high - a value between [low, color.length)
scheme -

finish

protected void finish(boolean positive,
                      int low,
                      int high,
                      int defaultValue)
Finish up the arrays by filling all values from low to high with the defaultValue.

Parameters:
positive - Whether or not this is positive or negative
low - a value between [0, high]
high - a value between [low, color.length)
defaultValue -

setPositive

public void setPositive(ColorScheme scheme,
                        double threshold,
                        double window)
Set the positive values for this using the specified color scheme with the given threshold and window. threshold + window should be less than the maximum value for the image.

Parameters:
scheme - The coloring scheme to use
threshold - The value to use as 0 (values < threshold are treated as 0)
window - The width of the colors(values > window + threshold are treated as 1)
Throws:
IllegalStateException - if this has been set before.

setNegative

public void setNegative(ColorScheme scheme,
                        double threshold,
                        double window)
Set the negative values for this using the specified color scheme with the given threshold and window. threshold + window should be less than the maximum value for the image.

Parameters:
scheme - The coloring scheme to use
threshold - The value to use as 0 (values > threshold are treated as 0)
window - The width of the colors(values < window + threshold are treated as 1)
Throws:
IllegalStateException - if this has been set before.

getAlphaComposite

public AlphaComposite getAlphaComposite()
Get the compositing rule for blending this color with an existing image.

Returns:
the compositing rule.

equals

public boolean equals(Object o)
Dispatch to equals(ColorLookupTable) or return false. Note hashCode is undefined...

Overrides:
equals in class Object
Parameters:
o -
Returns:
true if the color tables are equal.

equals

public boolean equals(ColorLookupTable other)
Compares two ColorLookupTables based on the requirement that all of each tables instance variables satisfy each of their equals conditions.

Parameters:
other - The other ColorLookupTable for comparison
Returns:
true if the equals condition is met, false otherwise

getMax

public double getMax()
Get the maximum supported value.

Returns:
The maximum supported value.

getMin

public double getMin()
Get the minimum supported value.

Returns:
The minimum supported value.

generateLegend

public BufferedImage generateLegend(boolean positive,
                                    boolean horizontal,
                                    int width,
                                    int height)
Make a legend that can be used to express the range that this table can display.

Parameters:
positive - whether this legend is for positive values.
horizontal - Whether this legend is oriented left to right or top to bottom
width - The width in pixels
height - The height in pixels
Returns:
A new BufferedImage with an evenly spaced legend.


Copyright © 2006 University of Washington. All Rights Reserved.