1 package org.catacomb.dataview; 2 3 import java.awt.Color; 4 5 import org.catacomb.datalish.Box; 6 import org.catacomb.graph.gui.Painter; 7 8 9 public class RasterRowElement extends PlotElement { 10 11 double[] xpts; 12 double[] vals; 13 double vmin; 14 double vmax; 15 double y0; 16 double thresh; 17 18 public RasterRowElement(double[] x, double[] v, double a, double b, double y, double th) { 19 vmin = a; 20 vmax = b; 21 y0 = y; 22 xpts = x; 23 vals = v; 24 thresh = th; 25 } 26 27 28 public void instruct(Painter p) { 29 Color[] cols = new Color[256]; 30 for (int i = 0; i < 256; i++) { 31 cols[i] = new Color(i, i, i); 32 } 33 34 for (int i = 0; i < xpts.length - 2; i++) { 35 double v = vals[i]; 36 double fv = (v - vmin) / (vmax - vmin); 37 if (fv < 0.) { 38 fv = 0.; 39 } 40 if (fv > 1.) { 41 fv = 1.; 42 } 43 p.fillRectangle(xpts[i], y0, xpts[i+1], y0+0.8, cols[(int)(255 * fv)]); 44 } 45 46 p.setColor(Color.yellow); 47 for (int i = 0; i < xpts.length-2; i++) { 48 if (vals[i] < thresh && vals[i+1] >= thresh) { 49 p.drawLine(xpts[i], y0, xpts[i], y0+0.8); 50 } 51 } 52 } 53 54 55 public void push(Box b) { 56 b.pushX(xpts); 57 b.pushY(y0+1); 58 b.pushY(y0); 59 } 60 61 }