annotate yetilab/plot/plot.yeti @ 254:5eb57c649de0 sparse

Using hashes is simpler, but turns out to be mostly no faster and sometimes much slower. Not one to merge back.
author Chris Cannam
date Tue, 21 May 2013 17:40:33 +0100
parents 67ff37b03856
children b5cd42899526
rev   line source
Chris@108 1 module yetilab.plot.plot;
Chris@108 2
Chris@108 3 import org.jzy3d.plot3d.builder: Mapper;
Chris@119 4 import org.jzy3d.maths: Range, Coord3d;
Chris@108 5 import org.jzy3d.chart: Chart, ChartLauncher;
Chris@108 6 import org.jzy3d.plot3d.builder: Builder;
Chris@108 7 import org.jzy3d.plot3d.builder.concrete: OrthonormalGrid;
Chris@108 8 import org.jzy3d.colors.colormaps: ColorMapRainbow;
Chris@119 9 import org.jzy3d.colors: ColorMapper, Color;
Chris@108 10 import org.jzy3d.plot3d.rendering.canvas: Quality;
Chris@119 11 import org.jzy3d.plot3d.rendering.view.modes: ViewPositionMode;
Chris@148 12 import org.jzy3d.plot3d.primitives: FlatLine2d, Point;
Chris@108 13
Chris@108 14 newMatrixMapper matrix =
Chris@108 15 (class MMapper extends Mapper
Chris@108 16 double f(double x, double y)
Chris@117 17 result = matrix.getAt y x;
Chris@117 18 println "f(\(x),\(y)) -> \(result)";
Chris@117 19 result
Chris@108 20 end;
Chris@108 21 new MMapper());
Chris@108 22
Chris@108 23 newMatrixLogMapper matrix =
Chris@108 24 (class MMapper extends Mapper
Chris@108 25 double f(double x, double y)
Chris@108 26 ln (matrix.getAt y x)
Chris@108 27 end;
Chris@108 28 new MMapper());
Chris@108 29
Chris@108 30 newMapper mapFunction =
Chris@108 31 (class FMapper extends Mapper
Chris@108 32 double f(double x, double y)
Chris@108 33 mapFunction x y
Chris@108 34 end;
Chris@108 35 new FMapper());
Chris@108 36
Chris@151 37 plotMatrix chart matrix is ~Chart -> 'a -> () =
Chris@117 38 (mapper = newMatrixMapper matrix;
Chris@108 39 size = matrix.size;
Chris@119 40 xrange = new Range(0, size.columns - 1);
Chris@119 41 yrange = new Range(0, size.rows - 1);
Chris@108 42 grid = new OrthonormalGrid(xrange, size.columns, yrange, size.rows);
Chris@112 43 println "Matrix size: \(size)";
Chris@117 44 surface = Builder#buildOrthonormal(grid, mapper); //??? big?
Chris@117 45 println "Z Bounds: \(surface#getBounds()#getZmin()) -> \(surface#getBounds()#getZmax())";
Chris@121 46 surface#setFaceDisplayed(true);
Chris@108 47 surface#setWireframeDisplayed(true);
Chris@108 48 surface#setWireframeColor(Color#BLACK);
Chris@108 49 chart#getScene()#getGraph()#add(surface);
Chris@115 50 ());
Chris@108 51
Chris@232 52 plotCurve chart depth curve is ~Chart -> number -> 'a -> () =
Chris@151 53 (scene = chart#getScene();
Chris@149 54 xx = map (.time) curve;
Chris@149 55 yy = map (.value) curve;
Chris@232 56 line = new FlatLine2d(xx as ~float[], yy as ~float[], depth);
Chris@148 57 line#setWireframeDisplayed(true);
Chris@148 58 line#setWireframeColor(Color#BLACK);
Chris@148 59 line#setWireframeWidth(2);
Chris@148 60 line#setFaceDisplayed(false);
Chris@148 61 scene#add(line);
Chris@148 62 chart#getView()#setViewPoint(new Coord3d(0, 0, 0));
Chris@149 63 /*
Chris@148 64 axes = chart#getAxeLayout();
Chris@148 65 axes#setXAxeLabelDisplayed(false);
Chris@148 66 axes#setYAxeLabelDisplayed(false);
Chris@148 67 axes#setZAxeLabelDisplayed(true);
Chris@148 68 axes#setZAxeLabel("unit goes here"); //!!!
Chris@148 69 axes#setYTickLabelDisplayed(false);
Chris@149 70 */
Chris@148 71 ());
Chris@148 72
Chris@232 73 plotSeries chart depth { start, step, values } is ~Chart -> number -> 'a -> () =
Chris@151 74 (scene = chart#getScene();
Chris@151 75 xx = map do i: start + step * i done [0..length values - 1];
Chris@151 76 yy = list values;
Chris@232 77 line = new FlatLine2d(xx as ~float[], yy as ~float[], depth);
Chris@150 78 line#setWireframeDisplayed(true);
Chris@150 79 line#setWireframeColor(Color#BLACK);
Chris@150 80 line#setWireframeWidth(2);
Chris@150 81 line#setFaceDisplayed(false);
Chris@150 82 scene#add(line);
Chris@150 83 chart#getView()#setViewPoint(new Coord3d(0, 0, 0));
Chris@150 84 /*
Chris@150 85 axes = chart#getAxeLayout();
Chris@150 86 axes#setXAxeLabelDisplayed(false);
Chris@150 87 axes#setYAxeLabelDisplayed(false);
Chris@150 88 axes#setZAxeLabelDisplayed(true);
Chris@150 89 axes#setZAxeLabel("unit goes here"); //!!!
Chris@150 90 axes#setYTickLabelDisplayed(false);
Chris@150 91 */
Chris@150 92 ());
Chris@150 93
Chris@151 94 plot structures =
Chris@151 95 (chart = new Chart(Quality#Nicest);
Chris@232 96 var depth = 0;
Chris@232 97 for structures do s:
Chris@232 98 case s of
Chris@151 99 Grid matrix:
Chris@151 100 plotMatrix chart matrix;
Chris@151 101 Curve curve:
Chris@232 102 plotCurve chart depth curve;
Chris@151 103 Series series:
Chris@232 104 plotSeries chart depth series;
Chris@151 105 other:
Chris@151 106 failWith "Unable to plot \(other)";
Chris@151 107 esac;
Chris@232 108 depth := depth + 1;
Chris@232 109 done;
Chris@151 110 ChartLauncher#openChart(chart);
Chris@151 111 chart);
Chris@108 112
Chris@115 113 {
Chris@119 114 newMatrixMapper,
Chris@119 115 newMatrixLogMapper,
Chris@119 116 newMapper,
Chris@115 117 plotMatrix,
Chris@151 118 plotCurve,
Chris@151 119 plotSeries,
Chris@151 120 plot,
Chris@115 121 }
Chris@110 122