view 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
line wrap: on
line source
module yetilab.plot.plot;

import org.jzy3d.plot3d.builder: Mapper;
import org.jzy3d.maths: Range, Coord3d;
import org.jzy3d.chart: Chart, ChartLauncher;
import org.jzy3d.plot3d.builder: Builder;
import org.jzy3d.plot3d.builder.concrete: OrthonormalGrid;
import org.jzy3d.colors.colormaps: ColorMapRainbow;
import org.jzy3d.colors: ColorMapper, Color;
import org.jzy3d.plot3d.rendering.canvas: Quality;
import org.jzy3d.plot3d.rendering.view.modes: ViewPositionMode;
import org.jzy3d.plot3d.primitives: FlatLine2d, Point;

newMatrixMapper matrix =
   (class MMapper extends Mapper
        double f(double x, double y)
            result = matrix.getAt y x;
            println "f(\(x),\(y)) -> \(result)";
            result
    end;
    new MMapper());

newMatrixLogMapper matrix =
   (class MMapper extends Mapper
        double f(double x, double y)
            ln (matrix.getAt y x)
    end;
    new MMapper());

newMapper mapFunction =
   (class FMapper extends Mapper
        double f(double x, double y)
            mapFunction x y
    end;
    new FMapper());

plotMatrix chart matrix is ~Chart -> 'a -> () =
   (mapper = newMatrixMapper matrix;
    size = matrix.size;
    xrange = new Range(0, size.columns - 1);
    yrange = new Range(0, size.rows - 1);
    grid = new OrthonormalGrid(xrange, size.columns, yrange, size.rows);
    println "Matrix size: \(size)";
    surface = Builder#buildOrthonormal(grid, mapper); //??? big?
    println "Z Bounds: \(surface#getBounds()#getZmin()) -> \(surface#getBounds()#getZmax())";
    surface#setFaceDisplayed(true);
    surface#setWireframeDisplayed(true);
    surface#setWireframeColor(Color#BLACK);
    chart#getScene()#getGraph()#add(surface);
    ());

plotCurve chart depth curve is ~Chart -> number -> 'a -> () =
   (scene = chart#getScene();
    xx = map (.time) curve;
    yy = map (.value) curve;
    line = new FlatLine2d(xx as ~float[], yy as ~float[], depth);
    line#setWireframeDisplayed(true);
    line#setWireframeColor(Color#BLACK);
    line#setWireframeWidth(2);
    line#setFaceDisplayed(false);
    scene#add(line);
    chart#getView()#setViewPoint(new Coord3d(0, 0, 0));
/*
    axes = chart#getAxeLayout();
    axes#setXAxeLabelDisplayed(false);
    axes#setYAxeLabelDisplayed(false);
    axes#setZAxeLabelDisplayed(true);
    axes#setZAxeLabel("unit goes here"); //!!!
    axes#setYTickLabelDisplayed(false);
*/
    ());

plotSeries chart depth { start, step, values } is ~Chart -> number -> 'a -> () =
   (scene = chart#getScene();
    xx = map do i: start + step * i done [0..length values - 1];
    yy = list values;
    line = new FlatLine2d(xx as ~float[], yy as ~float[], depth);
    line#setWireframeDisplayed(true);
    line#setWireframeColor(Color#BLACK);
    line#setWireframeWidth(2);
    line#setFaceDisplayed(false);
    scene#add(line);
    chart#getView()#setViewPoint(new Coord3d(0, 0, 0));
/*
    axes = chart#getAxeLayout();
    axes#setXAxeLabelDisplayed(false);
    axes#setYAxeLabelDisplayed(false);
    axes#setZAxeLabelDisplayed(true);
    axes#setZAxeLabel("unit goes here"); //!!!
    axes#setYTickLabelDisplayed(false);
*/
    ());

plot structures =
   (chart = new Chart(Quality#Nicest);
    var depth = 0;
    for structures do s:
        case s of
        Grid matrix:
            plotMatrix chart matrix;
        Curve curve:
            plotCurve chart depth curve;
        Series series:
            plotSeries chart depth series;
        other:
            failWith "Unable to plot \(other)";
        esac;
        depth := depth + 1;
    done;
    ChartLauncher#openChart(chart);
    chart);

{
    newMatrixMapper,
    newMatrixLogMapper,
    newMapper,
    plotMatrix, 
    plotCurve,
    plotSeries,
    plot,
}