package uk.ac.leeds.ccg.geotools; import java.lang.*; import java.awt.*; import uk.ac.leeds.ccg.widgets.*; public class HSVShader extends RampShader { private final boolean debug=false; // private Color missingColor = Color.white; public static final int HUE=0,SAT=1,VALUE=2; //private double missingCode = -9999; protected float[] start;//={0.0f,1.0f,0.0f}; protected float[] end;//={0.5f,1.0f,0.0f}; protected double[] range = {0d,1d}; //protected Color colors = new Color[2]; protected float[] now=new float[3]; protected float[] grad; protected float[] calc; protected boolean goShort = true; /* public HSVShader(Color first){ if(debug)System.out.println("setting up shader"); start = new float[3]; end = new float[3]; Color.RGBtoHSB(first.getRed(),first.getGreen(),first.getBlue(),start); //Color.RGBtoHSB(second.getRed(),second.getGreen(),second.getBlue(),end); end[0]=start[0]; end[1]=start[1]; end[2]=0.0f; //setRange(0,1); if(debug)System.out.println("From : H:"+start[0]+" S:"+start[1]+" V:"+start[2]); if(debug)System.out.println("To : H:"+end[0]+" S:"+end[1]+" V:"+end[2]); setRange(0,100); }*/ public HSVShader(){ this(Color.red,Color.blue); } public HSVShader(Color first,Color second){ this(first,second,true); } /** * Full constructor for a HSVShader
* this will set up a colour ramp from color one to colour two
* by interpolating Hue, Satuarion and Brightness seperatly.
* This genaraly gives a better result than ramping with RGB.
* As hue can be represented as a circle, there are two ways to go from
* any one colour to another colour. For example to ramp from blue to red
* either involves lots of shades of blue, purlpe and red OR hues of blues, greens
* yellows and reds.
* The shortest parameter (true by default in the other constructor) sets which
* way around the hue circle the shader should go. In the above example seting it to
* true would produce the blue-purple-red option whilst false would produce a blue-cyan-green-yellow-red set.
* @param lowest sane value for this ramp (inclusive) * @param highest sane value for this ramp (exclusive) * @param first A Color to start the ramp at * @param second A Color to end the ramp at * @param shortest A boolean to switch the direction of hue selection, see above description. */ public HSVShader(double low, double high,Color first,Color second, boolean shortest){ //super(0,1); goShort = shortest; if(debug)System.out.println("setting up shader"); start = new float[3]; end = new float[3]; setColors(first,second); setRange(0,100); conf = new Configure(); } /** * Constructor for a HSVShader
* this will set up a colour ramp from color one to colour two
* by interpolating Hue, Satuarion and Brightness seperatly.
* This genaraly gives a better result than ramping with RGB.
* As hue can be represented as a circle, there are two ways to go from
* any one colour to another colour. For example to ramp from blue to red
* either involves lots of shades of blue, purlpe and red OR hues of blues, greens
* yellows and reds.
* The shortest parameter (true by default in the other constructor) sets which
* way around the hue circle the shader should go. In the above example seting it to
* true would produce the blue-purple-red option whilst false would produce a blue-cyan-green-yellow-red set.
* @param first A Color to start the ramp at
* @param second A Color to end the ramp at
* @param shortest A boolean to switch the direction of hue selection, see above description.
*/
public HSVShader(Color first,Color second, boolean shortest){
this(0,100,first,second,shortest);
}
public void setRange(double low,double high){
super.setRange(low,high);
range[0]=low;range[1]=high;
grad = new float[3];
calc = new float[3];
calcGrads();
getKey().updateKey();
}
public void calcGrads(){
for(int i =0;i<3;i++){
grad[i] = (float)((end[i]-start[i])/(range[1]-range[0]));
calc[i] = (float)(-range[0]*grad[i]+start[i]);
}
}
public double[] getRange(){
double d[] = new double[2];
d[0]=range[0];
d[1]=range[1];
return d;
}
/*public void setGoShort(boolean flag){
goShort = flag;
setRange(low,high);
}*/
public void testValue(double v){
for(int i=0;i<3;i++){
now[i] = (float)(grad[i]*v+calc[i]);
}
if(debug)System.out.println("now H:"+now[0]+" S:"+now[1]+" V:"+now[2]);
}
public void setColors(Color first,Color second){
Color.RGBtoHSB(first.getRed(),first.getGreen(),first.getBlue(),start);
Color.RGBtoHSB(second.getRed(),second.getGreen(),second.getBlue(),end);
boolean backShort = (Math.abs((end[0]+1-start[0]))