Chris@108: module yetilab.plot.plot; Chris@108: Chris@108: import org.jzy3d.plot3d.builder: Mapper; Chris@119: import org.jzy3d.maths: Range, Coord3d; Chris@108: import org.jzy3d.chart: Chart, ChartLauncher; Chris@108: import org.jzy3d.plot3d.builder: Builder; Chris@108: import org.jzy3d.plot3d.builder.concrete: OrthonormalGrid; Chris@108: import org.jzy3d.colors.colormaps: ColorMapRainbow; Chris@119: import org.jzy3d.colors: ColorMapper, Color; Chris@108: import org.jzy3d.plot3d.rendering.canvas: Quality; Chris@119: import org.jzy3d.plot3d.rendering.view.modes: ViewPositionMode; Chris@148: import org.jzy3d.plot3d.primitives: FlatLine2d, Point; Chris@108: Chris@108: newMatrixMapper matrix = Chris@108: (class MMapper extends Mapper Chris@108: double f(double x, double y) Chris@117: result = matrix.getAt y x; Chris@117: println "f(\(x),\(y)) -> \(result)"; Chris@117: result Chris@108: end; Chris@108: new MMapper()); Chris@108: Chris@108: newMatrixLogMapper matrix = Chris@108: (class MMapper extends Mapper Chris@108: double f(double x, double y) Chris@108: ln (matrix.getAt y x) Chris@108: end; Chris@108: new MMapper()); Chris@108: Chris@108: newMapper mapFunction = Chris@108: (class FMapper extends Mapper Chris@108: double f(double x, double y) Chris@108: mapFunction x y Chris@108: end; Chris@108: new FMapper()); Chris@108: Chris@151: plotMatrix chart matrix is ~Chart -> 'a -> () = Chris@117: (mapper = newMatrixMapper matrix; Chris@108: size = matrix.size; Chris@119: xrange = new Range(0, size.columns - 1); Chris@119: yrange = new Range(0, size.rows - 1); Chris@108: grid = new OrthonormalGrid(xrange, size.columns, yrange, size.rows); Chris@112: println "Matrix size: \(size)"; Chris@117: surface = Builder#buildOrthonormal(grid, mapper); //??? big? Chris@117: println "Z Bounds: \(surface#getBounds()#getZmin()) -> \(surface#getBounds()#getZmax())"; Chris@121: surface#setFaceDisplayed(true); Chris@108: surface#setWireframeDisplayed(true); Chris@108: surface#setWireframeColor(Color#BLACK); Chris@108: chart#getScene()#getGraph()#add(surface); Chris@115: ()); Chris@108: Chris@232: plotCurve chart depth curve is ~Chart -> number -> 'a -> () = Chris@151: (scene = chart#getScene(); Chris@149: xx = map (.time) curve; Chris@149: yy = map (.value) curve; Chris@232: line = new FlatLine2d(xx as ~float[], yy as ~float[], depth); Chris@148: line#setWireframeDisplayed(true); Chris@148: line#setWireframeColor(Color#BLACK); Chris@148: line#setWireframeWidth(2); Chris@148: line#setFaceDisplayed(false); Chris@148: scene#add(line); Chris@148: chart#getView()#setViewPoint(new Coord3d(0, 0, 0)); Chris@149: /* Chris@148: axes = chart#getAxeLayout(); Chris@148: axes#setXAxeLabelDisplayed(false); Chris@148: axes#setYAxeLabelDisplayed(false); Chris@148: axes#setZAxeLabelDisplayed(true); Chris@148: axes#setZAxeLabel("unit goes here"); //!!! Chris@148: axes#setYTickLabelDisplayed(false); Chris@149: */ Chris@148: ()); Chris@148: Chris@232: plotSeries chart depth { start, step, values } is ~Chart -> number -> 'a -> () = Chris@151: (scene = chart#getScene(); Chris@151: xx = map do i: start + step * i done [0..length values - 1]; Chris@151: yy = list values; Chris@232: line = new FlatLine2d(xx as ~float[], yy as ~float[], depth); Chris@150: line#setWireframeDisplayed(true); Chris@150: line#setWireframeColor(Color#BLACK); Chris@150: line#setWireframeWidth(2); Chris@150: line#setFaceDisplayed(false); Chris@150: scene#add(line); Chris@150: chart#getView()#setViewPoint(new Coord3d(0, 0, 0)); Chris@150: /* Chris@150: axes = chart#getAxeLayout(); Chris@150: axes#setXAxeLabelDisplayed(false); Chris@150: axes#setYAxeLabelDisplayed(false); Chris@150: axes#setZAxeLabelDisplayed(true); Chris@150: axes#setZAxeLabel("unit goes here"); //!!! Chris@150: axes#setYTickLabelDisplayed(false); Chris@150: */ Chris@150: ()); Chris@150: Chris@151: plot structures = Chris@151: (chart = new Chart(Quality#Nicest); Chris@232: var depth = 0; Chris@232: for structures do s: Chris@232: case s of Chris@151: Grid matrix: Chris@151: plotMatrix chart matrix; Chris@151: Curve curve: Chris@232: plotCurve chart depth curve; Chris@151: Series series: Chris@232: plotSeries chart depth series; Chris@151: other: Chris@151: failWith "Unable to plot \(other)"; Chris@151: esac; Chris@232: depth := depth + 1; Chris@232: done; Chris@151: ChartLauncher#openChart(chart); Chris@151: chart); Chris@108: Chris@115: { Chris@119: newMatrixMapper, Chris@119: newMatrixLogMapper, Chris@119: newMapper, Chris@115: plotMatrix, Chris@151: plotCurve, Chris@151: plotSeries, Chris@151: plot, Chris@115: } Chris@110: