AuD
Lecture 'Algorithmen und Datenstrukturen' (code examples)
ColormapJet.java
Go to the documentation of this file.
1package aud.util;
2
4public class ColormapJet extends Colormap<Double> {
5
6 public double minValue=0.0;
7 public double maxValue=1.0;
8
9 static int JET[] = { // borrowed from octave
10 0x00008f, 0x00009f, 0x0000af, 0x0000bf, 0x0000cf,
11 0x0000df, 0x0000ef, 0x0000ff, 0x0010ff, 0x0020ff, 0x0030ff, 0x0040ff,
12 0x0050ff, 0x0060ff, 0x0070ff, 0x0080ff, 0x008fff, 0x009fff, 0x00afff,
13 0x00bfff, 0x00cfff, 0x00dfff, 0x00efff, 0x00ffff, 0x10ffef, 0x20ffdf,
14 0x30ffcf, 0x40ffbf, 0x50ffaf, 0x60ff9f, 0x70ff8f, 0x80ff80, 0x8fff70,
15 0x9fff60, 0xafff50, 0xbfff40, 0xcfff30, 0xdfff20, 0xefff10, 0xffff00,
16 0xffef00, 0xffdf00, 0xffcf00, 0xffbf00, 0xffaf00, 0xff9f00, 0xff8f00,
17 0xff8000, 0xff7000, 0xff6000, 0xff5000, 0xff4000, 0xff3000, 0xff2000,
18 0xff1000, 0xff0000, 0xef0000, 0xdf0000, 0xcf0000, 0xbf0000, 0xaf0000,
19 0x9f0000, 0x8f0000, 0x800000, };
20
21 static int INVALID = 0xffffff;
22
23 public ColormapJet() {}
24
25 public ColormapJet(double minValue,double maxValue) {
26 this.minValue=minValue;
27 this.maxValue=maxValue;
28 }
29
30 @Override public int getRGB(Double data) {
31
32 assert(maxValue>minValue);
33
34 if (Double.isInfinite(data))
35 return INVALID;
36
37 if (data<minValue)
38 return JET[0];
39 if (data>maxValue)
40 return JET[JET.length-1];
41
42 double t=(data-minValue)/(maxValue-minValue);
43
44 assert(0.0<=t && t<=1.0);
45
46 return JET[(int) (t*(JET.length-1))];
47 }
48
49 public static void main(String[] args) {
50 ColormapJet jet=new ColormapJet();
51 jet.minValue=-2.0;
52 jet.maxValue= 2.0;
53
54 double t=-2.125;
55 while (t<=2.125) {
56 System.out.println(t+" => "+jet.getString(t));
57 t+=0.125;
58 }
59 }
60}
map values in [minValue,maxValue] to color
Definition: ColormapJet.java:4
static void main(String[] args)
int getRGB(Double data)
ColormapJet(double minValue, double maxValue)
simple interface for color map
Definition: Colormap.java:4
String getString(T data)
get string representation from getRGB
Definition: Colormap.java:14