annotate yetilab/plot.yeti @ 296:ec6a36d88f57

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