1 package prefuse.util; 2 3 11 public class ColorMap { 12 13 private int[] palette; 14 private double minValue, maxValue; 15 16 23 public ColorMap(int[] map, double min, double max) { 24 palette = map; 25 minValue = min; 26 maxValue = max; 27 } 28 29 38 public int getColor(double val) { 39 if ( val < minValue ) { 40 return palette[0]; 41 } else if ( val >= maxValue ) { 42 return palette[palette.length-1]; 43 } else { 44 int idx = (int)(palette.length * 45 (val-minValue)/(maxValue-minValue)); 46 return palette[idx]; 47 } 48 } 49 50 54 public int[] getColorPalette() { 55 return palette; 56 } 57 58 62 public void setColorPalette(int[] palette) { 63 this.palette = palette; 64 } 65 66 71 public double getMaxValue() { 72 return maxValue; 73 } 74 75 80 public void setMaxValue(double maxValue) { 81 this.maxValue = maxValue; 82 } 83 84 89 public double getMinValue() { 90 return minValue; 91 } 92 93 98 public void setMinValue(double minValue) { 99 this.minValue = minValue; 100 } 101 102 } | Popular Tags |